migrated generators to TS!!

pull/62/head
tycrek 3 years ago
parent 81bf01d550
commit e1032588c5
No known key found for this signature in database
GPG Key ID: 25D74F3943625263

52
package-lock.json generated

@ -14,6 +14,8 @@
"@tycrek/express-nofavicon": "^1.0.2",
"@tycrek/isprod": "^2.0.2",
"@tycrek/log": ">=0.5.x",
"@types/fs-extra": "^9.0.12",
"@types/node": "^14.17.15",
"@types/ws": "^7.4.7",
"any-shell-escape": "^0.1.1",
"aws-sdk": "^2.930.0",
@ -722,10 +724,18 @@
"url": "https://patreon.com/tycrek"
}
},
"node_modules/@types/fs-extra": {
"version": "9.0.12",
"resolved": "https://registry.npmjs.org/@types/fs-extra/-/fs-extra-9.0.12.tgz",
"integrity": "sha512-I+bsBr67CurCGnSenZZ7v94gd3tc3+Aj2taxMT4yu4ABLuOgOjeFxX3dokG24ztSRg5tnT00sL8BszO7gSMoIw==",
"dependencies": {
"@types/node": "*"
}
},
"node_modules/@types/node": {
"version": "10.17.60",
"resolved": "https://registry.npmjs.org/@types/node/-/node-10.17.60.tgz",
"integrity": "sha512-F0KIgDJfy2nA3zMLmWGKxcH2ZVEtCZXHHdOQs2gSaQ27+lNeEfGxzkIw90aXswATX7AZ33tahPbzy6KAfUreVw=="
"version": "14.17.15",
"resolved": "https://registry.npmjs.org/@types/node/-/node-14.17.15.tgz",
"integrity": "sha512-D1sdW0EcSCmNdLKBGMYb38YsHUS6JcM7yQ6sLQ9KuZ35ck7LYCKE7kYFHOO59ayFOY3zobWVZxf4KXhYHcHYFA=="
},
"node_modules/@types/ws": {
"version": "7.4.7",
@ -2260,6 +2270,11 @@
"@types/node": "^10.0.3"
}
},
"node_modules/http-response-object/node_modules/@types/node": {
"version": "10.17.60",
"resolved": "https://registry.npmjs.org/@types/node/-/node-10.17.60.tgz",
"integrity": "sha512-F0KIgDJfy2nA3zMLmWGKxcH2ZVEtCZXHHdOQs2gSaQ27+lNeEfGxzkIw90aXswATX7AZ33tahPbzy6KAfUreVw=="
},
"node_modules/https-proxy-agent": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-5.0.0.tgz",
@ -2900,6 +2915,11 @@
"url": "^0.11.0"
}
},
"node_modules/node-vibrant/node_modules/@types/node": {
"version": "10.17.60",
"resolved": "https://registry.npmjs.org/@types/node/-/node-10.17.60.tgz",
"integrity": "sha512-F0KIgDJfy2nA3zMLmWGKxcH2ZVEtCZXHHdOQs2gSaQ27+lNeEfGxzkIw90aXswATX7AZ33tahPbzy6KAfUreVw=="
},
"node_modules/node-vibrant/node_modules/url": {
"version": "0.11.0",
"resolved": "https://registry.npmjs.org/url/-/url-0.11.0.tgz",
@ -5085,10 +5105,18 @@
"use-climate-change-reminder": "^0.0.7"
}
},
"@types/fs-extra": {
"version": "9.0.12",
"resolved": "https://registry.npmjs.org/@types/fs-extra/-/fs-extra-9.0.12.tgz",
"integrity": "sha512-I+bsBr67CurCGnSenZZ7v94gd3tc3+Aj2taxMT4yu4ABLuOgOjeFxX3dokG24ztSRg5tnT00sL8BszO7gSMoIw==",
"requires": {
"@types/node": "*"
}
},
"@types/node": {
"version": "10.17.60",
"resolved": "https://registry.npmjs.org/@types/node/-/node-10.17.60.tgz",
"integrity": "sha512-F0KIgDJfy2nA3zMLmWGKxcH2ZVEtCZXHHdOQs2gSaQ27+lNeEfGxzkIw90aXswATX7AZ33tahPbzy6KAfUreVw=="
"version": "14.17.15",
"resolved": "https://registry.npmjs.org/@types/node/-/node-14.17.15.tgz",
"integrity": "sha512-D1sdW0EcSCmNdLKBGMYb38YsHUS6JcM7yQ6sLQ9KuZ35ck7LYCKE7kYFHOO59ayFOY3zobWVZxf4KXhYHcHYFA=="
},
"@types/ws": {
"version": "7.4.7",
@ -6310,6 +6338,13 @@
"integrity": "sha512-bqX0XTF6fnXSQcEJ2Iuyr75yVakyjIDCqroJQ/aHfSdlM743Cwqoi2nDYMzLGWUcuTWGWy8AAvOKXTfiv6q9RA==",
"requires": {
"@types/node": "^10.0.3"
},
"dependencies": {
"@types/node": {
"version": "10.17.60",
"resolved": "https://registry.npmjs.org/@types/node/-/node-10.17.60.tgz",
"integrity": "sha512-F0KIgDJfy2nA3zMLmWGKxcH2ZVEtCZXHHdOQs2gSaQ27+lNeEfGxzkIw90aXswATX7AZ33tahPbzy6KAfUreVw=="
}
}
},
"https-proxy-agent": {
@ -6805,6 +6840,11 @@
"url": "^0.11.0"
},
"dependencies": {
"@types/node": {
"version": "10.17.60",
"resolved": "https://registry.npmjs.org/@types/node/-/node-10.17.60.tgz",
"integrity": "sha512-F0KIgDJfy2nA3zMLmWGKxcH2ZVEtCZXHHdOQs2gSaQ27+lNeEfGxzkIw90aXswATX7AZ33tahPbzy6KAfUreVw=="
},
"url": {
"version": "0.11.0",
"resolved": "https://registry.npmjs.org/url/-/url-0.11.0.tgz",

@ -41,6 +41,8 @@
"@tycrek/express-nofavicon": "^1.0.2",
"@tycrek/isprod": "^2.0.2",
"@tycrek/log": ">=0.5.x",
"@types/fs-extra": "^9.0.12",
"@types/node": "^14.17.15",
"@types/ws": "^7.4.7",
"any-shell-escape": "^0.1.1",
"aws-sdk": "^2.930.0",
@ -67,4 +69,4 @@
"ts": "^0.2.2",
"uuid": "^8.3.2"
}
}
}

