@zoodogood/utils 0.8.3 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from './primitives/mod.js';
2
+ export * from './objectives/mod.js';
package/lib/index.js ADDED
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./primitives/mod.js"), exports);
18
+ __exportStar(require("./objectives/mod.js"), exports);
@@ -0,0 +1,10 @@
1
+ interface IParams {
2
+ root: string;
3
+ logger?: boolean;
4
+ }
5
+ declare const _default: ({ root, logger }: IParams) => {
6
+ run: (command: string, params: string[]) => Promise<unknown>;
7
+ info: (string: string) => Promise<void>;
8
+ _npm: string;
9
+ };
10
+ export default _default;
@@ -0,0 +1,111 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ const child_process_1 = require("child_process");
16
+ const events_1 = __importDefault(require("events"));
17
+ exports.default = ({ root, logger = false }) => {
18
+ // Solve problem: https://stackoverflow.com/questions/43230346/error-spawn-npm-enoent
19
+ const _npm = process.platform === "win32" ? "npm.cmd" : "npm";
20
+ const EventsCallbacks = [
21
+ {
22
+ key: "stdoutError",
23
+ callback({ exitData }, error) {
24
+ logger && info(`Error: ${error.message}`);
25
+ exitData.reject(error);
26
+ },
27
+ },
28
+ {
29
+ key: "stderrError",
30
+ callback({ exitData }, error) {
31
+ logger && info(`Error: ${error.message}`);
32
+ exitData.reject(error);
33
+ },
34
+ },
35
+ {
36
+ key: "stdoutData",
37
+ callback(context, data) {
38
+ const content = String(data);
39
+ context.emitter.emit("data", content);
40
+ context.outString = context.outString.concat(content);
41
+ logger && console.info(content);
42
+ },
43
+ },
44
+ {
45
+ key: "stderrData",
46
+ callback(context, data) {
47
+ const content = String(data);
48
+ context.emitter.emit("data", content);
49
+ context.outString = context.outString.concat(content);
50
+ logger && console.info(content);
51
+ },
52
+ },
53
+ {
54
+ key: "message",
55
+ callback(_context, data) {
56
+ logger && console.info(data.toString());
57
+ },
58
+ },
59
+ {
60
+ key: "exit",
61
+ callback({ exitData, outString }) {
62
+ exitData.resolve(outString);
63
+ },
64
+ },
65
+ {
66
+ key: "error",
67
+ callback({ exitData }, error) {
68
+ logger && info(`Error: ${error.message}`);
69
+ exitData.reject(error);
70
+ },
71
+ },
72
+ ];
73
+ const info = (string) => __awaiter(void 0, void 0, void 0, function* () { return console.info(`\x1b[1m${string}\x1b[22m`); });
74
+ const run = (command, params) => __awaiter(void 0, void 0, void 0, function* () {
75
+ const child = (0, child_process_1.spawn)(command, params, { cwd: root });
76
+ const exitData = { resolve: null, reject: null };
77
+ const promise = new Promise((resolve, reject) => Object.assign(exitData, { resolve, reject }));
78
+ const emitter = new events_1.default();
79
+ const outString = "";
80
+ const events = Object.fromEntries(EventsCallbacks.map(({ callback, key }) => [
81
+ key,
82
+ callback.bind(null, {
83
+ exitData,
84
+ promise,
85
+ child,
86
+ emitter,
87
+ outString,
88
+ }),
89
+ ]));
90
+ (() => {
91
+ child.stdout.on("error", events.stdoutError);
92
+ child.stderr.on("error", events.stderrError);
93
+ child.stdout.on("data", events.stdoutData);
94
+ child.stderr.on("data", events.stderrData);
95
+ child.on("error", events.error);
96
+ child.on("message", events.message);
97
+ child.on("exitData", events.exitData);
98
+ })();
99
+ promise.finally(() => {
100
+ child.stdout.removeListener("error", events.stdoutError);
101
+ child.stderr.removeListener("error", events.stderrError);
102
+ child.stdout.removeListener("data", events.stdoutData);
103
+ child.stderr.removeListener("data", events.stderrData);
104
+ child.removeListener("error", events.error);
105
+ child.removeListener("message", events.message);
106
+ child.removeListener("exitData", events.exitData);
107
+ });
108
+ return promise;
109
+ });
110
+ return { run, info, _npm };
111
+ };
@@ -0,0 +1,25 @@
1
+ /// <reference types="node" />
2
+ interface ICustomCollectorOptions {
3
+ target: Required<{
4
+ removeListener: CallableFunction;
5
+ on: CallableFunction;
6
+ }>;
7
+ event: string;
8
+ filter?: Function;
9
+ time: number;
10
+ }
11
+ declare class CustomCollector {
12
+ #private;
13
+ timeoutId?: NodeJS.Timeout;
14
+ target: ICustomCollectorOptions["target"];
15
+ event: ICustomCollectorOptions["event"];
16
+ filter: ICustomCollectorOptions["filter"];
17
+ time: ICustomCollectorOptions["time"];
18
+ constructor({ target, event, filter, time }: ICustomCollectorOptions);
19
+ setCallback(callback: CallableFunction): void;
20
+ handle(handler: CallableFunction): void;
21
+ end(): void;
22
+ removeTimeout(): void;
23
+ setTimeout(ms: number): void;
24
+ }
25
+ export { CustomCollector };
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
+ if (kind === "m") throw new TypeError("Private method is not writable");
4
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
6
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
7
+ };
8
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
10
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
11
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
+ };
13
+ var _CustomCollector_callback;
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.CustomCollector = void 0;
16
+ class CustomCollector {
17
+ constructor({ target, event, filter, time = 0 }) {
18
+ _CustomCollector_callback.set(this, void 0);
19
+ if ("on" in target === false) {
20
+ throw new Error("Target must be similar to EventEmitter.prototype — target haven't method 'on'");
21
+ }
22
+ this.target = target;
23
+ this.event = event;
24
+ this.filter = filter;
25
+ this.time = time;
26
+ }
27
+ setCallback(callback) {
28
+ const handler = (...params) => {
29
+ const passed = !this.filter || this.filter(params);
30
+ if (!!passed === true) {
31
+ // @ts-ignore
32
+ callback.apply(this, params);
33
+ }
34
+ };
35
+ this.handle(handler);
36
+ }
37
+ handle(handler) {
38
+ this.end();
39
+ __classPrivateFieldSet(this, _CustomCollector_callback, handler, "f");
40
+ this.target.on(this.event, __classPrivateFieldGet(this, _CustomCollector_callback, "f"));
41
+ if (this.time > 0) {
42
+ this.setTimeout(this.time);
43
+ }
44
+ }
45
+ end() {
46
+ if (this.timeoutId) {
47
+ this.removeTimeout();
48
+ }
49
+ if (__classPrivateFieldGet(this, _CustomCollector_callback, "f")) {
50
+ this.target.removeListener(this.event, __classPrivateFieldGet(this, _CustomCollector_callback, "f"));
51
+ }
52
+ }
53
+ removeTimeout() {
54
+ clearTimeout(this.timeoutId);
55
+ }
56
+ setTimeout(ms) {
57
+ const callback = this.end.bind(this);
58
+ this.timeoutId = setTimeout(callback, ms);
59
+ }
60
+ }
61
+ exports.CustomCollector = CustomCollector;
62
+ _CustomCollector_callback = new WeakMap();
@@ -0,0 +1,16 @@
1
+ interface IGlitchTextOptions {
2
+ step?: number;
3
+ random?: boolean;
4
+ maximum?: number;
5
+ }
6
+ declare class GlitchText {
7
+ from: string;
8
+ to: string;
9
+ step: number;
10
+ random: boolean;
11
+ maximum: number;
12
+ [Symbol.iterator]: () => Generator<string>;
13
+ constructor(from?: string, to?: string, { step, random, maximum }?: IGlitchTextOptions);
14
+ iteratorFunction(): Generator<string, void, unknown>;
15
+ }
16
+ export { GlitchText };
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GlitchText = void 0;
4
+ const getRandomValue_1 = require("./getRandomValue");
5
+ class GlitchText {
6
+ constructor(from = "", to = "hello, world", { step = 15, random = false, maximum = 100 } = {}) {
7
+ this.from = from;
8
+ this.to = to;
9
+ this.step = step;
10
+ this.random = random;
11
+ this.maximum = maximum;
12
+ this[Symbol.iterator] = this.iteratorFunction;
13
+ }
14
+ *iteratorFunction() {
15
+ const word = [...this.from];
16
+ const target = this.to;
17
+ const MIN = 20;
18
+ const MAX = 40;
19
+ while (word.length !== target.length) {
20
+ if (word.length > target.length)
21
+ word.pop();
22
+ if (word.length < target.length)
23
+ word.push(String.fromCharCode(~~(Math.random() * 50)));
24
+ word.forEach((_, index, array) => array[index] = String.fromCharCode((0, getRandomValue_1.getRandomValue)({ min: MIN, max: MAX })));
25
+ yield word.join("");
26
+ }
27
+ if (this.maximum)
28
+ for (const index in word) {
29
+ const charCode = word[index].charCodeAt(0);
30
+ const targetCode = target[index].charCodeAt(0);
31
+ if (Math.abs(charCode - targetCode) > this.maximum)
32
+ word[index] = String.fromCharCode(charCode > targetCode ?
33
+ targetCode + this.maximum :
34
+ targetCode - this.maximum);
35
+ }
36
+ ;
37
+ while (word.join("") !== target) {
38
+ word.forEach((letter, i) => {
39
+ if (letter === target[i])
40
+ return;
41
+ const charCode = letter.charCodeAt(0), targetCode = target[i].charCodeAt(0);
42
+ const isUpper = targetCode > charCode;
43
+ let step = Math.min(Math.abs(targetCode - charCode), this.step);
44
+ if (this.random)
45
+ step *= Math.random() * 2;
46
+ word[i] = String.fromCharCode(isUpper ? charCode + step : charCode - step);
47
+ });
48
+ yield word.join("");
49
+ }
50
+ return;
51
+ }
52
+ }
53
+ exports.GlitchText = GlitchText;
@@ -0,0 +1,7 @@
1
+ interface IGetRandomValueOptions {
2
+ min?: number;
3
+ max: number;
4
+ round?: boolean;
5
+ }
6
+ declare function getRandomValue({ min, max, round }: IGetRandomValueOptions): number;
7
+ export { getRandomValue };
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getRandomValue = void 0;
4
+ function getRandomValue({ min = 0, max, round = true }) {
5
+ let value = Math.random() * (max - min + Number(round)) + min;
6
+ if (round) {
7
+ value = Math.floor(value);
8
+ }
9
+ return value;
10
+ }
11
+ exports.getRandomValue = getRandomValue;
@@ -0,0 +1,7 @@
1
+ export * from './CustomCollector.js';
2
+ export * from './GlitchText.js';
3
+ export * from './getRandomValue.js';
4
+ declare function omit(object: object, filter: CallableFunction): {
5
+ [k: string]: any;
6
+ };
7
+ export { omit };
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.omit = void 0;
18
+ __exportStar(require("./CustomCollector.js"), exports);
19
+ __exportStar(require("./GlitchText.js"), exports);
20
+ __exportStar(require("./getRandomValue.js"), exports);
21
+ function omit(object, filter) {
22
+ const entries = Object.entries(object)
23
+ .filter(([key, value], i) => filter(key, value, i));
24
+ return Object.fromEntries(entries);
25
+ }
26
+ exports.omit = omit;
@@ -0,0 +1,5 @@
1
+ interface IEndingOptions {
2
+ unite?: (quantity: number, word: string) => string;
3
+ }
4
+ declare function ending(quantity: number | undefined, base: string, multiple: string, alone: string, double: string, options?: IEndingOptions): string | number;
5
+ export { ending };
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ending = void 0;
4
+ function ending(quantity = 0, base, multiple, alone, double, options = {}) {
5
+ if (isNaN(quantity))
6
+ return NaN;
7
+ const numbers = quantity % 100 > 20 ? quantity % 20 : quantity % 10;
8
+ const end = numbers >= 5 || numbers === 0 ? multiple : numbers > 1 ? double : alone;
9
+ const word = base + end;
10
+ options.unite || (options.unite = (quantity, word) => `${quantity} ${word}`);
11
+ const input = options.unite(quantity, word);
12
+ return input;
13
+ }
14
+ exports.ending = ending;
package/package.json CHANGED
@@ -1,28 +1,39 @@
1
- {
2
- "name": "@zoodogood/utils",
3
- "type": "module",
4
- "version": "0.8.3",
5
- "description": "",
6
- "main": "index.js",
7
- "homepage": "https://zoodogood.github.io/utils",
8
- "scripts": {
9
- "test": "node index",
10
- "docs-build": "cd ./docs & retype build --output ./public"
11
- },
12
- "typings": "types/index",
13
- "exports": {
14
- "./primitives": "./packages/primitives/mod.js",
15
- "./objectives": "./packages/objectives/mod.js",
16
- "./discordjs": "./packages/discordjs/mod.js"
17
- },
18
- "repository": {
19
- "type": "git",
20
- "url": "https://github.com/zoodogood/utils"
21
- },
22
- "keywords": [],
23
- "author": "",
24
- "license": "ISC",
25
- "devDependencies": {
26
- "retype": "^0.2.0"
27
- }
28
- }
1
+ {
2
+ "name": "@zoodogood/utils",
3
+ "type": "module",
4
+ "version": "0.9.0",
5
+ "description": "",
6
+ "main": "lib/index.js",
7
+ "types": "lib/index.d.ts",
8
+ "homepage": "https://zoodogood.github.io/utils",
9
+ "scripts": {
10
+ "test": "node index",
11
+ "docs-build": "cd ./docs & retype build --output ./public"
12
+ },
13
+ "typings": "types/index",
14
+ "exports": {
15
+ "./primitives": "./lib/primitives/mod.js",
16
+ "./objectives": "./lib/objectives/mod.js",
17
+ "./discordjs": "./lib/discordjs/mod.js",
18
+ "./nodejs": "./lib/nodejs/mod.js"
19
+ },
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "https://github.com/zoodogood/utils"
23
+ },
24
+ "keywords": [],
25
+ "author": "",
26
+ "license": "ISC",
27
+ "devDependencies": {
28
+ "@types/node": "^20.5.9",
29
+ "discord.js": "^14.13.0",
30
+ "retype": "^0.2.0",
31
+ "typescript": "^5.2.2"
32
+ },
33
+ "peerDependencies": {
34
+ "discord.js": "^14.13.0"
35
+ },
36
+ "files": [
37
+ "/lib/**/*"
38
+ ]
39
+ }
package/readme.md CHANGED
@@ -1,8 +1,8 @@
1
-
2
- A set of utilities in different directions for primitive data types.
3
- # Docs:
4
- https://zoodogood.github.io/utils/public
5
-
6
- ```js
7
- export { ending } from '@zoodogood/utils/primitives';
1
+
2
+ A set of utilities in different directions for primitive data types.
3
+ # Docs:
4
+ https://zoodogood.github.io/utils/public
5
+
6
+ ```js
7
+ export { ending } from '@zoodogood/utils/primitives';
8
8
  ```
package/index.js DELETED
@@ -1,7 +0,0 @@
1
- export * from './packages/primitives/mod.js';
2
- export * from './packages/objectives/mod.js';
3
-
4
-
5
-
6
-
7
-
@@ -1,129 +0,0 @@
1
- import { EmbedBuilder, ModalBuilder, resolveColor, ActionRow } from 'discord.js';
2
- import { ComponentType } from 'discord-api-types/v10';
3
-
4
-
5
-
6
- function isEmptyEmbed(embed){
7
-
8
- const DEFAULT_PROPERTIES = {
9
- title: undefined,
10
- author: undefined,
11
- thumbnail: undefined,
12
- description: undefined,
13
- fields: undefined,
14
- image: undefined,
15
- footer: undefined,
16
- timestamp: undefined,
17
- video: undefined
18
- }
19
-
20
-
21
- // in isEmptyEmbed context is a good compare
22
- const isEqualDefault = (key) => String(embed[key]) === String(DEFAULT_PROPERTIES[key]);
23
-
24
- const isEveryPropertyDefault = Object.keys(DEFAULT_PROPERTIES)
25
- .every(isEqualDefault);
26
-
27
- return isEveryPropertyDefault;
28
- }
29
-
30
-
31
- function CreateMessage({
32
- content,
33
- title, url, author, thumbnail, description, color, fields, image, video, footer, timestamp,
34
- ephemeral, fetchReply,
35
- components, files, reference
36
-
37
- }){
38
- const message = {};
39
-
40
- thumbnail &&= { url: thumbnail };
41
- image &&= { url: image };
42
- video &&= { url: video };
43
-
44
-
45
- color = resolveColor(color ?? "Random");
46
-
47
- const embed = new EmbedBuilder({
48
- title, url, author, thumbnail,
49
- description, color, fields,
50
- image, video, footer, timestamp
51
- });
52
-
53
- if (!isEmptyEmbed(embed.data)){
54
- message.embeds = [embed];
55
- }
56
-
57
- if (files){
58
- message.files = files;
59
- }
60
-
61
- if (reference)
62
- message.reply = {
63
- messageReference: reference
64
- }
65
-
66
- message.components = components ? SimplifyComponents(components) : null;
67
-
68
-
69
- message.content = content;
70
- message.ephemeral = ephemeral;
71
- message.fetchReply = fetchReply;
72
-
73
-
74
-
75
- return message;
76
- }
77
-
78
- function CreateModal({title, customId, components}){
79
- components = SimplifyComponents(components);
80
- return new ModalBuilder({title, customId, components}).toJSON();
81
- }
82
-
83
-
84
-
85
- function SimplifyComponents(data){
86
-
87
- if (data instanceof Array && data.length === 0)
88
- return [];
89
-
90
- const isComponent = (component) => "type" in component;
91
- const isActionRow = (component) => component instanceof Array && isComponent(component.at(0)) || component instanceof ActionRow;
92
- const isComponents = (component) => component.length && isActionRow(component.at(0));
93
-
94
- const argumentType = [
95
- isComponent(data),
96
- isActionRow(data),
97
- isComponents(data)
98
- ].findIndex(Boolean);
99
-
100
- if (argumentType === -1)
101
- throw new TypeError("expected component");
102
-
103
- const inArray = (component) => [component];
104
- const arrayToActionRow = (componentsArray) => {
105
- if (componentsArray.type === ComponentType.ActionRow)
106
- return componentsArray;
107
-
108
- return { type: ComponentType.ActionRow, components: componentsArray };
109
- }
110
- const actionRowInArray = (actionRow) => [actionRow];
111
-
112
-
113
- if (argumentType <= 0)
114
- data = inArray(data);
115
-
116
- if (argumentType <= 1)
117
- data = actionRowInArray(data)
118
-
119
- data = data.map(arrayToActionRow);
120
- return data;
121
-
122
- }
123
-
124
- export {
125
- CreateMessage,
126
- CreateModal,
127
- SimplifyComponents,
128
- isEmptyEmbed
129
- };
@@ -1,86 +0,0 @@
1
- /**
2
- * @typedef CustomCollectorOptions
3
- * @property {object} target
4
- * @property {string} event
5
- * @property {Function} filter
6
- * @property {number} [time=0]
7
- */
8
-
9
- class CustomCollector {
10
-
11
- /** @type {Function} */
12
- #callback;
13
-
14
- /**
15
- *
16
- * @param {CustomCollectorOptions} param0
17
- */
18
- constructor({target, event, filter, time = 0}){
19
- if ("on" in target === false){
20
- throw new Error("Target must be similar to EventEmitter.prototype — target haven't method 'on'");
21
- }
22
-
23
- this.target = target;
24
- this.event = event;
25
- this.filter = filter;
26
- this.time = time;
27
- }
28
-
29
- /**
30
- *
31
- * @param {Function} callback
32
- * @returns {void}
33
- */
34
- setCallback(callback){
35
-
36
- const handler = (...params) => {
37
- const passed = !this.filter || this.filter(params);
38
-
39
- if (!!passed === true){
40
- callback.apply(this, params);
41
- };
42
- }
43
-
44
- this.handle(handler);
45
- }
46
-
47
- /**
48
- * @param {Function} handler
49
- * @returns {void}
50
- */
51
- handle(handler){
52
- this.end();
53
-
54
- this.#callback = handler;
55
- this.target.on(this.event, this.#callback);
56
-
57
- if (this.time > 0){
58
- this.setTimeout(this.time);
59
- };
60
- }
61
-
62
- end(){
63
- if (this.timeoutId){
64
- this.removeTimeout();
65
- }
66
-
67
- if (this.#callback){
68
- this.target.removeListener(this.event, this.#callback);
69
- }
70
- }
71
-
72
- removeTimeout(){
73
- clearTimeout(this.timeoutId);
74
- }
75
-
76
- /**
77
- * @param {number} ms
78
- * @returns {void}
79
- */
80
- setTimeout(ms){
81
- const callback = this.end.bind(this);
82
- this.timeoutId = setTimeout(callback, ms);
83
- }
84
- }
85
-
86
- export { CustomCollector };
@@ -1,102 +0,0 @@
1
- import { getRandomValue } from "./mod.js";
2
-
3
- /**
4
- * @typedef {Object} GlitchTextOptions
5
- * @property {number} [step=15]
6
- * @property {boolean} [random=false]
7
- * @property {number} [maximum=100]
8
- */
9
-
10
-
11
- class GlitchText {
12
- /**
13
- *
14
- * @param {string} from
15
- * @param {string} to
16
- * @param {GlitchTextOptions} param2
17
- */
18
- constructor(from = "", to = "hello, world", {step = 15, random = false, maximum = 100} = {}){
19
- this.from = from;
20
- this.to = to;
21
-
22
- this.step = step;
23
- this.random = random;
24
- this.maximum = maximum;
25
-
26
- this[Symbol.iterator] = this.iteratorFunction;
27
- }
28
-
29
- /**
30
- * @generator
31
- * @yields {string}
32
- */
33
- *iteratorFunction(){
34
- const word = [...this.from];
35
- const target = this.to;
36
- const MIN = 20;
37
- const MAX = 40;
38
-
39
- while (word.length !== target.length){
40
- if (word.length > target.length)
41
- word.pop();
42
-
43
- if (word.length < target.length)
44
- word.push( String.fromCharCode(~~(Math.random() * 50)) );
45
-
46
- word.forEach((_, index, array) =>
47
- array[index] = String.fromCharCode( getRandomValue({min: MIN, max: MAX}) ));
48
-
49
- yield word.join("");
50
- }
51
-
52
-
53
- if (this.maximum)
54
- for (const index in word){
55
- const charCode = word[ index ].charCodeAt(0);
56
- const targetCode = target[ index ].charCodeAt(0);
57
-
58
- if (Math.abs(charCode - targetCode) > this.maximum)
59
- word[ index ] = String.fromCharCode(
60
- charCode > targetCode ?
61
- targetCode + this.maximum :
62
- targetCode - this.maximum
63
- );
64
-
65
- };
66
-
67
-
68
-
69
- while ( word.join("") !== target ){
70
-
71
- word.forEach((letter, i) => {
72
- if (letter === target[i])
73
- return;
74
-
75
-
76
- const
77
- charCode = letter.charCodeAt(0),
78
- targetCode = target[i].charCodeAt(0);
79
-
80
- const isUpper = targetCode > charCode;
81
-
82
- let step = Math.min(
83
- Math.abs(targetCode - charCode),
84
- this.step
85
- );
86
-
87
- if (this.random)
88
- step *= Math.random() * 2;
89
-
90
- word[i] = String.fromCharCode( isUpper ? charCode + step : charCode - step );
91
- });
92
-
93
- yield word.join("");
94
- }
95
-
96
-
97
- return;
98
- }
99
- }
100
-
101
-
102
- export { GlitchText };
@@ -1,40 +0,0 @@
1
- export * from './CustomCollector.js';
2
- export * from './GlitchText.js';
3
-
4
- /**
5
- * @param {object} object
6
- * @param {(argv0: string, argv1: unknown, argv2: number) => void} filter
7
- * @returns {object}
8
- */
9
- function omit(object, filter){
10
- const entries = Object.entries(object)
11
- .filter(([key, value], i) => filter(key, value, i));
12
-
13
- return Object.fromEntries(entries);
14
- }
15
-
16
-
17
-
18
-
19
- /**
20
- * @typedef GetRandomValueOptions
21
- * @property {number} [min = 0]
22
- * @property {number} max
23
- * @property {boolean} [round=true]
24
- */
25
-
26
- /**
27
- *
28
- * @param {GetRandomValueOptions} param0
29
- * @returns {number}
30
- */
31
- function getRandomValue({min = 0, max, round = true}){
32
- let value = Math.random() * (max - min + Number(round)) + min;
33
-
34
- if (round){
35
- value = Math.floor(value);
36
- }
37
- return value;
38
- }
39
-
40
- export { omit, getRandomValue };
@@ -1,40 +0,0 @@
1
- /**
2
- * @typedef EndingOptions
3
- * @property {(argv1: number, argv2: string) => string} [unite]
4
- */
5
-
6
- /**
7
- * @param {number} quantity
8
- * @param {string} base
9
- * @param {string} multiple
10
- * @param {string} alone
11
- * @param {string} double
12
- * @param {EndingOptions} options
13
- * @returns {string|NaN}
14
- */
15
- function ending(quantity = 0, base, multiple, alone, double, options = {}) {
16
- if ( isNaN(quantity) )
17
- return NaN;
18
-
19
-
20
- const numbers = quantity % 100 > 20 ?
21
- quantity % 20 :
22
- quantity % 10;
23
-
24
- const end = (numbers >= 5 || numbers === 0) ?
25
- multiple :
26
- (numbers > 1) ? double : alone;
27
-
28
- const word = base + end;
29
-
30
- options.unite ||= (quantity, word) => `${ quantity } ${ word }`;
31
-
32
- const input = options.unite(quantity, word);
33
- return input;
34
- };
35
-
36
-
37
- export {
38
- ending
39
- }
40
-
package/retype.yml DELETED
@@ -1,11 +0,0 @@
1
- input: .
2
- output: .retype
3
- url: # Add your website address here
4
- branding:
5
- title: Project Name
6
- label: &268245847 Docs
7
- links:
8
- - text: Docs
9
- link: /docs
10
- footer:
11
- copyright: "&copy; Copyright {{ year }}. All rights reserved."
package/tsconfig.json DELETED
@@ -1,103 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- /* Visit https://aka.ms/tsconfig to read more about this file */
4
-
5
- /* Projects */
6
- // "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
7
- // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
8
- // "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */
9
- // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */
10
- // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
11
- // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
12
-
13
- /* Language and Environment */
14
- "target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
15
- // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
16
- // "jsx": "preserve", /* Specify what JSX code is generated. */
17
- // "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */
18
- // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
19
- // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */
20
- // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
21
- // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */
22
- // "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */
23
- // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
24
- // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
25
- // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
26
-
27
- /* Modules */
28
- "module": "commonjs", /* Specify what module code is generated. */
29
- // "rootDir": "./", /* Specify the root folder within your source files. */
30
- // "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */
31
- // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
32
- // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
33
- // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
34
- // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
35
- // "types": [], /* Specify type package names to be included without being referenced in a source file. */
36
- // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
37
- // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
38
- // "resolveJsonModule": true, /* Enable importing .json files. */
39
- // "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */
40
-
41
- /* JavaScript Support */
42
- // "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
43
- // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
44
- // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
45
-
46
- /* Emit */
47
- // "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
48
- // "declarationMap": true, /* Create sourcemaps for d.ts files. */
49
- // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
50
- // "sourceMap": true, /* Create source map files for emitted JavaScript files. */
51
- // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
52
- // "outDir": "./", /* Specify an output folder for all emitted files. */
53
- // "removeComments": true, /* Disable emitting comments. */
54
- // "noEmit": true, /* Disable emitting files from a compilation. */
55
- // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
56
- // "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */
57
- // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
58
- // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
59
- // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
60
- // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
61
- // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
62
- // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
63
- // "newLine": "crlf", /* Set the newline character for emitting files. */
64
- // "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */
65
- // "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */
66
- // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
67
- // "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
68
- // "declarationDir": "./", /* Specify the output directory for generated declaration files. */
69
- // "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */
70
-
71
- /* Interop Constraints */
72
- // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
73
- // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
74
- "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
75
- // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
76
- "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
77
-
78
- /* Type Checking */
79
- "strict": true, /* Enable all strict type-checking options. */
80
- // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
81
- // "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
82
- // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
83
- // "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
84
- // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
85
- // "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
86
- // "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */
87
- // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
88
- // "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */
89
- // "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */
90
- // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
91
- // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
92
- // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
93
- // "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
94
- // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
95
- // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */
96
- // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
97
- // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
98
-
99
- /* Completeness */
100
- // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
101
- "skipLibCheck": true /* Skip type checking all .d.ts files. */
102
- }
103
- }
package/types/index.d.ts DELETED
@@ -1,2 +0,0 @@
1
- export * from "./packages/primitives/mod.js";
2
- export * from "./packages/objectives/mod.js";
@@ -1,44 +0,0 @@
1
- export type CustomCollectorOptions = {
2
- target: object;
3
- event: string;
4
- filter: Function;
5
- time?: number;
6
- };
7
- /**
8
- * @typedef CustomCollectorOptions
9
- * @property {object} target
10
- * @property {string} event
11
- * @property {Function} filter
12
- * @property {number} [time=0]
13
- */
14
- export class CustomCollector {
15
- /**
16
- *
17
- * @param {CustomCollectorOptions} param0
18
- */
19
- constructor({ target, event, filter, time }: CustomCollectorOptions);
20
- target: any;
21
- event: string;
22
- filter: Function;
23
- time: number;
24
- /**
25
- *
26
- * @param {Function} callback
27
- * @returns {void}
28
- */
29
- setCallback(callback: Function): void;
30
- /**
31
- * @param {Function} handler
32
- * @returns {void}
33
- */
34
- handle(handler: Function): void;
35
- end(): void;
36
- removeTimeout(): void;
37
- /**
38
- * @param {number} ms
39
- * @returns {void}
40
- */
41
- setTimeout(ms: number): void;
42
- timeoutId: number;
43
- #private;
44
- }
@@ -1,30 +0,0 @@
1
- export type GlitchTextOptions = {
2
- step?: number;
3
- random?: boolean;
4
- maximum?: number;
5
- };
6
- /**
7
- * @typedef {Object} GlitchTextOptions
8
- * @property {number} [step=15]
9
- * @property {boolean} [random=false]
10
- * @property {number} [maximum=100]
11
- */
12
- export class GlitchText {
13
- /**
14
- *
15
- * @param {string} from
16
- * @param {string} to
17
- * @param {GlitchTextOptions} param2
18
- */
19
- constructor(from?: string, to?: string, { step, random, maximum }?: GlitchTextOptions);
20
- from: string;
21
- to: string;
22
- step: number;
23
- random: boolean;
24
- maximum: number;
25
- /**
26
- * @generator
27
- * @yields {string}
28
- */
29
- iteratorFunction(): {};
30
- }
@@ -1,25 +0,0 @@
1
- export * from "./CustomCollector.js";
2
- export * from "./GlitchText.js";
3
- export type GetRandomValueOptions = {
4
- min?: number;
5
- max: number;
6
- round?: boolean;
7
- };
8
- /**
9
- * @param {object} object
10
- * @param {(argv0: string, argv1: unknown, argv2: number) => void} filter
11
- * @returns {object}
12
- */
13
- export function omit(object: object, filter: (argv0: string, argv1: unknown, argv2: number) => void): object;
14
- /**
15
- * @typedef GetRandomValueOptions
16
- * @property {number} [min = 0]
17
- * @property {number} max
18
- * @property {boolean} [round=true]
19
- */
20
- /**
21
- *
22
- * @param {GetRandomValueOptions} param0
23
- * @returns {number}
24
- */
25
- export function getRandomValue({ min, max, round }: GetRandomValueOptions): number;
@@ -1,17 +0,0 @@
1
- export type EndingOptions = {
2
- unite?: (argv1: number, argv2: string) => string;
3
- };
4
- /**
5
- * @typedef EndingOptions
6
- * @property {(argv1: number, argv2: string) => string} [unite]
7
- */
8
- /**
9
- * @param {number} quantity
10
- * @param {string} base
11
- * @param {string} multiple
12
- * @param {string} alone
13
- * @param {string} double
14
- * @param {EndingOptions} options
15
- * @returns {string|NaN}
16
- */
17
- export function ending(quantity: number, base: string, multiple: string, alone: string, double: string, options?: EndingOptions): string | number;