Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore/typescript: Migrate to typescript. #76

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 64 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 1 addition & 30 deletions package.json
Original file line number Diff line number Diff line change
@@ -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"}}
45 changes: 28 additions & 17 deletions packages/apod/index.js → packages/apod/index.ts
Original file line number Diff line number Diff line change
@@ -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<string> {
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 `
<div class="answerCol">
<h3 class="apodLabel">Astronomy Picture of the Day</h3>
<div class="answerRow">
<div class="mainCol">
${data.url
? data.media_type === 'video'
? `<iframe src="${data.url}" title="${data.title}" class="apodIframe" type="text/html" frameBorder="0"></iframe>`
: `<img src="${data.url}" class="apodImage" alt="${data.title}" />`
: ``
${
data.url
? data.media_type === "video"
? `<iframe src="${data.url}" title="${data.title}" class="apodIframe" type="text/html" frameBorder="0"></iframe>`
: `<img src="${data.url}" class="apodImage" alt="${data.title}" />`
: ``
}
</div>
<div class="sideCol apodSideContain">
${data.title ? `<h2 class="apodName">${data.title}</h2>` : ``}
${data.copyright ? `<p class="apodAuthor">By ${data.copyright}</p>` : ``}
${
data.copyright
? `<p class="apodAuthor">By ${data.copyright}</p>`
: ``
}
${data.date ? `<p class="apodDate">${data.date}</p>` : ``}
${data.explanation ? `<p class="apodDesc">${data.explanation}</p>` : ``}
${
data.explanation
? `<p class="apodDesc">${data.explanation}</p>`
: ``
}
<a href="https://apod.nasa.gov" class="apodLink">apod.nasa.gov</a>
</div>
</div>
Expand Down Expand Up @@ -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 };
2 changes: 1 addition & 1 deletion packages/apod/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
8 changes: 8 additions & 0 deletions packages/apod/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export type IApod = {
url: string;
media_type: string;
title: string;
date: string;
copyright: string;
explanation: string;
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"use strict";

async function colorGenerator(query) {
function colorGenerator(_query: string): string {
return `<style>
.main {
width: 100%;
Expand Down Expand Up @@ -78,7 +76,7 @@ async function colorGenerator(query) {
margin: 0;
}
}

</style>
<div class="main noselect">
<div id="container1" class="sub pos0">
Expand Down Expand Up @@ -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 };


46 changes: 32 additions & 14 deletions packages/colorPicker/index.js → packages/colorPicker/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
'use strict';
"use strict";

function colorPicker(query) {

return `
function colorPicker(_query: string): string {
return `
<style>
#layer1 {
border-radius: 10px;
Expand Down Expand Up @@ -386,13 +385,32 @@ function colorPicker(query) {
});
})();
</script>
`
}

function trigger(query) {
query = query.toLowerCase();
return query === 'color picker' || query === 'colorpicker' || query === 'html color picker' || query === 'rgb palette' || query === 'rgb color' || query === 'rgb color code'
|| query === 'rgb code' || query === 'rgb picker' || query === 'hex color' || query === 'hex color code' || query === 'hex to rgb' || query === 'rgb to hex';
}

module.exports = { colorPicker, trigger };
`;
}

// @ts-ignore
function trigger(query: string | string[]): boolean {
query = (query as string).toLowerCase().split(" ");
const queryList = [
"color picker",
"colorpicker",
"html color picker",
"rgb palette",
"rgb color",
"rgb color code",
"rgb code",
"rgb picker",
"hex color",
"hex color code",
"hex to rgb",
"rgb to hex",
];
const filteredList = queryList.filter((item) =>
(query as string[]).every(
(el: string) => item.toLowerCase().indexOf(el) > -1
)
);
return !!filteredList.length;
}

module.exports = { colorPicker, trigger };
Loading