diff --git a/package-lock.json b/package-lock.json index 3f4b81f1..cc2b4536 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "presearch-packages", - "version": "0.1.26", + "version": "0.1.33", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -9,6 +9,16 @@ "resolved": "https://registry.npmjs.org/@types/node/-/node-14.14.10.tgz", "integrity": "sha512-J32dgx2hw8vXrSbu4ZlVhn1Nm3GbeCFNw2FWL8S5QKucHGY0cyNwjdQdO+KMBZ4wpmC7KhLCiNsdk1RFRIYUQQ==" }, + "@types/node-fetch": { + "version": "2.5.12", + "resolved": "https://registry.npmjs.org/@types/node-fetch/-/node-fetch-2.5.12.tgz", + "integrity": "sha512-MKgC4dlq4kKNa/mYrwpKfzQMB5X3ee5U6fSprkKpToBqBmX4nFZL9cW5jl6sWn+xpRJ7ypWh2yyqqr8UUCstSw==", + "dev": true, + "requires": { + "@types/node": "*", + "form-data": "^3.0.0" + } + }, "ansi-styles": { "version": "4.3.0", "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", @@ -17,6 +27,12 @@ "color-convert": "^2.0.1" } }, + "asynckit": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", + "integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k=", + "dev": true + }, "at-least-node": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/at-least-node/-/at-least-node-1.0.0.tgz", @@ -100,6 +116,15 @@ "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==" }, + "combined-stream": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", + "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", + "dev": true, + "requires": { + "delayed-stream": "~1.0.0" + } + }, "commander": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/commander/-/commander-4.1.1.tgz", @@ -212,6 +237,12 @@ "resolved": "https://registry.npmjs.org/decimal.js/-/decimal.js-10.2.1.tgz", "integrity": "sha512-KaL7+6Fw6i5A2XSnsbhm/6B+NuEA7TZ4vqxnd5tXz9sbKtrN9Srj8ab4vKVdK8YAqZO9P1kg45Y6YLoduPf+kw==" }, + "delayed-stream": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", + "integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk=", + "dev": true + }, "dom-serializer": { "version": "0.1.1", "resolved": "https://registry.npmjs.org/dom-serializer/-/dom-serializer-0.1.1.tgz", @@ -294,6 +325,17 @@ "resolved": "https://registry.npmjs.org/escape-latex/-/escape-latex-1.2.0.tgz", "integrity": "sha512-nV5aVWW1K0wEiUIEdZ4erkGGH8mDxGyxSeqPzRNtWP7ataw+/olFObw7hujFWlVjNsaDFw5VZ5NzVSIqRgfTiw==" }, + "form-data": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-3.0.1.tgz", + "integrity": "sha512-RHkBKtLWUVwd7SqRIvCZMEvAMoGUp0XU+seQiZejj0COz3RI3hWP4sCv3gZWWLjJTd7rGwcsF5eKZGii0r/hbg==", + "dev": true, + "requires": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + } + }, "fraction.js": { "version": "4.0.12", "resolved": "https://registry.npmjs.org/fraction.js/-/fraction.js-4.0.12.tgz", @@ -550,6 +592,21 @@ } } }, + "mime-db": { + "version": "1.49.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.49.0.tgz", + "integrity": "sha512-CIc8j9URtOVApSFCQIF+VBkX1RwXp/oMMOrqdyXSBXq5RWNEsRfyj1kiRnQgmNXmHxPoFIxOroKA3zcU9P+nAA==", + "dev": true + }, + "mime-types": { + "version": "2.1.32", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.32.tgz", + "integrity": "sha512-hJGaVS4G4c9TSMYh2n6SQAGrC4RnfU+daP8G7cSCmaqNjiOoUY0VHCMS42pxnQmVF1GWwFhbHWn3RIxCqTmZ9A==", + "dev": true, + "requires": { + "mime-db": "1.49.0" + } + }, "minimatch": { "version": "3.0.4", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", @@ -864,6 +921,12 @@ "integrity": "sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=", "dev": true }, + "typescript": { + "version": "4.3.5", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.3.5.tgz", + "integrity": "sha512-DqQgihaQ9cUrskJo9kIyW/+g0Vxsk8cDtZ52a3NGh0YNTfpUSArXSohyUGnvbPazEPLu398C0UxmKSOrPumUzA==", + "dev": true + }, "uid-number": { "version": "0.0.6", "resolved": "https://registry.npmjs.org/uid-number/-/uid-number-0.0.6.tgz", diff --git a/package.json b/package.json index 30857b59..2ae36908 100644 --- a/package.json +++ b/package.json @@ -1,30 +1 @@ -{ - "name": "presearch-packages", - "version": "0.1.33", - "description": "Instant information packages for the Presearch engine", - "main": "index.js", - "scripts": { - "merge-dependencies": "./bin/merge-dependencies", - "add-package-json": "git add package.json", - "create-package": "./bin/create-package.sh", - "create-package-windows": ".\\bin\\create-package.sh" - }, - "pre-commit": [ - "merge-dependencies", - "add-package-json" - ], - "author": "", - "license": "MIT", - "dependencies": { - "create-react-app": "^4.0.1", - "dotenv": "^8.2.0", - "mathjs": "^8.0.1", - "mathsteps": "^0.2.0", - "node-fetch": "^2.6.1", - "periodic-table": "^0.0.8", - "wikijs": "^6.0.1" - }, - "devDependencies": { - "pre-commit": "^1.2.2" - } -} +{"name":"presearch-packages","version":"0.1.33","description":"Instant information packages for the Presearch engine","main":"index.js","scripts":{"merge-dependencies":"./bin/merge-dependencies","add-package-json":"git add package.json","create-package":"./bin/create-package.sh","create-package-windows":".\\bin\\create-package.sh"},"pre-commit":["merge-dependencies","add-package-json"],"author":"","license":"MIT","dependencies":{"create-react-app":"^4.0.1","dotenv":"^6.1.0","mathjs":"^3.16.3","mathsteps":"^0.2.0","node-fetch":"^2.6.1","periodic-table":"^0.0.8","wikijs":"^6.0.1"},"devDependencies":{"pre-commit":"^1.2.2"}} \ No newline at end of file diff --git a/packages/apod/index.js b/packages/apod/index.ts similarity index 63% rename from packages/apod/index.js rename to packages/apod/index.ts index e72682e1..1b4e6fd3 100644 --- a/packages/apod/index.js +++ b/packages/apod/index.ts @@ -1,30 +1,43 @@ -'use strict'; -const fetch = require('node-fetch'); +import { IApod } from "./types"; -const APOD_API_KEY = 'bLhnNpy0ntfp1QzvG61uXC6m52fbcFKmtyJCYvbA'; +// @ts-ignore +const fetch = require("node-fetch"); -async function apod() { - const res = await fetch(`https://api.nasa.gov/planetary/apod?api_key=${APOD_API_KEY}`); +const APOD_API_KEY = "bLhnNpy0ntfp1QzvG61uXC6m52fbcFKmtyJCYvbA"; + +async function apod(): Promise { + const res: Response = await fetch( + `https://api.nasa.gov/planetary/apod?api_key=${APOD_API_KEY}` + ); const json = await res.text(); - const data = JSON.parse(json); + const data: IApod = JSON.parse(json); return `

