@ix-xs/node-comfort 1.1.31 → 1.2.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/LICENSE +21 -0
- package/README.md +623 -748
- package/index.js +39 -13
- package/package.json +74 -21
- package/src/Arr.js +433 -0
- package/src/Checker.js +547 -188
- package/src/FS.js +127 -1
- package/src/Func.js +375 -0
- package/src/Id.js +235 -0
- package/src/Logger.js +71 -0
- package/src/Num.js +366 -0
- package/src/Obj.js +421 -0
- package/src/SQLite.js +20 -9
- package/src/Str.js +452 -0
- package/src/Time.js +485 -0
- package/types/index.d.ts +406 -0
- package/types/index.d.ts.map +1 -1
- package/types/src/Arr.d.ts +252 -0
- package/types/src/Arr.d.ts.map +1 -0
- package/types/src/Checker.d.ts +292 -30
- package/types/src/Checker.d.ts.map +1 -1
- package/types/src/FS.d.ts +60 -0
- package/types/src/FS.d.ts.map +1 -1
- package/types/src/Func.d.ts +210 -0
- package/types/src/Func.d.ts.map +1 -0
- package/types/src/Id.d.ts +119 -0
- package/types/src/Id.d.ts.map +1 -0
- package/types/src/Logger.d.ts +33 -0
- package/types/src/Logger.d.ts.map +1 -1
- package/types/src/Num.d.ts +242 -0
- package/types/src/Num.d.ts.map +1 -0
- package/types/src/Obj.d.ts +189 -0
- package/types/src/Obj.d.ts.map +1 -0
- package/types/src/SQLite.d.ts +6 -1
- package/types/src/SQLite.d.ts.map +1 -1
- package/types/src/Str.d.ts +293 -0
- package/types/src/Str.d.ts.map +1 -0
- package/types/src/Time.d.ts +205 -0
- package/types/src/Time.d.ts.map +1 -0
- package/tsconfig.json +0 -18
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Clamps a number between a minimum and maximum.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* nodeComfort.num.clamp(15, 0, 10); // 10
|
|
6
|
+
* nodeComfort.num.clamp(-3, 0, 10); // 0
|
|
7
|
+
*
|
|
8
|
+
* @param {number} value - Value to clamp.
|
|
9
|
+
* @param {number} min - Lower bound.
|
|
10
|
+
* @param {number} max - Upper bound.
|
|
11
|
+
* @returns {number} The clamped value.
|
|
12
|
+
*/
|
|
13
|
+
export function clamp(value: number, min: number, max: number): number;
|
|
14
|
+
/**
|
|
15
|
+
* Checks whether a number is within an inclusive `[min, max]` range.
|
|
16
|
+
*
|
|
17
|
+
* @param {number} value - Value to test.
|
|
18
|
+
* @param {number} min - Lower bound.
|
|
19
|
+
* @param {number} max - Upper bound.
|
|
20
|
+
* @returns {boolean} True if within range.
|
|
21
|
+
*/
|
|
22
|
+
export function inRange(value: number, min: number, max: number): boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Rounds a number to a given number of decimal places (avoids float artifacts).
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* nodeComfort.num.round(1.005, 2); // 1.01
|
|
28
|
+
*
|
|
29
|
+
* @param {number} value - Value to round.
|
|
30
|
+
* @param {number} [decimals=0] - Number of decimal places.
|
|
31
|
+
* @returns {number} The rounded number.
|
|
32
|
+
*/
|
|
33
|
+
export function round(value: number, decimals?: number): number;
|
|
34
|
+
/**
|
|
35
|
+
* Rounds a number down to a given number of decimal places.
|
|
36
|
+
*
|
|
37
|
+
* @param {number} value - Value to round.
|
|
38
|
+
* @param {number} [decimals=0] - Number of decimal places.
|
|
39
|
+
* @returns {number} The floored number.
|
|
40
|
+
*/
|
|
41
|
+
export function floor(value: number, decimals?: number): number;
|
|
42
|
+
/**
|
|
43
|
+
* Rounds a number up to a given number of decimal places.
|
|
44
|
+
*
|
|
45
|
+
* @param {number} value - Value to round.
|
|
46
|
+
* @param {number} [decimals=0] - Number of decimal places.
|
|
47
|
+
* @returns {number} The ceiled number.
|
|
48
|
+
*/
|
|
49
|
+
export function ceil(value: number, decimals?: number): number;
|
|
50
|
+
/**
|
|
51
|
+
* Linearly interpolates between `start` and `end` by ratio `t` (0..1).
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* nodeComfort.num.lerp(0, 100, 0.5); // 50
|
|
55
|
+
*
|
|
56
|
+
* @param {number} start - Start value.
|
|
57
|
+
* @param {number} end - End value.
|
|
58
|
+
* @param {number} t - Interpolation factor (usually 0..1).
|
|
59
|
+
* @returns {number} The interpolated value.
|
|
60
|
+
*/
|
|
61
|
+
export function lerp(start: number, end: number, t: number): number;
|
|
62
|
+
/**
|
|
63
|
+
* Re-maps a number from one range to another.
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* nodeComfort.num.mapRange(5, 0, 10, 0, 100); // 50
|
|
67
|
+
*
|
|
68
|
+
* @param {number} value - Value to map.
|
|
69
|
+
* @param {number} inMin - Input range minimum.
|
|
70
|
+
* @param {number} inMax - Input range maximum.
|
|
71
|
+
* @param {number} outMin - Output range minimum.
|
|
72
|
+
* @param {number} outMax - Output range maximum.
|
|
73
|
+
* @returns {number} The mapped value.
|
|
74
|
+
*/
|
|
75
|
+
export function mapRange(value: number, inMin: number, inMax: number, outMin: number, outMax: number): number;
|
|
76
|
+
/**
|
|
77
|
+
* Returns a random number (float) in `[min, max)`.
|
|
78
|
+
*
|
|
79
|
+
* Not cryptographically secure. For secure randomness use `nodeComfort.id`.
|
|
80
|
+
*
|
|
81
|
+
* @param {number} [min=0] - Lower bound (inclusive).
|
|
82
|
+
* @param {number} [max=1] - Upper bound (exclusive).
|
|
83
|
+
* @returns {number} A random float.
|
|
84
|
+
*/
|
|
85
|
+
export function random(min?: number, max?: number): number;
|
|
86
|
+
/**
|
|
87
|
+
* Returns a random integer in `[min, max]` (both inclusive).
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* nodeComfort.num.randomInt(1, 6); // dice roll
|
|
91
|
+
*
|
|
92
|
+
* @param {number} min - Lower bound (inclusive).
|
|
93
|
+
* @param {number} max - Upper bound (inclusive).
|
|
94
|
+
* @returns {number} A random integer.
|
|
95
|
+
*/
|
|
96
|
+
export function randomInt(min: number, max: number): number;
|
|
97
|
+
/**
|
|
98
|
+
* Sums all numbers in an array.
|
|
99
|
+
*
|
|
100
|
+
* @param {number[]} values - Array of numbers.
|
|
101
|
+
* @returns {number} The sum (0 for an empty array).
|
|
102
|
+
*/
|
|
103
|
+
export function sum(values: number[]): number;
|
|
104
|
+
/**
|
|
105
|
+
* Returns the arithmetic mean (average) of an array of numbers.
|
|
106
|
+
*
|
|
107
|
+
* @param {number[]} values - Array of numbers.
|
|
108
|
+
* @returns {number} The average (0 for an empty array).
|
|
109
|
+
*/
|
|
110
|
+
export function average(values: number[]): number;
|
|
111
|
+
/**
|
|
112
|
+
* Returns the median value of an array of numbers.
|
|
113
|
+
*
|
|
114
|
+
* @param {number[]} values - Array of numbers.
|
|
115
|
+
* @returns {number} The median (0 for an empty array).
|
|
116
|
+
*/
|
|
117
|
+
export function median(values: number[]): number;
|
|
118
|
+
/**
|
|
119
|
+
* Returns the smallest number in an array.
|
|
120
|
+
*
|
|
121
|
+
* @param {number[]} values - Array of numbers.
|
|
122
|
+
* @returns {number|undefined} The minimum, or undefined if empty.
|
|
123
|
+
*/
|
|
124
|
+
export function min(values: number[]): number | undefined;
|
|
125
|
+
/**
|
|
126
|
+
* Returns the largest number in an array.
|
|
127
|
+
*
|
|
128
|
+
* @param {number[]} values - Array of numbers.
|
|
129
|
+
* @returns {number|undefined} The maximum, or undefined if empty.
|
|
130
|
+
*/
|
|
131
|
+
export function max(values: number[]): number | undefined;
|
|
132
|
+
/**
|
|
133
|
+
* Computes what percentage `value` is of `total`.
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* nodeComfort.num.percent(25, 200); // 12.5
|
|
137
|
+
*
|
|
138
|
+
* @param {number} value - Partial value.
|
|
139
|
+
* @param {number} total - Total value.
|
|
140
|
+
* @param {number} [decimals=2] - Decimal places to keep.
|
|
141
|
+
* @returns {number} The percentage.
|
|
142
|
+
*/
|
|
143
|
+
export function percent(value: number, total: number, decimals?: number): number;
|
|
144
|
+
/**
|
|
145
|
+
* Formats a byte count into a human-readable string (KB, MB, GB, ...).
|
|
146
|
+
*
|
|
147
|
+
* By default uses binary sizing (base 1024) with familiar `KB`/`MB` labels.
|
|
148
|
+
* Set `binary: false` for SI sizing (base 1000), or `iec: true` for
|
|
149
|
+
* strict `KiB`/`MiB` labels.
|
|
150
|
+
*
|
|
151
|
+
* @example
|
|
152
|
+
* nodeComfort.num.formatBytes(1536); // "1.5 KB"
|
|
153
|
+
* nodeComfort.num.formatBytes(1073741824); // "1 GB"
|
|
154
|
+
* nodeComfort.num.formatBytes(1000, { binary: false }); // "1 KB"
|
|
155
|
+
* nodeComfort.num.formatBytes(1024, { iec: true }); // "1 KiB"
|
|
156
|
+
*
|
|
157
|
+
* @param {number} bytes - Number of bytes.
|
|
158
|
+
* @param {{ decimals?: number, binary?: boolean, iec?: boolean }} [options] - Formatting options.
|
|
159
|
+
* @returns {string} The human-readable size.
|
|
160
|
+
*/
|
|
161
|
+
export function formatBytes(bytes: number, options?: {
|
|
162
|
+
decimals?: number;
|
|
163
|
+
binary?: boolean;
|
|
164
|
+
iec?: boolean;
|
|
165
|
+
}): string;
|
|
166
|
+
/**
|
|
167
|
+
* Formats a large number with a compact suffix (K, M, B, T).
|
|
168
|
+
*
|
|
169
|
+
* @example
|
|
170
|
+
* nodeComfort.num.abbreviate(1500); // "1.5K"
|
|
171
|
+
* nodeComfort.num.abbreviate(2_400_000); // "2.4M"
|
|
172
|
+
*
|
|
173
|
+
* @param {number} value - Number to abbreviate.
|
|
174
|
+
* @param {number} [decimals=1] - Decimal places.
|
|
175
|
+
* @returns {string} The abbreviated number.
|
|
176
|
+
*/
|
|
177
|
+
export function abbreviate(value: number, decimals?: number): string;
|
|
178
|
+
/**
|
|
179
|
+
* Inserts thousands separators into a number.
|
|
180
|
+
*
|
|
181
|
+
* @example
|
|
182
|
+
* nodeComfort.num.thousands(1234567); // "1,234,567"
|
|
183
|
+
* nodeComfort.num.thousands(1234.5, " "); // "1 234.5"
|
|
184
|
+
*
|
|
185
|
+
* @param {number} value - Number to format.
|
|
186
|
+
* @param {string} [separator=","] - Thousands separator.
|
|
187
|
+
* @returns {string} The formatted number.
|
|
188
|
+
*/
|
|
189
|
+
export function thousands(value: number, separator?: string): string;
|
|
190
|
+
/**
|
|
191
|
+
* Returns the English ordinal suffix for a number ("st", "nd", "rd", "th").
|
|
192
|
+
*
|
|
193
|
+
* @example
|
|
194
|
+
* nodeComfort.num.ordinal(1); // "1st"
|
|
195
|
+
* nodeComfort.num.ordinal(22); // "22nd"
|
|
196
|
+
*
|
|
197
|
+
* @param {number} value - The number.
|
|
198
|
+
* @returns {string} The number with its ordinal suffix.
|
|
199
|
+
*/
|
|
200
|
+
export function ordinal(value: number): string;
|
|
201
|
+
/**
|
|
202
|
+
* Parses a value into a number, returning a fallback when it isn't numeric.
|
|
203
|
+
*
|
|
204
|
+
* @example
|
|
205
|
+
* nodeComfort.num.parse("42px"); // 42
|
|
206
|
+
* nodeComfort.num.parse("nope", 0); // 0
|
|
207
|
+
*
|
|
208
|
+
* @param {*} value - Value to parse.
|
|
209
|
+
* @param {number} [fallback=NaN] - Value returned when parsing fails.
|
|
210
|
+
* @returns {number} The parsed number or the fallback.
|
|
211
|
+
*/
|
|
212
|
+
export function parse(value: any, fallback?: number): number;
|
|
213
|
+
/**
|
|
214
|
+
* Checks whether a number is even.
|
|
215
|
+
* @param {number} value - Number to check.
|
|
216
|
+
* @returns {boolean} True if even.
|
|
217
|
+
*/
|
|
218
|
+
export function isEven(value: number): boolean;
|
|
219
|
+
/**
|
|
220
|
+
* Checks whether a number is odd.
|
|
221
|
+
* @param {number} value - Number to check.
|
|
222
|
+
* @returns {boolean} True if odd.
|
|
223
|
+
*/
|
|
224
|
+
export function isOdd(value: number): boolean;
|
|
225
|
+
/**
|
|
226
|
+
* Returns an array of numbers from `start` to `end`.
|
|
227
|
+
*
|
|
228
|
+
* `end` is exclusive. Supports a custom step and descending ranges.
|
|
229
|
+
*
|
|
230
|
+
* @example
|
|
231
|
+
* nodeComfort.num.range(4); // [0, 1, 2, 3]
|
|
232
|
+
* nodeComfort.num.range(1, 5); // [1, 2, 3, 4]
|
|
233
|
+
* nodeComfort.num.range(0, 10, 2); // [0, 2, 4, 6, 8]
|
|
234
|
+
* nodeComfort.num.range(5, 0); // [5, 4, 3, 2, 1]
|
|
235
|
+
*
|
|
236
|
+
* @param {number} start - Start (or end if it's the only argument).
|
|
237
|
+
* @param {number} [end] - End (exclusive).
|
|
238
|
+
* @param {number} [step] - Step size (defaults to 1 or -1 based on direction).
|
|
239
|
+
* @returns {number[]} The generated range.
|
|
240
|
+
*/
|
|
241
|
+
export function range(start: number, end?: number, step?: number): number[];
|
|
242
|
+
//# sourceMappingURL=Num.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Num.d.ts","sourceRoot":"","sources":["../../src/Num.js"],"names":[],"mappings":"AAOE;;;;;;;;;;;GAWG;AACH,6BALW,MAAM,OACN,MAAM,OACN,MAAM,GACJ,MAAM,CAIlB;AAED;;;;;;;GAOG;AACH,+BALW,MAAM,OACN,MAAM,OACN,MAAM,GACJ,OAAO,CAInB;AAED;;;;;;;;;GASG;AACH,6BAJW,MAAM,aACN,MAAM,GACJ,MAAM,CAKlB;AAED;;;;;;GAMG;AACH,6BAJW,MAAM,aACN,MAAM,GACJ,MAAM,CAKlB;AAED;;;;;;GAMG;AACH,4BAJW,MAAM,aACN,MAAM,GACJ,MAAM,CAKlB;AAED;;;;;;;;;;GAUG;AACH,4BALW,MAAM,OACN,MAAM,KACN,MAAM,GACJ,MAAM,CAIlB;AAED;;;;;;;;;;;;GAYG;AACH,gCAPW,MAAM,SACN,MAAM,SACN,MAAM,UACN,MAAM,UACN,MAAM,GACJ,MAAM,CAKlB;AAED;;;;;;;;GAQG;AACH,6BAJW,MAAM,QACN,MAAM,GACJ,MAAM,CAIlB;AAED;;;;;;;;;GASG;AACH,+BAJW,MAAM,OACN,MAAM,GACJ,MAAM,CAMlB;AAED;;;;;GAKG;AACH,4BAHW,MAAM,EAAE,GACN,MAAM,CAIlB;AAED;;;;;GAKG;AACH,gCAHW,MAAM,EAAE,GACN,MAAM,CAIlB;AAED;;;;;GAKG;AACH,+BAHW,MAAM,EAAE,GACN,MAAM,CAOlB;AAED;;;;;GAKG;AACH,4BAHW,MAAM,EAAE,GACN,MAAM,GAAC,SAAS,CAI5B;AAED;;;;;GAKG;AACH,4BAHW,MAAM,EAAE,GACN,MAAM,GAAC,SAAS,CAI5B;AAED;;;;;;;;;;GAUG;AACH,+BALW,MAAM,SACN,MAAM,aACN,MAAM,GACJ,MAAM,CAKlB;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,mCAJW,MAAM,YACN;IAAE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAAC,GAAG,CAAC,EAAE,OAAO,CAAA;CAAE,GACpD,MAAM,CAalB;AAED;;;;;;;;;;GAUG;AACH,kCAJW,MAAM,aACN,MAAM,GACJ,MAAM,CAelB;AAED;;;;;;;;;;GAUG;AACH,iCAJW,MAAM,cACN,MAAM,GACJ,MAAM,CAMlB;AAED;;;;;;;;;GASG;AACH,+BAHW,MAAM,GACJ,MAAM,CASlB;AAED;;;;;;;;;;GAUG;AACH,6BAJW,GAAC,aACD,MAAM,GACJ,MAAM,CAMlB;AAED;;;;GAIG;AACH,8BAHW,MAAM,GACJ,OAAO,CAInB;AAED;;;;GAIG;AACH,6BAHW,MAAM,GACJ,OAAO,CAInB;AAED;;;;;;;;;;;;;;;GAeG;AACH,6BALW,MAAM,QACN,MAAM,SACN,MAAM,GACJ,MAAM,EAAE,CAkBpB"}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deeply clones a value.
|
|
3
|
+
*
|
|
4
|
+
* Uses the native `structuredClone` when the value supports it (plain data,
|
|
5
|
+
* Dates, Maps, Sets, typed arrays, ...), and falls back to a manual deep copy
|
|
6
|
+
* otherwise. Functions are copied by reference.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* const copy = nodeComfort.obj.clone({ a: { b: 1 } });
|
|
10
|
+
*
|
|
11
|
+
* @template T
|
|
12
|
+
* @param {T} value - Value to clone.
|
|
13
|
+
* @returns {T} A deep copy.
|
|
14
|
+
*/
|
|
15
|
+
export function clone<T>(value: T): T;
|
|
16
|
+
/**
|
|
17
|
+
* Deeply merges two or more plain objects into a new object.
|
|
18
|
+
*
|
|
19
|
+
* Later sources win. Plain-object values are merged recursively; arrays and
|
|
20
|
+
* other values are replaced (not concatenated). Inputs are never mutated.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* nodeComfort.obj.merge({ a: { x: 1 } }, { a: { y: 2 } });
|
|
24
|
+
* // { a: { x: 1, y: 2 } }
|
|
25
|
+
*
|
|
26
|
+
* @param {...Record<string, any>} sources - Objects to merge.
|
|
27
|
+
* @returns {Record<string, any>} The merged object.
|
|
28
|
+
*/
|
|
29
|
+
export function merge(...sources: Record<string, any>[]): Record<string, any>;
|
|
30
|
+
/**
|
|
31
|
+
* Deeply compares two values for structural equality.
|
|
32
|
+
*
|
|
33
|
+
* Handles plain objects, arrays, Dates, RegExps, Maps and Sets.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* nodeComfort.obj.equal({ a: [1, 2] }, { a: [1, 2] }); // true
|
|
37
|
+
*
|
|
38
|
+
* @param {*} a - First value.
|
|
39
|
+
* @param {*} b - Second value.
|
|
40
|
+
* @returns {boolean} True if the values are deeply equal.
|
|
41
|
+
*/
|
|
42
|
+
export function equal(a: any, b: any): boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Gets a nested value from an object using a dot/bracket path.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* nodeComfort.obj.get({ a: { b: [{ c: 42 }] } }, "a.b[0].c"); // 42
|
|
48
|
+
* nodeComfort.obj.get({}, "a.b.c", "default"); // "default"
|
|
49
|
+
*
|
|
50
|
+
* @param {Record<string, any>} object - Source object.
|
|
51
|
+
* @param {string|Array<string|number>} path - Dot path or key array.
|
|
52
|
+
* @param {*} [fallback] - Returned when the path does not resolve.
|
|
53
|
+
* @returns {*} The value at the path, or the fallback.
|
|
54
|
+
*/
|
|
55
|
+
export function get(object: Record<string, any>, path: string | Array<string | number>, fallback?: any): any;
|
|
56
|
+
/**
|
|
57
|
+
* Sets a nested value in an object using a dot/bracket path (returns a clone).
|
|
58
|
+
*
|
|
59
|
+
* Intermediate objects/arrays are created as needed. The original object is
|
|
60
|
+
* not mutated.
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* nodeComfort.obj.set({}, "a.b.c", 1); // { a: { b: { c: 1 } } }
|
|
64
|
+
*
|
|
65
|
+
* @param {Record<string, any>} object - Source object.
|
|
66
|
+
* @param {string|Array<string|number>} path - Dot path or key array.
|
|
67
|
+
* @param {*} value - Value to set.
|
|
68
|
+
* @returns {Record<string, any>} A new object with the value set.
|
|
69
|
+
*/
|
|
70
|
+
export function set(object: Record<string, any>, path: string | Array<string | number>, value: any): Record<string, any>;
|
|
71
|
+
/**
|
|
72
|
+
* Checks whether a nested path exists in an object.
|
|
73
|
+
*
|
|
74
|
+
* @param {Record<string, any>} object - Source object.
|
|
75
|
+
* @param {string|Array<string|number>} path - Dot path or key array.
|
|
76
|
+
* @returns {boolean} True if the path resolves.
|
|
77
|
+
*/
|
|
78
|
+
export function has(object: Record<string, any>, path: string | Array<string | number>): boolean;
|
|
79
|
+
/**
|
|
80
|
+
* Returns a new object containing only the given keys.
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* nodeComfort.obj.pick({ a: 1, b: 2, c: 3 }, ["a", "c"]); // { a: 1, c: 3 }
|
|
84
|
+
*
|
|
85
|
+
* @param {Record<string, any>} object - Source object.
|
|
86
|
+
* @param {string[]} keys - Keys to keep.
|
|
87
|
+
* @returns {Record<string, any>} The picked object.
|
|
88
|
+
*/
|
|
89
|
+
export function pick(object: Record<string, any>, keys: string[]): Record<string, any>;
|
|
90
|
+
/**
|
|
91
|
+
* Returns a new object without the given keys.
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* nodeComfort.obj.omit({ a: 1, b: 2, c: 3 }, ["b"]); // { a: 1, c: 3 }
|
|
95
|
+
*
|
|
96
|
+
* @param {Record<string, any>} object - Source object.
|
|
97
|
+
* @param {string[]} keys - Keys to remove.
|
|
98
|
+
* @returns {Record<string, any>} The remaining object.
|
|
99
|
+
*/
|
|
100
|
+
export function omit(object: Record<string, any>, keys: string[]): Record<string, any>;
|
|
101
|
+
/**
|
|
102
|
+
* Returns a new object keeping only the entries that pass a predicate.
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* nodeComfort.obj.filter({ a: 1, b: 2, c: 3 }, (v) => v > 1); // { b: 2, c: 3 }
|
|
106
|
+
*
|
|
107
|
+
* @param {Record<string, any>} object - Source object.
|
|
108
|
+
* @param {(value: any, key: string) => boolean} predicate - Test function.
|
|
109
|
+
* @returns {Record<string, any>} The filtered object.
|
|
110
|
+
*/
|
|
111
|
+
export function filter(object: Record<string, any>, predicate: (value: any, key: string) => boolean): Record<string, any>;
|
|
112
|
+
/**
|
|
113
|
+
* Maps over an object's values, returning a new object with the same keys.
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* nodeComfort.obj.mapValues({ a: 1, b: 2 }, (v) => v * 10); // { a: 10, b: 20 }
|
|
117
|
+
*
|
|
118
|
+
* @param {Record<string, any>} object - Source object.
|
|
119
|
+
* @param {(value: any, key: string) => any} fn - Mapping function.
|
|
120
|
+
* @returns {Record<string, any>} The mapped object.
|
|
121
|
+
*/
|
|
122
|
+
export function mapValues(object: Record<string, any>, fn: (value: any, key: string) => any): Record<string, any>;
|
|
123
|
+
/**
|
|
124
|
+
* Maps over an object's keys, returning a new object with remapped keys.
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* nodeComfort.obj.mapKeys({ a: 1 }, (k) => k.toUpperCase()); // { A: 1 }
|
|
128
|
+
*
|
|
129
|
+
* @param {Record<string, any>} object - Source object.
|
|
130
|
+
* @param {(key: string, value: any) => string} fn - Key-mapping function.
|
|
131
|
+
* @returns {Record<string, any>} The remapped object.
|
|
132
|
+
*/
|
|
133
|
+
export function mapKeys(object: Record<string, any>, fn: (key: string, value: any) => string): Record<string, any>;
|
|
134
|
+
/**
|
|
135
|
+
* Swaps keys and values of an object.
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* nodeComfort.obj.invert({ a: "x", b: "y" }); // { x: "a", y: "b" }
|
|
139
|
+
*
|
|
140
|
+
* @param {Record<string, any>} object - Source object.
|
|
141
|
+
* @returns {Record<string, string>} The inverted object.
|
|
142
|
+
*/
|
|
143
|
+
export function invert(object: Record<string, any>): Record<string, string>;
|
|
144
|
+
/**
|
|
145
|
+
* Removes entries whose value is `null` or `undefined` (shallow).
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
* nodeComfort.obj.compact({ a: 1, b: null, c: undefined }); // { a: 1 }
|
|
149
|
+
*
|
|
150
|
+
* @param {Record<string, any>} object - Source object.
|
|
151
|
+
* @returns {Record<string, any>} The compacted object.
|
|
152
|
+
*/
|
|
153
|
+
export function compact(object: Record<string, any>): Record<string, any>;
|
|
154
|
+
/**
|
|
155
|
+
* Flattens a nested object into a single-level object with dot-path keys.
|
|
156
|
+
*
|
|
157
|
+
* @example
|
|
158
|
+
* nodeComfort.obj.flatten({ a: { b: { c: 1 } } }); // { "a.b.c": 1 }
|
|
159
|
+
*
|
|
160
|
+
* @param {Record<string, any>} object - Source object.
|
|
161
|
+
* @param {string} [prefix=""] - Prefix for keys (used internally).
|
|
162
|
+
* @returns {Record<string, any>} The flattened object.
|
|
163
|
+
*/
|
|
164
|
+
export function flatten(object: Record<string, any>, prefix?: string): Record<string, any>;
|
|
165
|
+
/**
|
|
166
|
+
* Rebuilds a nested object from a flat, dot-path keyed object.
|
|
167
|
+
*
|
|
168
|
+
* @example
|
|
169
|
+
* nodeComfort.obj.unflatten({ "a.b.c": 1 }); // { a: { b: { c: 1 } } }
|
|
170
|
+
*
|
|
171
|
+
* @param {Record<string, any>} object - Flat object.
|
|
172
|
+
* @returns {Record<string, any>} The nested object.
|
|
173
|
+
*/
|
|
174
|
+
export function unflatten(object: Record<string, any>): Record<string, any>;
|
|
175
|
+
/**
|
|
176
|
+
* Checks whether an object has no own enumerable keys.
|
|
177
|
+
*
|
|
178
|
+
* @param {Record<string, any>} object - Source object.
|
|
179
|
+
* @returns {boolean} True if the object is empty.
|
|
180
|
+
*/
|
|
181
|
+
export function isEmpty(object: Record<string, any>): boolean;
|
|
182
|
+
/**
|
|
183
|
+
* Freezes an object deeply, making it (and all nested objects) immutable.
|
|
184
|
+
*
|
|
185
|
+
* @param {Record<string, any>} object - Object to freeze.
|
|
186
|
+
* @returns {Record<string, any>} The same, now deeply-frozen, object.
|
|
187
|
+
*/
|
|
188
|
+
export function deepFreeze(object: Record<string, any>): Record<string, any>;
|
|
189
|
+
//# sourceMappingURL=Obj.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Obj.d.ts","sourceRoot":"","sources":["../../src/Obj.js"],"names":[],"mappings":"AAmEE;;;;;;;;;;;;;GAaG;AACH,sBAJa,CAAC,SACH,CAAC,GACC,CAAC,CASb;AAED;;;;;;;;;;;;GAYG;AACH,kCAHc,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAA,GACpB,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAkB/B;AAED;;;;;;;;;;;GAWG;AACH,yBAJW,GAAC,KACD,GAAC,GACC,OAAO,CA+BnB;AAED;;;;;;;;;;;GAWG;AACH,4BALW,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,QACnB,MAAM,GAAC,KAAK,CAAC,MAAM,GAAC,MAAM,CAAC,aAC3B,GAAC,GACC,GAAC,CAUb;AAED;;;;;;;;;;;;;GAaG;AACH,4BALW,MAAM,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;;;;GAQG;AACH,gCAHW,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GACjB,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAI/B;AAED;;;;;;;;;GASG;AACH,gCAJW,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,WACnB,MAAM,GACJ,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAa/B;AAED;;;;;;;;GAQG;AACH,kCAHW,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GACjB,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAQ/B;AAED;;;;;GAKG;AACH,gCAHW,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GACjB,OAAO,CAInB;AAED;;;;;GAKG;AACH,mCAHW,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GACjB,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAW/B"}
|
package/types/src/SQLite.d.ts
CHANGED
|
@@ -6,13 +6,18 @@ declare class SQLite {
|
|
|
6
6
|
* The database file and its parent folders are created if necessary.
|
|
7
7
|
* WAL journal mode and foreign key support are enabled automatically.
|
|
8
8
|
*
|
|
9
|
-
*
|
|
9
|
+
* Pass `":memory:"` to create a transient in-memory database.
|
|
10
|
+
*
|
|
11
|
+
* @param {string} [path="db.sqlite"] - Path to the SQLite database file.
|
|
10
12
|
*
|
|
11
13
|
* @example
|
|
12
14
|
* const db = new SQLite();
|
|
13
15
|
*
|
|
14
16
|
* @example
|
|
15
17
|
* const db = new SQLite("data/my-app.sqlite");
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* const db = new SQLite(":memory:");
|
|
16
21
|
*/
|
|
17
22
|
constructor(path?: string);
|
|
18
23
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SQLite.d.ts","sourceRoot":"","sources":["../../src/SQLite.js"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"SQLite.d.ts","sourceRoot":"","sources":["../../src/SQLite.js"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