Skip to content

Commit

Permalink
feat: new functions, duplicates removal
Browse files Browse the repository at this point in the history
  • Loading branch information
Dreamyplayer committed Sep 28, 2022
1 parent 22e8979 commit 2aeacc4
Showing 1 changed file with 38 additions and 74 deletions.
112 changes: 38 additions & 74 deletions src/gen.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
/* eslint-disable no-sequences */
const mkdir = require('mkdirp');
const { performance } = require('node:perf_hooks');
const { green, bgBlue, red, cyan } = require('colorette');
const {
RAN_GEN_1,
RAN_GEN_2,
Expand All @@ -10,101 +13,62 @@ const {
RAN_GEN_Shuff,
RAN_GEN_TOP,
} = require('../utils/genfunctions');
const { numberFormat, duration, wait } = require('../utils/functions');
const ms = require('ms');
const { compactMode, wait } = require('../utils/functions');
const { existsSync, unlinkSync, createWriteStream } = require('node:fs');
const { mkdir, performance, chalk } = require('../utils/modules');
const { length, random, amount, outfile } = require('../config').generator;

(module.exports = (e = 16, _ = !1, N = 1, o) =>
(module.exports = (codesLength = 16, _ = !1, N = 1, o) =>
new Promise(async n => {
const r = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789×';
const t = r.length - 1;
const l = [];
o && existsSync(o) && unlinkSync(o);
const E = performance.now();
if (_) {
require.main === module &&
wait(2000).then(() => {
console.log(
`${chalk.bgBlue('[Developing]')} ${chalk.green(numberFormat(N))} codes of length ${chalk.red(e)}.\n`,
);
});
require.main === module &&
wait(2000).then(() => {
console.log(
`${bgBlue('[Developing]')} ${green(compactMode({ date: N, formatType: 'Number' }))} codes of length ${red(
codesLength,
)}.\n`,
);
});

for (let _ = 0; _ < N; _++) {
let _ = '';
if (e === 24) {
let e = [
RAN_GEN_1(24),
RAN_GEN_2(24),
RAN_GEN_3(24),
RAN_GEN_4,
RAN_GEN_Direct,
RAN_GEN_TOP(24),
RAN_GEN_Shuff(RAN_GEN_1(24)),
RAN_GEN_Shuff(RAN_GEN_2(24)),
RAN_GEN_Shuff(RAN_GEN_3(24)),
RAN_GEN_Shuff(RAN_GEN_TOP(24)),
];
_ = e[Math.floor(Math.random() * e.length)];
} else {
let e = [
RAN_GEN_1(16),
RAN_GEN_2(16),
RAN_GEN_3(16),
RAN_GEN_4_C,
RAN_GEN_Direct_C,
RAN_GEN_TOP(16),
RAN_GEN_Shuff(RAN_GEN_1(16)),
RAN_GEN_Shuff(RAN_GEN_2(16)),
RAN_GEN_Shuff(RAN_GEN_3(16)),
RAN_GEN_Shuff(RAN_GEN_TOP(16)),
];
_ = e[Math.floor(Math.random() * e.length)];
}
l.push(_);
}
} else {
const o = _ ? r.length ** e : N;
require.main === module &&
wait(4000).then(() => {
console.log(
`${chalk.bgBlue('[Developing]')} ${chalk.green(numberFormat(o))} codes of length ${chalk.red(e)}.\n`,
);
});
for (let _ = 0; _ < N; _++) {
let _ = '';
let e = [
RAN_GEN_1(codesLength),
RAN_GEN_2(codesLength),
RAN_GEN_3(codesLength),
RAN_GEN_4,
RAN_GEN_4_C,
RAN_GEN_Direct,
RAN_GEN_Direct_C,
RAN_GEN_TOP(codesLength),
RAN_GEN_Shuff(RAN_GEN_1(codesLength)),
RAN_GEN_Shuff(RAN_GEN_2(codesLength)),
RAN_GEN_Shuff(RAN_GEN_3(codesLength)),
RAN_GEN_Shuff(RAN_GEN_TOP(codesLength)),
];
_ = e[Math.floor(Math.random() * e.length)];

let n = Array(e).fill(0);
for (; l.length < o; ) {
let _ = '';
for (let N = 0; N < e; N++) _ += r[n[N]];
l.push(_);
let N = !1;
for (let _ = 0; _ < e; _++) {
if (n[_] < t) {
n[_]++, (N = !0);
for (let e = 0; e < _; e++) n[e] = 0;
break;
}
n[_];
}
if (!N) break;
}
l.push(_);
}

const R = performance.now();
if (o) {
await mkdir(o.match(/.*(\/|\\)/g)[0]);
const e = createWriteStream(o, { encoding: 'utf-8' });
e.write(l.join('\n')), e.close();
e.write(Array.from(new Set(l)).join('\n').toString()), e.close();
}
n({ start: E, end: R, codes: l });
})),
require.main === module &&
(console.log(`${chalk.bgBlue('[Establishing]')} Generation. . .\n`),
(console.log(`${bgBlue('[Establishing]')} Generation. . .\n`),
module.exports(length, random, amount, outfile).then(e => {
wait(6000).then(() => {
console.info(
`${chalk.bgBlue('[END]')} Coffee Break ${chalk.cyan(
duration(e.end - e.start, !0, !0),
)} 🍵 - Developed ${chalk.green(numberFormat(e.codes.length))} codes`,
`${bgBlue('[END]')} Coffee Break ${cyan(
e.end - e.start <= 1000 ? (e.end - e.start).toString().split('.')[0] + 'ms' : ms(e.end - e.start),
)} 🍵 - Developed ${green(compactMode({ date: e.codes.length, formatType: 'Number' }))} codes`,
);
});
}));

0 comments on commit 2aeacc4

Please sign in to comment.