@d-zero/dealer 1.2.0 → 1.3.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/dist/count-down-function-parser.d.ts +4 -0
- package/dist/count-down-function-parser.js +4 -0
- package/dist/deal.d.ts +6 -0
- package/dist/deal.js +6 -0
- package/dist/dealer.js +3 -3
- package/dist/lanes.js +1 -1
- package/dist/riffle.d.ts +7 -0
- package/dist/riffle.js +7 -0
- package/package.json +2 -2
- package/dist/animate.d.ts +0 -1
- package/dist/animate.js +0 -3
- package/dist/get-corsor-pos.d.ts +0 -1
- package/dist/get-corsor-pos.js +0 -16
- package/dist/logger.d.ts +0 -14
- package/dist/logger.js +0 -111
- package/dist/write-verbosely.d.ts +0 -1
- package/dist/write-verbosely.js +0 -3
package/dist/deal.d.ts
CHANGED
|
@@ -5,4 +5,10 @@ export type DealOptions = DealerOptions & LanesOptions & {
|
|
|
5
5
|
readonly debug?: boolean;
|
|
6
6
|
};
|
|
7
7
|
export type DealHeader = (progress: number, done: number, total: number, limit: number) => string;
|
|
8
|
+
/**
|
|
9
|
+
*
|
|
10
|
+
* @param items
|
|
11
|
+
* @param setup
|
|
12
|
+
* @param options
|
|
13
|
+
*/
|
|
8
14
|
export declare function deal<T extends WeakKey>(items: readonly T[], setup: (process: T, update: (log: string) => void, index: number) => Promise<() => void | Promise<void>> | (() => void | Promise<void>), options?: DealOptions): Promise<void>;
|
package/dist/deal.js
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { Dealer } from './dealer.js';
|
|
2
2
|
import { Lanes } from './lanes.js';
|
|
3
3
|
const DEBUG_ID = Number.MIN_SAFE_INTEGER;
|
|
4
|
+
/**
|
|
5
|
+
*
|
|
6
|
+
* @param items
|
|
7
|
+
* @param setup
|
|
8
|
+
* @param options
|
|
9
|
+
*/
|
|
4
10
|
export async function deal(items, setup, options) {
|
|
5
11
|
const dealer = new Dealer(items, options);
|
|
6
12
|
const lanes = new Lanes(options);
|
package/dist/dealer.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
export class Dealer {
|
|
2
|
+
#debug = () => { };
|
|
2
3
|
#done = new WeakSet();
|
|
3
4
|
#doneCount = 0;
|
|
5
|
+
#finish = () => { };
|
|
4
6
|
#items;
|
|
5
7
|
#limit;
|
|
8
|
+
#progress = () => { };
|
|
6
9
|
#starts = new WeakMap();
|
|
7
10
|
#workers = new Set();
|
|
8
|
-
#debug = () => { };
|
|
9
|
-
#finish = () => { };
|
|
10
|
-
#progress = () => { };
|
|
11
11
|
constructor(items, options) {
|
|
12
12
|
this.#items = items;
|
|
13
13
|
this.#limit = options?.limit ?? 10;
|
package/dist/lanes.js
CHANGED
package/dist/riffle.d.ts
CHANGED
package/dist/riffle.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@d-zero/dealer",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "A tool that provides an API and CLI for parallel processing of collections and sequential logging to standard output",
|
|
5
5
|
"author": "D-ZERO",
|
|
6
6
|
"license": "MIT",
|
|
@@ -26,5 +26,5 @@
|
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"ansi-colors": "4.1.3"
|
|
28
28
|
},
|
|
29
|
-
"gitHead": "
|
|
29
|
+
"gitHead": "e4fd17857e31022d121527b00fd7f009dbdb2142"
|
|
30
30
|
}
|
package/dist/animate.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function animate(chars: string[], time: number): string | undefined;
|
package/dist/animate.js
DELETED
package/dist/get-corsor-pos.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function getCursorPos(): Promise<[x: number, y: number]>;
|
package/dist/get-corsor-pos.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
export function getCursorPos() {
|
|
2
|
-
return new Promise((resolve) => {
|
|
3
|
-
const termcodes = { cursorGetPosition: '\u001B[6n' };
|
|
4
|
-
process.stdin.setEncoding('utf8');
|
|
5
|
-
process.stdin.setRawMode(true);
|
|
6
|
-
const readFx = function () {
|
|
7
|
-
const buf = process.stdin.read();
|
|
8
|
-
const str = JSON.stringify(buf); // "\u001b[9;1R"
|
|
9
|
-
const xy = /\[.*/.exec(str)?.[0].replaceAll(/\[|R"/g, '').split(';');
|
|
10
|
-
process.stdin.setRawMode(false);
|
|
11
|
-
resolve([Number(xy?.[1] ?? 0), Number(xy?.[0] ?? 0)]);
|
|
12
|
-
};
|
|
13
|
-
process.stdin.once('readable', readFx);
|
|
14
|
-
process.stdout.write(termcodes.cursorGetPosition);
|
|
15
|
-
});
|
|
16
|
-
}
|
package/dist/logger.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { Animations, FPS } from './types.js';
|
|
2
|
-
interface Options {
|
|
3
|
-
animations?: Animations;
|
|
4
|
-
fps?: FPS;
|
|
5
|
-
}
|
|
6
|
-
export declare class Logger {
|
|
7
|
-
#private;
|
|
8
|
-
constructor(options?: Options);
|
|
9
|
-
clear(): void;
|
|
10
|
-
close(): void;
|
|
11
|
-
verboseMode(): void;
|
|
12
|
-
write(...logs: string[]): void;
|
|
13
|
-
}
|
|
14
|
-
export {};
|
package/dist/logger.js
DELETED
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import readline from 'node:readline';
|
|
2
|
-
import c from 'ansi-colors';
|
|
3
|
-
import { countDownFunctionParser } from './count-down-function-parser.js';
|
|
4
|
-
import { riffle } from './riffle.js';
|
|
5
|
-
import { writeVerbosely } from './write-verbosely.js';
|
|
6
|
-
const animationPresets = {
|
|
7
|
-
earth: ['🌏', '🌍', '🌎'],
|
|
8
|
-
dots: ['. ', '.. ', '...'],
|
|
9
|
-
block: ['▘', '▀', '▜', '▉', '▟', '▃', '▖', ' '],
|
|
10
|
-
propeller: ['\\', '|', '/', '-'],
|
|
11
|
-
};
|
|
12
|
-
export class Logger {
|
|
13
|
-
#animations;
|
|
14
|
-
#coundDownMap = new Map();
|
|
15
|
-
#frameInterval;
|
|
16
|
-
#lastWroteLineNum = 0;
|
|
17
|
-
#stack = null;
|
|
18
|
-
#time = 0;
|
|
19
|
-
#timer = null;
|
|
20
|
-
#verbose = false;
|
|
21
|
-
constructor(options) {
|
|
22
|
-
this.#animations = {
|
|
23
|
-
...animationPresets,
|
|
24
|
-
...options?.animations,
|
|
25
|
-
};
|
|
26
|
-
const fps = options?.fps ?? 30;
|
|
27
|
-
this.#frameInterval = 1000 / fps;
|
|
28
|
-
process.stdout.on('resize', () => this.#resize());
|
|
29
|
-
}
|
|
30
|
-
clear() {
|
|
31
|
-
if (this.#verbose) {
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
const cursorY = this.#lastWroteLineNum * -1;
|
|
35
|
-
readline.moveCursor(process.stdout, 0, cursorY);
|
|
36
|
-
readline.cursorTo(process.stdout, 0);
|
|
37
|
-
}
|
|
38
|
-
close() {
|
|
39
|
-
if (this.#verbose) {
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
// Writing last stack
|
|
43
|
-
if (this.#timer) {
|
|
44
|
-
clearTimeout(this.#timer);
|
|
45
|
-
this.#timer = null;
|
|
46
|
-
}
|
|
47
|
-
this.#write();
|
|
48
|
-
this.#time = 0;
|
|
49
|
-
this.#lastWroteLineNum = 0;
|
|
50
|
-
this.#stack = null;
|
|
51
|
-
}
|
|
52
|
-
verboseMode() {
|
|
53
|
-
this.#verbose = true;
|
|
54
|
-
}
|
|
55
|
-
write(...logs) {
|
|
56
|
-
if (this.#verbose) {
|
|
57
|
-
writeVerbosely(...logs);
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
this.#stack = logs;
|
|
61
|
-
if (this.#timer) {
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
this.#run();
|
|
65
|
-
}
|
|
66
|
-
#countDown(text) {
|
|
67
|
-
const parsed = countDownFunctionParser(text);
|
|
68
|
-
if (!parsed) {
|
|
69
|
-
return text;
|
|
70
|
-
}
|
|
71
|
-
const { id, time, placeholder, unit } = parsed;
|
|
72
|
-
const currentTime = this.#coundDownMap.get(id);
|
|
73
|
-
let displayTimeMS;
|
|
74
|
-
if (currentTime == null) {
|
|
75
|
-
this.#coundDownMap.set(id, Date.now());
|
|
76
|
-
displayTimeMS = time;
|
|
77
|
-
}
|
|
78
|
-
else {
|
|
79
|
-
const elapsedTime = Date.now() - currentTime;
|
|
80
|
-
displayTimeMS = Math.max(time - elapsedTime, 0);
|
|
81
|
-
}
|
|
82
|
-
const displayTime = unit === 's' ? Math.round(displayTimeMS / 1000) : displayTimeMS;
|
|
83
|
-
return text.replace(placeholder, `${displayTime}`);
|
|
84
|
-
}
|
|
85
|
-
#resize() {
|
|
86
|
-
if (this.#verbose) {
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
this.#write();
|
|
90
|
-
}
|
|
91
|
-
#run() {
|
|
92
|
-
this.#time += 1;
|
|
93
|
-
this.#timer = setTimeout(() => this.#run(), this.#frameInterval);
|
|
94
|
-
this.#write();
|
|
95
|
-
}
|
|
96
|
-
#write() {
|
|
97
|
-
if (!this.#stack) {
|
|
98
|
-
return;
|
|
99
|
-
}
|
|
100
|
-
this.clear();
|
|
101
|
-
const reset = c.reset('');
|
|
102
|
-
for (const line of this.#stack) {
|
|
103
|
-
readline.clearLine(process.stdout, 0);
|
|
104
|
-
let text = riffle(line, this.#time, this.#animations ?? {});
|
|
105
|
-
text = this.#countDown(text);
|
|
106
|
-
const displayText = text.slice(0, process.stdout.columns);
|
|
107
|
-
process.stdout.write(`${reset}${displayText}${reset}\n`);
|
|
108
|
-
}
|
|
109
|
-
this.#lastWroteLineNum = this.#stack.length;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function writeVerbosely(...lines: string[]): void;
|
package/dist/write-verbosely.js
DELETED