@kidus.dev/flowdb 1.0.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/README.md +15 -0
- package/dist/core/blob/blob.d.ts +25 -0
- package/dist/core/blob/blob.d.ts.map +1 -0
- package/dist/core/blob/blob.js +57 -0
- package/dist/core/blob/blob_disk_driver.d.ts +27 -0
- package/dist/core/blob/blob_disk_driver.d.ts.map +1 -0
- package/dist/core/blob/blob_disk_driver.js +179 -0
- package/dist/core/blob/blob_storage.d.ts +90 -0
- package/dist/core/blob/blob_storage.d.ts.map +1 -0
- package/dist/core/blob/blob_storage.js +248 -0
- package/dist/core/collection/collection.d.ts +99 -0
- package/dist/core/collection/collection.d.ts.map +1 -0
- package/dist/core/collection/collection.js +226 -0
- package/dist/core/collection/document.d.ts +24 -0
- package/dist/core/collection/document.d.ts.map +1 -0
- package/dist/core/collection/document.js +86 -0
- package/dist/core/collection/driver/collection_file_driver.d.ts +20 -0
- package/dist/core/collection/driver/collection_file_driver.d.ts.map +1 -0
- package/dist/core/collection/driver/collection_file_driver.js +90 -0
- package/dist/core/collection/driver/collection_operations.d.ts +43 -0
- package/dist/core/collection/driver/collection_operations.d.ts.map +1 -0
- package/dist/core/collection/driver/collection_operations.js +278 -0
- package/dist/core/collection/query/compares.d.ts +90 -0
- package/dist/core/collection/query/compares.d.ts.map +1 -0
- package/dist/core/collection/query/compares.js +362 -0
- package/dist/core/collection/query/filtering.d.ts +14 -0
- package/dist/core/collection/query/filtering.d.ts.map +1 -0
- package/dist/core/collection/query/filtering.js +176 -0
- package/dist/core/collection/query/query_builder.d.ts +145 -0
- package/dist/core/collection/query/query_builder.d.ts.map +1 -0
- package/dist/core/collection/query/query_builder.js +196 -0
- package/dist/core/collection/query/query_executor.d.ts +87 -0
- package/dist/core/collection/query/query_executor.d.ts.map +1 -0
- package/dist/core/collection/query/query_executor.js +348 -0
- package/dist/core/collection/query/relation.d.ts +29 -0
- package/dist/core/collection/query/relation.d.ts.map +1 -0
- package/dist/core/collection/query/relation.js +40 -0
- package/dist/core/database/backup.d.ts +26 -0
- package/dist/core/database/backup.d.ts.map +1 -0
- package/dist/core/database/backup.js +114 -0
- package/dist/core/database/database.d.ts +57 -0
- package/dist/core/database/database.d.ts.map +1 -0
- package/dist/core/database/database.js +179 -0
- package/dist/core/database/database_file_driver.d.ts +27 -0
- package/dist/core/database/database_file_driver.d.ts.map +1 -0
- package/dist/core/database/database_file_driver.js +135 -0
- package/dist/core/store/store.d.ts +24 -0
- package/dist/core/store/store.d.ts.map +1 -0
- package/dist/core/store/store.js +54 -0
- package/dist/core/store/store_file_driver.d.ts +26 -0
- package/dist/core/store/store_file_driver.d.ts.map +1 -0
- package/dist/core/store/store_file_driver.js +87 -0
- package/dist/tools/encryptor.d.ts +17 -0
- package/dist/tools/encryptor.d.ts.map +1 -0
- package/dist/tools/encryptor.js +80 -0
- package/dist/tools/format.d.ts +10 -0
- package/dist/tools/format.d.ts.map +1 -0
- package/dist/tools/format.js +40 -0
- package/dist/tools/index.d.ts +7 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +6 -0
- package/dist/tools/json.d.ts +19 -0
- package/dist/tools/json.d.ts.map +1 -0
- package/dist/tools/json.js +232 -0
- package/dist/tools/performance.d.ts +20 -0
- package/dist/tools/performance.d.ts.map +1 -0
- package/dist/tools/performance.js +53 -0
- package/dist/tools/print_colored.d.ts +47 -0
- package/dist/tools/print_colored.d.ts.map +1 -0
- package/dist/tools/print_colored.js +119 -0
- package/dist/tools/random.d.ts +46 -0
- package/dist/tools/random.d.ts.map +1 -0
- package/dist/tools/random.js +214 -0
- package/package.json +40 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
export declare enum PrintColor {
|
|
2
|
+
red = 31,
|
|
3
|
+
green = 32,
|
|
4
|
+
yellow = 33,
|
|
5
|
+
blue = 34,
|
|
6
|
+
magenta = 35,
|
|
7
|
+
white = 37,
|
|
8
|
+
black = 30,
|
|
9
|
+
grey = 90,
|
|
10
|
+
lightGrey = 97,
|
|
11
|
+
lightRed = 91,
|
|
12
|
+
lightGreen = 92,
|
|
13
|
+
lightYellow = 93,
|
|
14
|
+
lightBlue = 94,
|
|
15
|
+
lightMagenta = 95,
|
|
16
|
+
lightCyan = 96,
|
|
17
|
+
lightWhite = 97
|
|
18
|
+
}
|
|
19
|
+
export declare class Output {
|
|
20
|
+
text: string;
|
|
21
|
+
color?: PrintColor;
|
|
22
|
+
isBold: boolean;
|
|
23
|
+
constructor(text: string, color?: PrintColor, isBold?: boolean);
|
|
24
|
+
}
|
|
25
|
+
export default class PrintColored {
|
|
26
|
+
outputs: Output[];
|
|
27
|
+
chain(text: string, color?: PrintColor, isBold?: boolean): this;
|
|
28
|
+
chainln(text: string, color?: PrintColor, isBold?: boolean): this;
|
|
29
|
+
printit(): void;
|
|
30
|
+
getIt(): string;
|
|
31
|
+
throwIt(): never;
|
|
32
|
+
red(text: string): this;
|
|
33
|
+
redBold(text: string): this;
|
|
34
|
+
green(text: string): this;
|
|
35
|
+
greenBold(text: string): this;
|
|
36
|
+
yellow(text: string): this;
|
|
37
|
+
yellowBold(text: string): this;
|
|
38
|
+
blue(text: string): this;
|
|
39
|
+
blueBold(text: string): this;
|
|
40
|
+
magenta(text: string): this;
|
|
41
|
+
magentaBold(text: string): this;
|
|
42
|
+
white(text: string): this;
|
|
43
|
+
whiteBold(text: string): this;
|
|
44
|
+
black(text: string): this;
|
|
45
|
+
blackBold(text: string): this;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=print_colored.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"print_colored.d.ts","sourceRoot":"","sources":["../../src/tools/print_colored.ts"],"names":[],"mappings":"AAAA,oBAAY,UAAU;IACpB,GAAG,KAAK;IACR,KAAK,KAAK;IACV,MAAM,KAAK;IACX,IAAI,KAAK;IACT,OAAO,KAAK;IACZ,KAAK,KAAK;IACV,KAAK,KAAK;I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,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAKzB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAK7B,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAKzB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;CAI9B"}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
export var PrintColor;
|
|
2
|
+
(function (PrintColor) {
|
|
3
|
+
PrintColor[PrintColor["red"] = 31] = "red";
|
|
4
|
+
PrintColor[PrintColor["green"] = 32] = "green";
|
|
5
|
+
PrintColor[PrintColor["yellow"] = 33] = "yellow";
|
|
6
|
+
PrintColor[PrintColor["blue"] = 34] = "blue";
|
|
7
|
+
PrintColor[PrintColor["magenta"] = 35] = "magenta";
|
|
8
|
+
PrintColor[PrintColor["white"] = 37] = "white";
|
|
9
|
+
PrintColor[PrintColor["black"] = 30] = "black";
|
|
10
|
+
PrintColor[PrintColor["grey"] = 90] = "grey";
|
|
11
|
+
PrintColor[PrintColor["lightGrey"] = 97] = "lightGrey";
|
|
12
|
+
PrintColor[PrintColor["lightRed"] = 91] = "lightRed";
|
|
13
|
+
PrintColor[PrintColor["lightGreen"] = 92] = "lightGreen";
|
|
14
|
+
PrintColor[PrintColor["lightYellow"] = 93] = "lightYellow";
|
|
15
|
+
PrintColor[PrintColor["lightBlue"] = 94] = "lightBlue";
|
|
16
|
+
PrintColor[PrintColor["lightMagenta"] = 95] = "lightMagenta";
|
|
17
|
+
PrintColor[PrintColor["lightCyan"] = 96] = "lightCyan";
|
|
18
|
+
PrintColor[PrintColor["lightWhite"] = 97] = "lightWhite";
|
|
19
|
+
})(PrintColor || (PrintColor = {}));
|
|
20
|
+
export class Output {
|
|
21
|
+
text;
|
|
22
|
+
color;
|
|
23
|
+
isBold;
|
|
24
|
+
constructor(text, color, isBold = false) {
|
|
25
|
+
this.text = text;
|
|
26
|
+
this.color = color;
|
|
27
|
+
this.isBold = isBold;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
export default class PrintColored {
|
|
31
|
+
outputs = [];
|
|
32
|
+
chain(text, color, isBold) {
|
|
33
|
+
this.outputs.push(new Output(text, color, isBold ?? false));
|
|
34
|
+
return this;
|
|
35
|
+
}
|
|
36
|
+
chainln(text, color, isBold) {
|
|
37
|
+
this.outputs.push(new Output(text + "\n", color, isBold ?? false));
|
|
38
|
+
return this;
|
|
39
|
+
}
|
|
40
|
+
printit() {
|
|
41
|
+
const text = this.outputs
|
|
42
|
+
.map((output) => {
|
|
43
|
+
const colorCode = output.color !== undefined ? output.color : 0;
|
|
44
|
+
return `\x1B[${output.isBold ? "1;" + colorCode : colorCode}m${output.text}\x1B[0m`;
|
|
45
|
+
})
|
|
46
|
+
.join(" ");
|
|
47
|
+
// eslint-disable-next-line no-console
|
|
48
|
+
console.log(text);
|
|
49
|
+
}
|
|
50
|
+
getIt() {
|
|
51
|
+
return this.outputs
|
|
52
|
+
.map((output) => {
|
|
53
|
+
if (output.color === undefined)
|
|
54
|
+
return output.text;
|
|
55
|
+
return `\x1B[${output.isBold ? "1;" + output.color : output.color}m${output.text}\x1B[0m`;
|
|
56
|
+
})
|
|
57
|
+
.join(" ");
|
|
58
|
+
}
|
|
59
|
+
throwIt() {
|
|
60
|
+
throw new Error(this.getIt());
|
|
61
|
+
}
|
|
62
|
+
// Optional chainers
|
|
63
|
+
red(text) {
|
|
64
|
+
this.outputs.push(new Output(text, PrintColor.red, false));
|
|
65
|
+
return this;
|
|
66
|
+
}
|
|
67
|
+
redBold(text) {
|
|
68
|
+
this.outputs.push(new Output(text, PrintColor.red, true));
|
|
69
|
+
return this;
|
|
70
|
+
}
|
|
71
|
+
green(text) {
|
|
72
|
+
this.outputs.push(new Output(text, PrintColor.green, false));
|
|
73
|
+
return this;
|
|
74
|
+
}
|
|
75
|
+
greenBold(text) {
|
|
76
|
+
this.outputs.push(new Output(text, PrintColor.green, true));
|
|
77
|
+
return this;
|
|
78
|
+
}
|
|
79
|
+
yellow(text) {
|
|
80
|
+
this.outputs.push(new Output(text, PrintColor.yellow, false));
|
|
81
|
+
return this;
|
|
82
|
+
}
|
|
83
|
+
yellowBold(text) {
|
|
84
|
+
this.outputs.push(new Output(text, PrintColor.yellow, true));
|
|
85
|
+
return this;
|
|
86
|
+
}
|
|
87
|
+
blue(text) {
|
|
88
|
+
this.outputs.push(new Output(text, PrintColor.blue, false));
|
|
89
|
+
return this;
|
|
90
|
+
}
|
|
91
|
+
blueBold(text) {
|
|
92
|
+
this.outputs.push(new Output(text, PrintColor.blue, true));
|
|
93
|
+
return this;
|
|
94
|
+
}
|
|
95
|
+
magenta(text) {
|
|
96
|
+
this.outputs.push(new Output(text, PrintColor.magenta, false));
|
|
97
|
+
return this;
|
|
98
|
+
}
|
|
99
|
+
magentaBold(text) {
|
|
100
|
+
this.outputs.push(new Output(text, PrintColor.magenta, true));
|
|
101
|
+
return this;
|
|
102
|
+
}
|
|
103
|
+
white(text) {
|
|
104
|
+
this.outputs.push(new Output(text, PrintColor.white, false));
|
|
105
|
+
return this;
|
|
106
|
+
}
|
|
107
|
+
whiteBold(text) {
|
|
108
|
+
this.outputs.push(new Output(text, PrintColor.white, true));
|
|
109
|
+
return this;
|
|
110
|
+
}
|
|
111
|
+
black(text) {
|
|
112
|
+
this.outputs.push(new Output(text, PrintColor.black, false));
|
|
113
|
+
return this;
|
|
114
|
+
}
|
|
115
|
+
blackBold(text) {
|
|
116
|
+
this.outputs.push(new Output(text, PrintColor.black, true));
|
|
117
|
+
return this;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
export default class Random {
|
|
2
|
+
private static _cuidCounter;
|
|
3
|
+
static nextInt(max: number): number;
|
|
4
|
+
static uuid(): string;
|
|
5
|
+
static cuid(): string;
|
|
6
|
+
static alpha(length: number, opts?: {
|
|
7
|
+
includeUppercase?: boolean;
|
|
8
|
+
}): string;
|
|
9
|
+
static alphaNumeric(length: number, opts?: {
|
|
10
|
+
includeUppercase?: boolean;
|
|
11
|
+
}): string;
|
|
12
|
+
static numeric(length: number): string;
|
|
13
|
+
static boolean(): boolean;
|
|
14
|
+
static pickOne<T>(values: T[]): T;
|
|
15
|
+
static shuffle<T>(values: T[]): T[];
|
|
16
|
+
static nextDouble(): number;
|
|
17
|
+
static date(args?: {
|
|
18
|
+
start?: Date;
|
|
19
|
+
end?: Date;
|
|
20
|
+
}): Date;
|
|
21
|
+
static fromCharset(length: number, charset: string): string;
|
|
22
|
+
static hexColor(opts?: {
|
|
23
|
+
withAlpha?: boolean;
|
|
24
|
+
}): string;
|
|
25
|
+
static pickMapValue<K, V>(map: Map<K, V> | {
|
|
26
|
+
[key: string]: V;
|
|
27
|
+
}, opts?: {
|
|
28
|
+
weights?: number[];
|
|
29
|
+
}): V;
|
|
30
|
+
static duration(args?: {
|
|
31
|
+
min?: number;
|
|
32
|
+
max?: number;
|
|
33
|
+
}): number;
|
|
34
|
+
static coin(probability: number): boolean;
|
|
35
|
+
static pickSome<T>(values: T[], args?: {
|
|
36
|
+
min?: number;
|
|
37
|
+
max?: number;
|
|
38
|
+
}): T[];
|
|
39
|
+
static pickMany<T>(values: T[], args?: {
|
|
40
|
+
count?: number;
|
|
41
|
+
}): T[];
|
|
42
|
+
static ipv4(): string;
|
|
43
|
+
static doubleInRange(min: number, max: number): number;
|
|
44
|
+
static intInRange(min: number, max: number): number;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=random.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"random.d.ts","sourceRoot":"","sources":["../../src/tools/random.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,OAAO,OAAO,MAAM;IACzB,OAAO,CAAC,MAAM,CAAC,YAAY,CAAK;IAEhC,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;IAInC,MAAM,CAAC,IAAI,IAAI,MAAM;IA4BrB,MAAM,CAAC,IAAI,IAAI,MAAM;IAoB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IAQlE,MAAM,CAAC,IAAI,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO;IAOzC,MAAM,CAAC,QAAQ,CAAC,CAAC,EACf,MAAM,EAAE,CAAC,EAAE,EACX,IAAI,GAAE;QAAE,GAAG,CAAC,EAAE,MAAM,CAAC;QAAC,GAAG,CAAC,EAAE,MAAM,CAAA;KAAO,GACxC,CAAC,EAAE;IAgBN,MAAM,CAAC,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,EAAE,IAAI,GAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAA;KAAO,GAAG,CAAC,EAAE;IAanE,MAAM,CAAC,IAAI,IAAI,MAAM;IAIrB,MAAM,CAAC,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM;IAKtD,MAAM,CAAC,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM;CAIpD"}
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
export default class Random {
|
|
2
|
+
static _cuidCounter = 0;
|
|
3
|
+
static nextInt(max) {
|
|
4
|
+
return Math.floor(Math.random() * max);
|
|
5
|
+
}
|
|
6
|
+
static uuid() {
|
|
7
|
+
function fourDigits() {
|
|
8
|
+
return Random.nextInt(0x10000).toString(16).padStart(4, "0");
|
|
9
|
+
}
|
|
10
|
+
function twoDigits() {
|
|
11
|
+
return Random.nextInt(0x100).toString(16).padStart(2, "0");
|
|
12
|
+
}
|
|
13
|
+
return (fourDigits() +
|
|
14
|
+
fourDigits() +
|
|
15
|
+
"-" +
|
|
16
|
+
fourDigits() +
|
|
17
|
+
"-" +
|
|
18
|
+
"4" +
|
|
19
|
+
twoDigits() +
|
|
20
|
+
twoDigits() +
|
|
21
|
+
"-" +
|
|
22
|
+
(8 + Random.nextInt(4)).toString(16) +
|
|
23
|
+
twoDigits() +
|
|
24
|
+
twoDigits() +
|
|
25
|
+
"-" +
|
|
26
|
+
fourDigits() +
|
|
27
|
+
fourDigits() +
|
|
28
|
+
fourDigits());
|
|
29
|
+
}
|
|
30
|
+
static cuid() {
|
|
31
|
+
const ts = Date.now().toString(36).padStart(8, "0");
|
|
32
|
+
Random._cuidCounter = (Random._cuidCounter + 1) % 1679616;
|
|
33
|
+
const count = Random._cuidCounter.toString(36).padStart(4, "0");
|
|
34
|
+
const randomPart = Random.nextInt(1679616).toString(36).padStart(4, "0");
|
|
35
|
+
let fingerprint = "0000";
|
|
36
|
+
try {
|
|
37
|
+
fingerprint = ((typeof process !== "undefined" && process.pid ? process.pid : 0) ^
|
|
38
|
+
Math.floor(Math.random() * 1000000))
|
|
39
|
+
.toString(36)
|
|
40
|
+
.padStart(4, "0");
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
// fallback
|
|
44
|
+
fingerprint = Random.nextInt(0x10000).toString(36).padStart(4, "0");
|
|
45
|
+
}
|
|
46
|
+
return `c${ts}${count}${randomPart}${fingerprint}`;
|
|
47
|
+
}
|
|
48
|
+
static alpha(length, opts = {}) {
|
|
49
|
+
const lowercase = "abcdefghijklmnopqrstuvwxyz";
|
|
50
|
+
const uppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
51
|
+
const chars = opts.includeUppercase ? lowercase + uppercase : lowercase;
|
|
52
|
+
let out = "";
|
|
53
|
+
for (let i = 0; i < length; ++i) {
|
|
54
|
+
out += chars[Random.nextInt(chars.length)];
|
|
55
|
+
}
|
|
56
|
+
return out;
|
|
57
|
+
}
|
|
58
|
+
static alphaNumeric(length, opts = {}) {
|
|
59
|
+
const lowercase = "abcdefghijklmnopqrstuvwxyz";
|
|
60
|
+
const uppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
61
|
+
const numbers = "0123456789";
|
|
62
|
+
const chars = opts.includeUppercase
|
|
63
|
+
? lowercase + uppercase + numbers
|
|
64
|
+
: lowercase + numbers;
|
|
65
|
+
let out = "";
|
|
66
|
+
for (let i = 0; i < length; ++i) {
|
|
67
|
+
out += chars[Random.nextInt(chars.length)];
|
|
68
|
+
}
|
|
69
|
+
return out;
|
|
70
|
+
}
|
|
71
|
+
static numeric(length) {
|
|
72
|
+
const numbers = "0123456789";
|
|
73
|
+
let out = "";
|
|
74
|
+
for (let i = 0; i < length; ++i) {
|
|
75
|
+
out += numbers[Random.nextInt(numbers.length)];
|
|
76
|
+
}
|
|
77
|
+
return out;
|
|
78
|
+
}
|
|
79
|
+
static boolean() {
|
|
80
|
+
return Math.random() < 0.5;
|
|
81
|
+
}
|
|
82
|
+
static pickOne(values) {
|
|
83
|
+
if (!values.length)
|
|
84
|
+
throw new Error("List cannot be empty");
|
|
85
|
+
return values[Random.nextInt(values.length)];
|
|
86
|
+
}
|
|
87
|
+
static shuffle(values) {
|
|
88
|
+
const list = values.slice();
|
|
89
|
+
for (let i = list.length - 1; i > 0; --i) {
|
|
90
|
+
const j = Random.nextInt(i + 1);
|
|
91
|
+
[list[i], list[j]] = [list[j], list[i]];
|
|
92
|
+
}
|
|
93
|
+
return list;
|
|
94
|
+
}
|
|
95
|
+
static nextDouble() {
|
|
96
|
+
return Math.random();
|
|
97
|
+
}
|
|
98
|
+
static date(args = {}) {
|
|
99
|
+
const from = args.start || new Date(1970, 0, 1);
|
|
100
|
+
const to = args.end || new Date();
|
|
101
|
+
if (from > to)
|
|
102
|
+
throw new Error("start must be before end");
|
|
103
|
+
const fromMs = from.getTime();
|
|
104
|
+
const toMs = to.getTime();
|
|
105
|
+
const ms = fromMs + Math.floor(Math.random() * (toMs - fromMs + 1));
|
|
106
|
+
return new Date(ms);
|
|
107
|
+
}
|
|
108
|
+
static fromCharset(length, charset) {
|
|
109
|
+
if (!charset.length)
|
|
110
|
+
throw new Error("charset cannot be empty");
|
|
111
|
+
let out = "";
|
|
112
|
+
for (let i = 0; i < length; ++i) {
|
|
113
|
+
out += charset[Random.nextInt(charset.length)];
|
|
114
|
+
}
|
|
115
|
+
return out;
|
|
116
|
+
}
|
|
117
|
+
static hexColor(opts = {}) {
|
|
118
|
+
const withAlpha = opts.withAlpha || false;
|
|
119
|
+
const value = withAlpha
|
|
120
|
+
? Random.nextInt(0x100000000)
|
|
121
|
+
: Random.nextInt(0x1000000);
|
|
122
|
+
return withAlpha
|
|
123
|
+
? `#${value.toString(16).padStart(8, "0").toUpperCase()}`
|
|
124
|
+
: `#${value.toString(16).padStart(6, "0").toUpperCase()}`;
|
|
125
|
+
}
|
|
126
|
+
static pickMapValue(map, opts = {}) {
|
|
127
|
+
// Support both Map and object
|
|
128
|
+
let values;
|
|
129
|
+
if (map instanceof Map) {
|
|
130
|
+
values = Array.from(map.values());
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
values = Object.values(map);
|
|
134
|
+
}
|
|
135
|
+
if (!values.length)
|
|
136
|
+
throw new Error("Map cannot be empty");
|
|
137
|
+
if (!opts.weights) {
|
|
138
|
+
return Random.pickOne(values);
|
|
139
|
+
}
|
|
140
|
+
const weights = opts.weights;
|
|
141
|
+
if (weights.length !== values.length) {
|
|
142
|
+
throw new Error("Weights length must match Map value count.");
|
|
143
|
+
}
|
|
144
|
+
let sum = weights.reduce((a, b) => a + b, 0);
|
|
145
|
+
let r = Math.random() * sum;
|
|
146
|
+
for (let i = 0; i < values.length; ++i) {
|
|
147
|
+
if (!weights[i])
|
|
148
|
+
continue;
|
|
149
|
+
if (r < weights[i])
|
|
150
|
+
return values[i];
|
|
151
|
+
r -= weights[i];
|
|
152
|
+
}
|
|
153
|
+
return values[values.length - 1];
|
|
154
|
+
}
|
|
155
|
+
static duration(args = {}) {
|
|
156
|
+
// Returns random milliseconds between min (inclusive) and max (inclusive)
|
|
157
|
+
const min = args.min ?? 0;
|
|
158
|
+
const max = args.max ?? 60000;
|
|
159
|
+
if (min > max)
|
|
160
|
+
throw new Error("min must be < max");
|
|
161
|
+
return min + Random.nextInt(max - min + 1);
|
|
162
|
+
}
|
|
163
|
+
static coin(probability) {
|
|
164
|
+
if (probability < 0.0 || probability > 1.0) {
|
|
165
|
+
throw new Error("probability must be from 0.0 to 1.0");
|
|
166
|
+
}
|
|
167
|
+
return Math.random() < probability;
|
|
168
|
+
}
|
|
169
|
+
static pickSome(values, args = {}) {
|
|
170
|
+
if (!values.length)
|
|
171
|
+
throw new Error("List cannot be empty");
|
|
172
|
+
let lower = args.min ?? 0;
|
|
173
|
+
let upper = args.max ?? values.length;
|
|
174
|
+
if (lower < 0)
|
|
175
|
+
lower = 0;
|
|
176
|
+
if (upper > values.length)
|
|
177
|
+
upper = values.length;
|
|
178
|
+
if (lower > upper)
|
|
179
|
+
throw new Error("min must be <= max");
|
|
180
|
+
const count = lower + Random.nextInt(upper - lower + 1);
|
|
181
|
+
const list = values.slice();
|
|
182
|
+
for (let i = list.length - 1; i > 0; --i) {
|
|
183
|
+
const j = Random.nextInt(i + 1);
|
|
184
|
+
[list[i], list[j]] = [list[j], list[i]];
|
|
185
|
+
}
|
|
186
|
+
return list.slice(0, count);
|
|
187
|
+
}
|
|
188
|
+
static pickMany(values, args = {}) {
|
|
189
|
+
const count = args.count ?? values.length;
|
|
190
|
+
if (count < 0)
|
|
191
|
+
throw new Error("count must be >= 0");
|
|
192
|
+
if (count > values.length)
|
|
193
|
+
throw new Error("count must be <= values.length");
|
|
194
|
+
const list = values.slice();
|
|
195
|
+
for (let i = list.length - 1; i > 0; --i) {
|
|
196
|
+
const j = Random.nextInt(i + 1);
|
|
197
|
+
[list[i], list[j]] = [list[j], list[i]];
|
|
198
|
+
}
|
|
199
|
+
return list.slice(0, count);
|
|
200
|
+
}
|
|
201
|
+
static ipv4() {
|
|
202
|
+
return Array.from({ length: 4 }, () => Random.nextInt(256)).join(".");
|
|
203
|
+
}
|
|
204
|
+
static doubleInRange(min, max) {
|
|
205
|
+
if (min >= max)
|
|
206
|
+
throw new Error("min must be less than max");
|
|
207
|
+
return min + Math.random() * (max - min);
|
|
208
|
+
}
|
|
209
|
+
static intInRange(min, max) {
|
|
210
|
+
if (min >= max)
|
|
211
|
+
throw new Error("min must be less than max");
|
|
212
|
+
return min + Random.nextInt(max - min);
|
|
213
|
+
}
|
|
214
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@kidus.dev/flowdb",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "A lightweight, pluggable local database for TypeScript and JavaScript projects.",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"module": "dist/index.js",
|
|
8
|
+
"type": "module",
|
|
9
|
+
"files": [
|
|
10
|
+
"dist"
|
|
11
|
+
],
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"import": "./dist/index.js",
|
|
15
|
+
"require": "./dist/index.js",
|
|
16
|
+
"types": "./dist/index.d.ts"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "tsc",
|
|
21
|
+
"prepublishOnly": "npm run build",
|
|
22
|
+
"test": "node dist/test/index.js"
|
|
23
|
+
},
|
|
24
|
+
"keywords": [
|
|
25
|
+
"database",
|
|
26
|
+
"local",
|
|
27
|
+
"typescript",
|
|
28
|
+
"storage",
|
|
29
|
+
"embedded"
|
|
30
|
+
],
|
|
31
|
+
"author": "Kidus Abrham <kidusabrham.dev@gmail.com>",
|
|
32
|
+
"license": "MIT",
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@types/bun": "latest",
|
|
35
|
+
"typescript": "^5.0.0"
|
|
36
|
+
},
|
|
37
|
+
"peerDependencies": {
|
|
38
|
+
"typescript": "^5.0.0"
|
|
39
|
+
}
|
|
40
|
+
}
|