Astronomy Picture of the Day

- ${data.url - ? data.media_type === 'video' - ? `` - : `${data.title}` - : `` + ${ + data.url + ? data.media_type === "video" + ? `` + : `${data.title}` + : `` }
${data.title ? `

${data.title}

` : ``} - ${data.copyright ? `

By ${data.copyright}

` : ``} + ${ + data.copyright + ? `

By ${data.copyright}

` + : `` + } ${data.date ? `

${data.date}

` : ``} - ${data.explanation ? `

${data.explanation}

` : ``} + ${ + data.explanation + ? `

${data.explanation}

` + : `` + } apod.nasa.gov
@@ -90,9 +103,7 @@ async function apod() { // This line is for testing package with browserify bundle // window.apod = apod(); - -async function trigger(query) { - return query.toLowerCase() === 'apod'; -} +// @ts-ignore +const trigger = (query: string): boolean => query.toLowerCase() === "apod"; module.exports = { apod, trigger }; diff --git a/packages/apod/package.json b/packages/apod/package.json index d7ece09a..ae688186 100644 --- a/packages/apod/package.json +++ b/packages/apod/package.json @@ -2,7 +2,7 @@ "name": "apod", "version": "1.0.0", "description": "Astronomy Picture of the Day", - "main": "index.js", + "main": "index.ts", "dependencies": { "node-fetch": "^2.6.1" }, diff --git a/packages/apod/types.ts b/packages/apod/types.ts new file mode 100644 index 00000000..45ecb343 --- /dev/null +++ b/packages/apod/types.ts @@ -0,0 +1,8 @@ +export type IApod = { + url: string; + media_type: string; + title: string; + date: string; + copyright: string; + explanation: string; +}; diff --git a/packages/colorGenerator/index.js b/packages/colorGenerator/index.ts similarity index 96% rename from packages/colorGenerator/index.js rename to packages/colorGenerator/index.ts index 4daedeb2..982e58b9 100644 --- a/packages/colorGenerator/index.js +++ b/packages/colorGenerator/index.ts @@ -1,6 +1,4 @@ -"use strict"; - -async function colorGenerator(query) { +function colorGenerator(_query: string): string { return `
@@ -385,17 +383,22 @@ async function colorGenerator(query) { `; } -async function trigger(query) { - query = query.toLowerCase(); - return ( - query === "color generator" || - query === "random color" || - query === "random color generator" || - query === "colorgenerator" || - query === "color palette" +// @ts-ignore +function trigger(query: string | string[]): boolean { + query = (query as string).toLowerCase().split(" "); + const queryList = [ + "color generator", + "random color", + "random color generator", + "colorgenerator", + "color palette", + ]; + const filteredList = queryList.filter((item) => + (query as string[]).every( + (el: string) => item.toLowerCase().indexOf(el) > -1 + ) ); + return !!filteredList.length; } module.exports = { colorGenerator, trigger }; - - diff --git a/packages/colorPicker/index.js b/packages/colorPicker/index.ts similarity index 95% rename from packages/colorPicker/index.js rename to packages/colorPicker/index.ts index 2f0bc6d8..aab9bf84 100644 --- a/packages/colorPicker/index.js +++ b/packages/colorPicker/index.ts @@ -1,8 +1,7 @@ -'use strict'; +"use strict"; -function colorPicker(query) { - - return ` +function colorPicker(_query: string): string { + return ` `; } catch (error) { - return null + return null; } } -async function trigger(query) { - query = query.toLowerCase(); - for (let coin of coin_list) { - if ( - (coin.id === query || - coin.name.toLowerCase() === query || - coin.symbol === query) && - !coin.symbol.toLowerCase().includes(".cx") - ) - return true; - } +// @ts-ignore +async function trigger(query: string | string[]) { + query = (query as string).toLowerCase().split(" "); + const filteredCoins = coin_list.filter( + (item) => + (query as string[]).every((el: string) => item.id.toLowerCase().indexOf(el) > -1) || + (query as string[]).every((el: string) => item.name.toLowerCase().indexOf(el) > -1) || + (query as string[]).every((el: string) => item.symbol.toLowerCase().indexOf(el) > -1) + ); - return false; + return !!filteredCoins.length; } module.exports = { cryptoInfo, trigger }; diff --git a/packages/cryptoInfo/types.ts b/packages/cryptoInfo/types.ts new file mode 100644 index 00000000..f0085838 --- /dev/null +++ b/packages/cryptoInfo/types.ts @@ -0,0 +1,116 @@ +export type ILinks = { + homepage: Array; + blockchain_site: Array; + official_forum_url: Array; + chat_url: Array; + announcement_url: Array; + twitter_screen_name: string; + facebook_username: string; + bitcointalk_thread_identifier: string; + telegram_channel_identifier: string; + subreddit_url: string; + repos_url: { + github: Array; + bitbucket: Array; + }; +}; + +export type IMarketData = { + max_supply: number; + total_supply: number; + last_updated: string; + market_cap_rank: number; + price_change_24h: number; + circulating_supply: number; + price_change_percentage_24h: number; + price_change_percentage_7d: number; + price_change_percentage_14d: number; + price_change_percentage_30d: number; + price_change_percentage_60d: number; + price_change_percentage_200d: number; + price_change_percentage_1y: number; + market_cap_change_24h: number; + market_cap_change_percentage_24h: number; + market_cap_change_percentage_24h_in_currency: { + [key: string]: number; + }; + price_change_percentage_1h_in_currency: { + [key: string]: number; + }; + price_change_percentage_24h_in_currency: { + [key: string]: number; + }; + price_change_percentage_7d_in_currency: { + [key: string]: number; + }; + price_change_percentage_14d_in_currency: { + [key: string]: number; + }; + price_change_percentage_30d_in_currency: { + [key: string]: number; + }; + price_change_percentage_60d_in_currency: { + [key: string]: number; + }; + price_change_percentage_200d_in_currency: { + [key: string]: number; + }; + price_change_percentage_1y_in_currency: { + [key: string]: number; + }; + market_cap_change_24h_in_currency: { + [key: string]: number; + }; + fully_diluted_valuation: { + [key: string]: number; + }; + price_change_24h_in_currency: { + [key: string]: number; + }; + total_volume: { + [key: string]: number; + }; + current_price: { + [key: string]: number; + }; + market_cap: { + [key: string]: number; + }; + high_24h: { + [key: string]: number; + }; + low_24h: { + [key: string]: number; + }; +}; + +export type ICoin = { + id: string; + name: string; + symbol: string; + base: string; + target: string; + market: IMarketData; + last: number; + volume: number; + image: { + small: string; + }; + converted_last: string; + converted_volume: number; + trust_score: string; + market_data: IMarketData; + links: ILinks; + market_cap_rank: number; + asset_platform_id: boolean; + bid_ask_spread_percentage: number; + timestamp: string; + last_traded_at: string; + last_fetch_at: string; + is_anomaly: boolean; + is_stale: boolean; + trade_url: string; + token_info_url: null; + coin_id: string; + target_coin_id: string; +}; diff --git a/packages/exchangeRates/index.js b/packages/exchangeRates/index.ts similarity index 89% rename from packages/exchangeRates/index.js rename to packages/exchangeRates/index.ts index c2625bdc..87245e6c 100644 --- a/packages/exchangeRates/index.js +++ b/packages/exchangeRates/index.ts @@ -1,11 +1,11 @@ -'use strict'; +// @ts-ignore const fetch = require('node-fetch'); -var currentPrice; -var usd; -var cad; -var eur; -var gbp; +let currentPrice: number; +let usd: number; +let cad: number; +let eur: number; +let gbp: number; const API = "https://api.nbp.pl/api/exchangerates/tables/a/?format=json" @@ -18,15 +18,15 @@ const apiRequest = async () => { return true; }).catch(() => false) } -async function exchangeRates(query) { +async function exchangeRates(query: string): Promise { const data = await apiRequest(); if (!data) return ""; query = query.toLowerCase(); - var amount = query.split(' ').join(''); + var amount: string | number[] = query.split(' ').join(''); amount = amount.split(',').join(''); - amount = amount.match(/\d+/g).map(Number); - var first; - var second; + amount = amount.match(/\d+/g) && amount.match(/\d+/g).map(Number); + var first: string; + var second: string; if(query.includes("usd to pln")){ first ="USD"; second = "PLN"; @@ -132,9 +132,9 @@ async function exchangeRates(query) { if(second === "PLN"){ - var summary = amount[0] * currentPrice; + var summary: number | string = amount[0] * currentPrice; } else { - var summary = amount[0] / currentPrice; + var summary: number | string = amount[0] / currentPrice; } summary = summary.toFixed(2); @@ -152,19 +152,19 @@ async function exchangeRates(query) { `; } - -function trigger(query) { - return query === 'starwars quote' || query === 'star wars quote'; +// @ts-ignore +function trigger(query: string): boolean { + return query === "starwars quote" || query === "star wars quote"; } module.exports = { starWarsQuote, trigger }; diff --git a/server/package.json b/server/package.json index 88d3d693..44f3da6a 100644 --- a/server/package.json +++ b/server/package.json @@ -2,9 +2,9 @@ "name": "presearch-packages-test-server", "version": "0.1.0", "description": "", - "main": "index.js", + "main": "index.ts", "scripts": { - "start": "./node_modules/nodemon/bin/nodemon.js --watch ../ index.js" + "start": "./node_modules/nodemon/bin/nodemon.js --watch ../index.js --exec 'ts-node ./index.js'" }, "dependencies": { "dotenv": "^6.1.0", diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 00000000..c97abffc --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,29 @@ +{ + "compilerOptions": { + "target": "esnext", + "module": "CommonJS", + "jsx": "preserve", + "lib": ["dom", "es2017"], + "moduleResolution": "node", + "allowJs": true, + "noEmit": true, + "strict": false, + "allowSyntheticDefaultImports": true, + "skipLibCheck": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "removeComments": false, + "preserveConstEnums": true, + "sourceMap": true, + "esModuleInterop": true, + "forceConsistentCasingInFileNames": true, + "resolveJsonModule": true, + "isolatedModules": false, + "baseUrl": ".", + "paths": { + "*": ["./packages"] + } + }, + "exclude": ["node_modules"], + "include": ["**/*.ts", "**/*.tsx"] +}