@ -1,10 +1,10 @@
const fs = require('fs-extra');
import fs from 'fs-extra';
// Don't trigger circular dependency during setup
if (!require.main.filename.includes('setup.js'))
if (require !== undefined && !require?.main?.filename.includes('setup.js'))
var MIN_LENGTH = require('../setup').gfyIdSize; // skipcq: JS-0239, JS-0102
function getWord(list, delim = '') {
function getWord(list: string[], delim = '') {
return list[Math.floor(Math.random() * list.length)].concat(delim);
}
@ -20,4 +20,4 @@ function genString(count = MIN_LENGTH) {
return gfycat.concat(getWord(animals));
};
module.exports = ({ gfyLength }) => genString(gfyLength);
module.exports = ({ gfyLength }: { gfyLength: number }) => genString(gfyLength);

@ -1,2 +0,0 @@
const { randomBytes } = require('crypto');
module.exports = (length, charset) => [...randomBytes(length)].map((byte) => charset[Number(byte) % charset.length]).join('').slice(1).concat(charset[0]);

@ -0,0 +1,2 @@
import { randomBytes } from 'crypto';
module.exports = (length: number, charset: string[]): string => [...randomBytes(length)].map((byte) => charset[Number(byte) % charset.length]).join('').slice(1).concat(charset[0]);

@ -1,2 +0,0 @@
const cryptoRandomString = require('crypto-random-string');
module.exports = ({ length }) => cryptoRandomString({ length, type: 'alphanumeric' });

@ -0,0 +1,2 @@
import cryptoRandomString from 'crypto-random-string';
module.exports = ({ length }: { length: number }) => cryptoRandomString({ length, type: 'alphanumeric' });

@ -1,5 +1,5 @@
const uuid = require('uuid').v4;
const fs = require('fs-extra');
import fs from 'fs-extra';
const path = require('path');
const randomGen = require('./random');
const TLog = require('@tycrek/log');
@ -20,7 +20,7 @@ if (require.main === module) {
// Generate the user
const username = process.argv[2] ? process.argv[2].replace(/[^\da-z_]/gi, '').substring(0, MAX_USERNAME) : randomGen({ length: 20 }); // skipcq: JS-0074
if (!auth.users) auth.users = {};
if (Object.values(auth.users).findIndex((user) => user.username === username) !== -1) {
if (Object.values(auth.users).findIndex((user: any) => user.username === username) !== -1) {
log.error('Username already exists', username);
process.exit(1);
}

@ -1,3 +1,3 @@
const lengthGen = require('./lengthGen');
const zeroWidthChars = ['\u200B', '\u200C', '\u200D', '\u2060'];
module.exports = ({ length }) => lengthGen(length, zeroWidthChars);
module.exports = ({ length }: { length: number }) => lengthGen(length, zeroWidthChars);

@ -1,14 +1,16 @@
{
"extends": "@tsconfig/node14/tsconfig.json",
"compilerOptions": {
"allowJs": true,
"lib": [
"ES2020",
"DOM"
]
],
"allowJs": true,
"downlevelIteration": true
},
"include": [
"src/**/*.js"
"src/**/*.js",
"src/**/*.ts"
],
"exclude": [
"ass-x"

Loading…
Cancel
Save