@gesslar/toolkit 0.8.0 → 1.0.2
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 +39 -0
- package/package.json +22 -8
- package/src/browser/index.js +10 -0
- package/src/browser/lib/Sass.js +168 -0
- package/src/browser/lib/Tantrum.js +115 -0
- package/src/browser/lib/Util.js +257 -0
- package/src/browser/lib/Valid.js +76 -0
- package/src/index.js +14 -12
- package/src/lib/Cache.js +2 -3
- package/src/lib/Contract.js +3 -4
- package/src/lib/FS.js +15 -20
- package/src/lib/FileObject.js +1 -1
- package/src/lib/Glog.js +2 -2
- package/src/lib/Sass.js +2 -91
- package/src/lib/Schemer.js +2 -2
- package/src/lib/Tantrum.js +3 -70
- package/src/lib/Terms.js +2 -3
- package/src/lib/Util.js +2 -252
- package/src/lib/Valid.js +17 -20
- package/src/types/browser/index.d.ts +8 -0
- package/src/types/browser/index.d.ts.map +1 -0
- package/src/types/browser/lib/Collection.d.ts +246 -0
- package/src/types/browser/lib/Collection.d.ts.map +1 -0
- package/src/types/browser/lib/Data.d.ts +206 -0
- package/src/types/browser/lib/Data.d.ts.map +1 -0
- package/src/types/browser/lib/Sass.d.ts +62 -0
- package/src/types/browser/lib/Sass.d.ts.map +1 -0
- package/src/types/browser/lib/Tantrum.d.ts +51 -0
- package/src/types/browser/lib/Tantrum.d.ts.map +1 -0
- package/src/types/browser/lib/TypeSpec.d.ts +92 -0
- package/src/types/browser/lib/TypeSpec.d.ts.map +1 -0
- package/src/types/browser/lib/Util.d.ts +129 -0
- package/src/types/browser/lib/Util.d.ts.map +1 -0
- package/src/types/browser/lib/Valid.d.ts +33 -0
- package/src/types/browser/lib/Valid.d.ts.map +1 -0
- package/src/types/index.d.ts +10 -10
- package/src/types/lib/Cache.d.ts +2 -3
- package/src/types/lib/Cache.d.ts.map +1 -1
- package/src/types/lib/Contract.d.ts +3 -4
- package/src/types/lib/Contract.d.ts.map +1 -1
- package/src/types/lib/FS.d.ts +2 -2
- package/src/types/lib/FS.d.ts.map +1 -1
- package/src/types/lib/Sass.d.ts +2 -55
- package/src/types/lib/Sass.d.ts.map +1 -1
- package/src/types/lib/Tantrum.d.ts +3 -44
- package/src/types/lib/Tantrum.d.ts.map +1 -1
- package/src/types/lib/Terms.d.ts +2 -3
- package/src/types/lib/Terms.d.ts.map +1 -1
- package/src/types/lib/Util.d.ts +2 -123
- package/src/types/lib/Util.d.ts.map +1 -1
- package/src/types/lib/Valid.d.ts +1 -1
- package/src/types/lib/Valid.d.ts.map +1 -1
- /package/src/{lib → browser/lib}/Collection.js +0 -0
- /package/src/{lib → browser/lib}/Data.js +0 -0
- /package/src/{lib → browser/lib}/TypeSpec.js +0 -0
package/src/lib/Util.js
CHANGED
|
@@ -1,88 +1,13 @@
|
|
|
1
1
|
import {createHash} from "node:crypto"
|
|
2
|
-
import {performance} from "node:perf_hooks"
|
|
3
2
|
import {EventEmitter} from "node:events"
|
|
4
3
|
import Sass from "./Sass.js"
|
|
5
|
-
import
|
|
6
|
-
import Collection from "./Collection.js"
|
|
4
|
+
import {Util as BrowserUtil} from "../browser/index.js"
|
|
7
5
|
|
|
8
6
|
/**
|
|
9
7
|
* Utility class providing common helper functions for string manipulation,
|
|
10
8
|
* timing, hashing, and option parsing.
|
|
11
9
|
*/
|
|
12
|
-
export default class Util {
|
|
13
|
-
/**
|
|
14
|
-
* Capitalizes the first letter of a string.
|
|
15
|
-
*
|
|
16
|
-
* @param {string} text - The text to capitalize
|
|
17
|
-
* @returns {string} Text with first letter capitalized
|
|
18
|
-
*/
|
|
19
|
-
static capitalize(text) {
|
|
20
|
-
if(typeof text !== "string")
|
|
21
|
-
throw new TypeError("Util.capitalize expects a string")
|
|
22
|
-
|
|
23
|
-
if(text.length === 0)
|
|
24
|
-
return ""
|
|
25
|
-
|
|
26
|
-
const [first, ...rest] = Array.from(text)
|
|
27
|
-
|
|
28
|
-
return `${first.toLocaleUpperCase()}${rest.join("")}`
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Measure wall-clock time for an async function.
|
|
33
|
-
*
|
|
34
|
-
* @template T
|
|
35
|
-
* @param {() => Promise<T>} fn - Thunk returning a promise.
|
|
36
|
-
* @returns {Promise<{result: T, cost: number}>} Object containing result and elapsed ms (number, 1 decimal).
|
|
37
|
-
*/
|
|
38
|
-
static async time(fn) {
|
|
39
|
-
const t0 = performance.now()
|
|
40
|
-
const result = await fn()
|
|
41
|
-
const cost = Math.round((performance.now() - t0) * 10) / 10
|
|
42
|
-
|
|
43
|
-
return {result, cost}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Right-align a string inside a fixed width (left pad with spaces).
|
|
48
|
-
* If the string exceeds width it is returned unchanged.
|
|
49
|
-
*
|
|
50
|
-
* @param {string|number} text - Text to align.
|
|
51
|
-
* @param {number} width - Target field width (default 80).
|
|
52
|
-
* @returns {string} Padded string.
|
|
53
|
-
*/
|
|
54
|
-
static rightAlignText(text, width=80) {
|
|
55
|
-
const work = String(text)
|
|
56
|
-
|
|
57
|
-
if(work.length > width)
|
|
58
|
-
return work
|
|
59
|
-
|
|
60
|
-
const diff = width-work.length
|
|
61
|
-
|
|
62
|
-
return `${" ".repeat(diff)}${work}`
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Centre-align a string inside a fixed width (pad with spaces on left).
|
|
67
|
-
* If the string exceeds width it is returned unchanged.
|
|
68
|
-
*
|
|
69
|
-
* @param {string|number} text - Text to align.
|
|
70
|
-
* @param {number} width - Target field width (default 80).
|
|
71
|
-
* @returns {string} Padded string with text centred.
|
|
72
|
-
*/
|
|
73
|
-
static centreAlignText(text, width=80) {
|
|
74
|
-
const work = String(text)
|
|
75
|
-
|
|
76
|
-
if(work.length >= width)
|
|
77
|
-
return work
|
|
78
|
-
|
|
79
|
-
const totalPadding = width - work.length
|
|
80
|
-
const leftPadding = Math.floor(totalPadding / 2)
|
|
81
|
-
const rightPadding = totalPadding - leftPadding
|
|
82
|
-
|
|
83
|
-
return `${" ".repeat(leftPadding)}${work}${" ".repeat(rightPadding)}`
|
|
84
|
-
}
|
|
85
|
-
|
|
10
|
+
export default class Util extends BrowserUtil {
|
|
86
11
|
/**
|
|
87
12
|
* Compute sha256 hash (hex) of the provided string.
|
|
88
13
|
*
|
|
@@ -130,100 +55,6 @@ export default class Util {
|
|
|
130
55
|
.filter(option => option && /^[a-zA-Z0-9]/.test(option)) // Filter out options that don't start with alphanumeric
|
|
131
56
|
}
|
|
132
57
|
|
|
133
|
-
/**
|
|
134
|
-
* Asynchronously awaits all promises in parallel.
|
|
135
|
-
* Wrapper around Promise.all for consistency with other utility methods.
|
|
136
|
-
*
|
|
137
|
-
* @param {Array<Promise<unknown>>} promises - Array of promises to await
|
|
138
|
-
* @returns {Promise<Array<unknown>>} Results of all promises
|
|
139
|
-
*/
|
|
140
|
-
static async awaitAll(promises) {
|
|
141
|
-
return await Promise.all(promises)
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* Settles all promises (both fulfilled and rejected) in parallel.
|
|
146
|
-
* Wrapper around Promise.allSettled for consistency with other utility methods.
|
|
147
|
-
*
|
|
148
|
-
* @param {Array<Promise<unknown>>} promises - Array of promises to settle
|
|
149
|
-
* @returns {Promise<Array<object>>} Results of all settled promises with status and value/reason
|
|
150
|
-
*/
|
|
151
|
-
static async settleAll(promises) {
|
|
152
|
-
return await Promise.allSettled(promises)
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* Checks if any result in the settled promise array is rejected.
|
|
157
|
-
*
|
|
158
|
-
* @param {Array<object>} result - Array of settled promise results.
|
|
159
|
-
* @returns {boolean} True if any result is rejected, false otherwise.
|
|
160
|
-
*/
|
|
161
|
-
static anyRejected(result) {
|
|
162
|
-
return result.some(r => r.status === "rejected")
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
/**
|
|
166
|
-
* Filters and returns all rejected results from a settled promise array.
|
|
167
|
-
*
|
|
168
|
-
* @param {Array<object>} result - Array of settled promise results.
|
|
169
|
-
* @returns {Array<object>} Array of rejected results.
|
|
170
|
-
*/
|
|
171
|
-
static settledAndRejected(result) {
|
|
172
|
-
return result.filter(r => r.status === "rejected")
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
/**
|
|
176
|
-
* Extracts the rejection reasons from an array of rejected promise results.
|
|
177
|
-
*
|
|
178
|
-
* @param {Array<object>} rejected - Array of rejected results.
|
|
179
|
-
* @returns {Array<unknown>} Array of rejection reasons.
|
|
180
|
-
*/
|
|
181
|
-
static rejectedReasons(rejected) {
|
|
182
|
-
return rejected.map(r => r.reason)
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
/**
|
|
186
|
-
* Throws a Sass error containing all rejection reasons from settled promises.
|
|
187
|
-
*
|
|
188
|
-
* @param {string} [_message] - Optional error message. Defaults to "GIGO"
|
|
189
|
-
* @param {Array<object>} rejected - Array of rejected results.
|
|
190
|
-
* @throws {Error} Throws a Sass error with rejection reasons.
|
|
191
|
-
*/
|
|
192
|
-
static throwRejected(_message="GIGO", rejected) {
|
|
193
|
-
throw Sass.new(Util.rejectedReasons(rejected))
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
/**
|
|
197
|
-
* Filters and returns all fulfilled results from a settled promise array.
|
|
198
|
-
*
|
|
199
|
-
* @param {Array<object>} result - Array of settled promise results.
|
|
200
|
-
* @returns {Array<object>} Array of fulfilled results.
|
|
201
|
-
*/
|
|
202
|
-
static settledAndFulfilled(result) {
|
|
203
|
-
return result.filter(r => r.status === "fulfilled")
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
/**
|
|
207
|
-
* Extracts the values from all fulfilled results in a settled promise array.
|
|
208
|
-
*
|
|
209
|
-
* @param {Array<object>} result - Array of settled promise results.
|
|
210
|
-
* @returns {Array<unknown>} Array of fulfilled values.
|
|
211
|
-
*/
|
|
212
|
-
static fulfilledValues(result) {
|
|
213
|
-
return this.settledAndFulfilled(result).map(r => r.value)
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
/**
|
|
217
|
-
* Returns the first promise to resolve or reject from an array of promises.
|
|
218
|
-
* Wrapper around Promise.race for consistency with other utility methods.
|
|
219
|
-
*
|
|
220
|
-
* @param {Array<Promise<unknown>>} promises - Array of promises to race
|
|
221
|
-
* @returns {Promise<unknown>} Result of the first settled promise
|
|
222
|
-
*/
|
|
223
|
-
static async race(promises) {
|
|
224
|
-
return await Promise.race(promises)
|
|
225
|
-
}
|
|
226
|
-
|
|
227
58
|
/**
|
|
228
59
|
* Private method that performs the actual async emission logic.
|
|
229
60
|
* Handles listener execution, error aggregation, and result processing.
|
|
@@ -321,85 +152,4 @@ export default class Util {
|
|
|
321
152
|
)
|
|
322
153
|
}
|
|
323
154
|
}
|
|
324
|
-
|
|
325
|
-
/**
|
|
326
|
-
* Determine the Levenshtein distance between two string values
|
|
327
|
-
*
|
|
328
|
-
* @param {string} a The first value for comparison.
|
|
329
|
-
* @param {string} b The second value for comparison.
|
|
330
|
-
* @returns {number} The Levenshtein distance
|
|
331
|
-
*/
|
|
332
|
-
static levenshteinDistance(a, b) {
|
|
333
|
-
const matrix = Array.from({length: a.length + 1}, (_, i) =>
|
|
334
|
-
Array.from({length: b.length + 1}, (_, j) =>
|
|
335
|
-
(i === 0 ? j : j === 0 ? i : 0)
|
|
336
|
-
)
|
|
337
|
-
)
|
|
338
|
-
|
|
339
|
-
for(let i = 1; i <= a.length; i++) {
|
|
340
|
-
for(let j = 1; j <= b.length; j++) {
|
|
341
|
-
matrix[i][j] =
|
|
342
|
-
a[i - 1] === b[j - 1]
|
|
343
|
-
? matrix[i - 1][j - 1]
|
|
344
|
-
: 1 + Math.min(
|
|
345
|
-
matrix[i - 1][j], matrix[i][j - 1],
|
|
346
|
-
matrix[i - 1][j - 1]
|
|
347
|
-
)
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
return matrix[a.length][b.length]
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
/**
|
|
355
|
-
* Determine the closest match between a string and allowed values
|
|
356
|
-
* from the Levenshtein distance.
|
|
357
|
-
*
|
|
358
|
-
* @param {string} input The input string to resolve
|
|
359
|
-
* @param {Array<string>} allowedValues The values which are permitted
|
|
360
|
-
* @param {number} [threshold] Max edit distance for a "close match"
|
|
361
|
-
* @returns {string} Suggested, probable match.
|
|
362
|
-
*/
|
|
363
|
-
static findClosestMatch(input, allowedValues, threshold=2) {
|
|
364
|
-
let closestMatch = null
|
|
365
|
-
let closestDistance = Infinity
|
|
366
|
-
let closestLengthDiff = Infinity
|
|
367
|
-
|
|
368
|
-
for(const value of allowedValues) {
|
|
369
|
-
const distance = Util.levenshteinDistance(input, value)
|
|
370
|
-
const lengthDiff = Math.abs(input.length - value.length)
|
|
371
|
-
|
|
372
|
-
if(distance < closestDistance && distance <= threshold) {
|
|
373
|
-
closestMatch = value
|
|
374
|
-
closestDistance = distance
|
|
375
|
-
closestLengthDiff = lengthDiff
|
|
376
|
-
} else if(distance === closestDistance &&
|
|
377
|
-
distance <= threshold &&
|
|
378
|
-
lengthDiff < closestLengthDiff) {
|
|
379
|
-
closestMatch = value
|
|
380
|
-
closestLengthDiff = lengthDiff
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
return closestMatch
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
static regexify(input, trim=true, flags=[]) {
|
|
388
|
-
Valid.type(input, "String")
|
|
389
|
-
Valid.type(trim, "Boolean")
|
|
390
|
-
Valid.type(flags, "Array")
|
|
391
|
-
|
|
392
|
-
Valid.assert(
|
|
393
|
-
flags.length === 0 ||
|
|
394
|
-
(flags.length > 0 && Collection.isArrayUniform(flags, "String")),
|
|
395
|
-
"All flags must be strings")
|
|
396
|
-
|
|
397
|
-
return new RegExp(
|
|
398
|
-
input
|
|
399
|
-
.split(/\r\n|\r|\n/)
|
|
400
|
-
.map(i => trim ? i.trim() : i)
|
|
401
|
-
.filter(i => trim ? Boolean(i) : true)
|
|
402
|
-
.join("")
|
|
403
|
-
, flags?.join(""))
|
|
404
|
-
}
|
|
405
155
|
}
|
package/src/lib/Valid.js
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @file Valid.js
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* Node-flavoured validation utilities that throw the Node Sass error type.
|
|
5
|
+
* Mirrors the browser Valid API so browser and Node callers behave the same.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import _assert from "node:assert/strict"
|
|
9
|
-
|
|
10
8
|
import Sass from "./Sass.js"
|
|
11
|
-
import Data from "
|
|
12
|
-
import Collection from "
|
|
9
|
+
import Data from "../browser/lib/Data.js"
|
|
10
|
+
import Collection from "../browser/lib/Collection.js"
|
|
13
11
|
|
|
14
12
|
/**
|
|
15
13
|
* Validation utility class providing type checking and assertion methods.
|
|
16
14
|
*/
|
|
17
15
|
export default class Valid {
|
|
16
|
+
static #restrictedProto = ["__proto__", "constructor", "prototype"]
|
|
17
|
+
|
|
18
18
|
/**
|
|
19
19
|
* Validates a value against a type. Uses Data.isType.
|
|
20
20
|
*
|
|
@@ -40,25 +40,22 @@ export default class Valid {
|
|
|
40
40
|
* met (optional)
|
|
41
41
|
*/
|
|
42
42
|
static assert(condition, message, arg = null) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
)
|
|
43
|
+
if(!Data.isType(condition, "boolean")) {
|
|
44
|
+
throw Sass.new(`Condition must be a boolean, got ${condition}`)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if(!Data.isType(message, "string")) {
|
|
48
|
+
throw Sass.new(`Message must be a string, got ${message}`)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if(!(arg === null || arg === undefined || typeof arg === "number")) {
|
|
52
|
+
throw Sass.new(`Arg must be a number, got ${arg}`)
|
|
53
|
+
}
|
|
55
54
|
|
|
56
55
|
if(!condition)
|
|
57
56
|
throw Sass.new(`${message}${arg ? `: ${arg}` : ""}`)
|
|
58
57
|
}
|
|
59
58
|
|
|
60
|
-
static #restrictedProto = ["__proto__", "constructor", "prototype"]
|
|
61
|
-
|
|
62
59
|
/**
|
|
63
60
|
* Protects against prototype pollution by checking keys for dangerous property names.
|
|
64
61
|
* Throws if any restricted prototype properties are found in the keys array.
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { default as Collection } from "./lib/Collection.js";
|
|
2
|
+
export { default as Data } from "./lib/Data.js";
|
|
3
|
+
export { default as Sass } from "./lib/Sass.js";
|
|
4
|
+
export { default as Tantrum } from "./lib/Tantrum.js";
|
|
5
|
+
export { default as Type } from "./lib/TypeSpec.js";
|
|
6
|
+
export { default as Util } from "./lib/Util.js";
|
|
7
|
+
export { default as Valid } from "./lib/Valid.js";
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../browser/index.js"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility class for collection operations.
|
|
3
|
+
* Provides static methods for working with arrays, objects, sets, and maps.
|
|
4
|
+
*/
|
|
5
|
+
export default class Collection {
|
|
6
|
+
/**
|
|
7
|
+
* Evaluates an array with a predicate function, optionally in reverse order.
|
|
8
|
+
* Returns the first truthy result from the predicate.
|
|
9
|
+
*
|
|
10
|
+
* @param {Array<unknown>} collection - The array to evaluate
|
|
11
|
+
* @param {(value: unknown, index: number, array: Array<unknown>) => unknown} predicate - Function to evaluate each element
|
|
12
|
+
* @param {boolean} [forward] - Whether to iterate forward (true) or backward (false). Defaults to true
|
|
13
|
+
* @returns {unknown|undefined} The first truthy result from the predicate, or undefined
|
|
14
|
+
* @throws {Sass} If collection is not an array or predicate is not a function
|
|
15
|
+
*/
|
|
16
|
+
static evalArray(collection: Array<unknown>, predicate: (value: unknown, index: number, array: Array<unknown>) => unknown, forward?: boolean): unknown | undefined;
|
|
17
|
+
/**
|
|
18
|
+
* Evaluates an object with a predicate function.
|
|
19
|
+
* Returns the first truthy result from the predicate.
|
|
20
|
+
*
|
|
21
|
+
* @param {object} collection - The object to evaluate
|
|
22
|
+
* @param {(value: unknown, key: string, object: object) => unknown} predicate - Function to evaluate each property
|
|
23
|
+
* @returns {unknown|undefined} The first truthy result from the predicate, or undefined
|
|
24
|
+
* @throws {Sass} If collection is not an object or predicate is not a function
|
|
25
|
+
*/
|
|
26
|
+
static evalObject(collection: object, predicate: (value: unknown, key: string, object: object) => unknown): unknown | undefined;
|
|
27
|
+
/**
|
|
28
|
+
* Evaluates a Set with a predicate function.
|
|
29
|
+
* Returns the first truthy result from the predicate.
|
|
30
|
+
*
|
|
31
|
+
* @param {Set<unknown>} collection - The Set to evaluate
|
|
32
|
+
* @param {(value: unknown, set: Set<unknown>) => unknown} predicate - Function to evaluate each element
|
|
33
|
+
* @returns {unknown|undefined} The first truthy result from the predicate, or undefined
|
|
34
|
+
* @throws {Sass} If collection is not a Set or predicate is not a function
|
|
35
|
+
*/
|
|
36
|
+
static evalSet(collection: Set<unknown>, predicate: (value: unknown, set: Set<unknown>) => unknown): unknown | undefined;
|
|
37
|
+
/**
|
|
38
|
+
* Evaluates a Map with a predicate function, optionally in reverse order.
|
|
39
|
+
* Returns the first truthy result from the predicate.
|
|
40
|
+
*
|
|
41
|
+
* @param {Map<unknown, unknown>} collection - The Map to evaluate
|
|
42
|
+
* @param {(value: unknown, key: unknown, map: Map<unknown, unknown>) => unknown} predicate - Function to evaluate each entry
|
|
43
|
+
* @param {boolean} [forward] - Whether to iterate forward (true) or backward (false). Defaults to true
|
|
44
|
+
* @returns {unknown|undefined} The first truthy result from the predicate, or undefined
|
|
45
|
+
* @throws {Sass} If collection is not a Map or predicate is not a function
|
|
46
|
+
*/
|
|
47
|
+
static evalMap(collection: Map<unknown, unknown>, predicate: (value: unknown, key: unknown, map: Map<unknown, unknown>) => unknown, forward?: boolean): unknown | undefined;
|
|
48
|
+
/**
|
|
49
|
+
* Zips two arrays together into an array of pairs.
|
|
50
|
+
* The resulting array length equals the shorter input array.
|
|
51
|
+
*
|
|
52
|
+
* @param {Array<unknown>} array1 - The first array
|
|
53
|
+
* @param {Array<unknown>} array2 - The second array
|
|
54
|
+
* @returns {Array<[unknown, unknown]>} Array of paired elements
|
|
55
|
+
*/
|
|
56
|
+
static zip(array1: Array<unknown>, array2: Array<unknown>): Array<[unknown, unknown]>;
|
|
57
|
+
/**
|
|
58
|
+
* Unzips an array of pairs into separate arrays.
|
|
59
|
+
* Transposes a 2D array structure.
|
|
60
|
+
*
|
|
61
|
+
* @param {Array<Array<unknown>>} array - Array of arrays to unzip
|
|
62
|
+
* @returns {Array<Array<unknown>>} Array of unzipped arrays, or empty array for invalid input
|
|
63
|
+
*/
|
|
64
|
+
static unzip(array: Array<Array<unknown>>): Array<Array<unknown>>;
|
|
65
|
+
/**
|
|
66
|
+
* Maps an array using an async function, processing items sequentially.
|
|
67
|
+
* Unlike Promise.all(array.map()), this processes one item at a time.
|
|
68
|
+
*
|
|
69
|
+
* @param {Array<unknown>} array - The array to map
|
|
70
|
+
* @param {(item: unknown) => Promise<unknown>} asyncFn - Async function to apply to each element
|
|
71
|
+
* @returns {Promise<Array<unknown>>} Promise resolving to the mapped array
|
|
72
|
+
* @throws {Sass} If array is not an Array or asyncFn is not a function
|
|
73
|
+
*/
|
|
74
|
+
static asyncMap(array: Array<unknown>, asyncFn: (item: unknown) => Promise<unknown>): Promise<Array<unknown>>;
|
|
75
|
+
/**
|
|
76
|
+
* Checks if all elements in an array are of a specified type
|
|
77
|
+
*
|
|
78
|
+
* @param {Array<unknown>} arr - The array to check
|
|
79
|
+
* @param {string} [type] - The type to check for (optional, defaults to the type of the first element)
|
|
80
|
+
* @returns {boolean} Whether all elements are of the specified type
|
|
81
|
+
*/
|
|
82
|
+
static isArrayUniform(arr: Array<unknown>, type?: string): boolean;
|
|
83
|
+
/**
|
|
84
|
+
* Checks if an array is unique
|
|
85
|
+
*
|
|
86
|
+
* @param {Array<unknown>} arr - The array of which to remove duplicates
|
|
87
|
+
* @returns {Array<unknown>} The unique elements of the array
|
|
88
|
+
*/
|
|
89
|
+
static isArrayUnique(arr: Array<unknown>): Array<unknown>;
|
|
90
|
+
/**
|
|
91
|
+
* Returns the intersection of two arrays.
|
|
92
|
+
*
|
|
93
|
+
* @param {Array<unknown>} arr1 - The first array.
|
|
94
|
+
* @param {Array<unknown>} arr2 - The second array.
|
|
95
|
+
* @returns {Array<unknown>} The intersection of the two arrays.
|
|
96
|
+
*/
|
|
97
|
+
static intersection(arr1: Array<unknown>, arr2: Array<unknown>): Array<unknown>;
|
|
98
|
+
/**
|
|
99
|
+
* Checks whether two arrays have any elements in common.
|
|
100
|
+
*
|
|
101
|
+
* This function returns `true` if at least one element from `arr1` exists in
|
|
102
|
+
* `arr2`, and `false` otherwise. It optimizes by iterating over the shorter
|
|
103
|
+
* array for efficiency.
|
|
104
|
+
*
|
|
105
|
+
* Example:
|
|
106
|
+
* Collection.intersects([1, 2, 3], [3, 4, 5]) // returns true
|
|
107
|
+
* Collection.intersects(["a", "b"], ["c", "d"]) // returns false
|
|
108
|
+
*
|
|
109
|
+
* @param {Array<unknown>} arr1 - The first array to check for intersection.
|
|
110
|
+
* @param {Array<unknown>} arr2 - The second array to check for intersection.
|
|
111
|
+
* @returns {boolean} True if any element is shared between the arrays, false otherwise.
|
|
112
|
+
*/
|
|
113
|
+
static intersects(arr1: Array<unknown>, arr2: Array<unknown>): boolean;
|
|
114
|
+
/**
|
|
115
|
+
* Pads an array to a specified length with a value. This operation
|
|
116
|
+
* occurs in-place.
|
|
117
|
+
*
|
|
118
|
+
* @param {Array<unknown>} arr - The array to pad.
|
|
119
|
+
* @param {number} length - The length to pad the array to.
|
|
120
|
+
* @param {unknown} value - The value to pad the array with.
|
|
121
|
+
* @param {number} [position] - The position to pad the array at. Defaults to 0
|
|
122
|
+
* @returns {Array<unknown>} The padded array.
|
|
123
|
+
*/
|
|
124
|
+
static arrayPad(arr: Array<unknown>, length: number, value: unknown, position?: number): Array<unknown>;
|
|
125
|
+
/**
|
|
126
|
+
* Filters an array asynchronously using a predicate function.
|
|
127
|
+
* Applies the predicate to all items in parallel and returns filtered results.
|
|
128
|
+
*
|
|
129
|
+
* @param {Array<unknown>} arr - The array to filter
|
|
130
|
+
* @param {(value: unknown, index: number, array: Array<unknown>) => Promise<boolean>} predicate - Async predicate function that returns a promise resolving to boolean
|
|
131
|
+
* @returns {Promise<Array<unknown>>} Promise resolving to the filtered array
|
|
132
|
+
*/
|
|
133
|
+
static asyncFilter(arr: Array<unknown>, predicate: (value: unknown, index: number, array: Array<unknown>) => Promise<boolean>): Promise<Array<unknown>>;
|
|
134
|
+
/**
|
|
135
|
+
* Clones an object
|
|
136
|
+
*
|
|
137
|
+
* @param {object} obj - The object to clone
|
|
138
|
+
* @param {boolean} freeze - Whether to freeze the cloned object
|
|
139
|
+
* @returns {object} The cloned object
|
|
140
|
+
*/
|
|
141
|
+
static cloneObject(obj: object, freeze?: boolean): object;
|
|
142
|
+
/**
|
|
143
|
+
* Checks if an object is empty
|
|
144
|
+
*
|
|
145
|
+
* @param {object} obj - The object to check
|
|
146
|
+
* @returns {boolean} Whether the object is empty
|
|
147
|
+
*/
|
|
148
|
+
static isObjectEmpty(obj: object): boolean;
|
|
149
|
+
/**
|
|
150
|
+
* Ensures that a nested path of objects exists within the given object.
|
|
151
|
+
* Creates empty objects along the path if they don't exist.
|
|
152
|
+
*
|
|
153
|
+
* @param {object} obj - The object to check/modify
|
|
154
|
+
* @param {Array<string>} keys - Array of keys representing the path to ensure
|
|
155
|
+
* @returns {object} Reference to the deepest nested object in the path
|
|
156
|
+
*/
|
|
157
|
+
static assureObjectPath(obj: object, keys: Array<string>): object;
|
|
158
|
+
/**
|
|
159
|
+
* Sets a value in a nested object structure using an array of keys; creating
|
|
160
|
+
* the structure if it does not exist.
|
|
161
|
+
*
|
|
162
|
+
* @param {object} obj - The target object to set the value in
|
|
163
|
+
* @param {Array<string>} keys - Array of keys representing the path to the target property
|
|
164
|
+
* @param {unknown} value - The value to set at the target location
|
|
165
|
+
*/
|
|
166
|
+
static setNestedValue(obj: object, keys: Array<string>, value: unknown): void;
|
|
167
|
+
/**
|
|
168
|
+
* Deeply merges two or more objects. Arrays are replaced, not merged.
|
|
169
|
+
*
|
|
170
|
+
* @param {...object} sources - Objects to merge (left to right)
|
|
171
|
+
* @returns {object} The merged object
|
|
172
|
+
*/
|
|
173
|
+
static mergeObject(...sources: object[]): object;
|
|
174
|
+
/**
|
|
175
|
+
* Freezes an object and all of its properties recursively.
|
|
176
|
+
*
|
|
177
|
+
* @param {object} obj The object to freeze.
|
|
178
|
+
* @returns {object} The frozen object.
|
|
179
|
+
*/
|
|
180
|
+
static deepFreezeObject(obj: object): object;
|
|
181
|
+
/**
|
|
182
|
+
* Maps an object using a transformer function
|
|
183
|
+
*
|
|
184
|
+
* @param {object} original The original object
|
|
185
|
+
* @param {function(unknown): unknown} transformer The transformer function
|
|
186
|
+
* @param {boolean} mutate Whether to mutate the original object
|
|
187
|
+
* @returns {Promise<object>} The mapped object
|
|
188
|
+
*/
|
|
189
|
+
static mapObject(original: object, transformer: (arg0: unknown) => unknown, mutate?: boolean): Promise<object>;
|
|
190
|
+
/**
|
|
191
|
+
* Allocates an object from a source array and a spec array or function.
|
|
192
|
+
*
|
|
193
|
+
* @param {unknown} source The source array
|
|
194
|
+
* @param {Array<unknown>|function(Array<unknown>): Promise<Array<unknown>>|Array<unknown>} spec The spec array or function
|
|
195
|
+
* @returns {Promise<object>} The allocated object
|
|
196
|
+
*/
|
|
197
|
+
static allocateObject(source: unknown, spec: Array<unknown> | ((arg0: Array<unknown>) => Promise<Array<unknown>> | Array<unknown>)): Promise<object>;
|
|
198
|
+
/**
|
|
199
|
+
* Trims falsy values from both ends of an array (in-place).
|
|
200
|
+
* Optionally preserves specific falsy values.
|
|
201
|
+
*
|
|
202
|
+
* @param {Array<unknown>} arr - The array to trim
|
|
203
|
+
* @param {Array<unknown>} [except] - Values to preserve even if falsy. Defaults to empty array
|
|
204
|
+
* @returns {Array<unknown>} The trimmed array (same reference, modified in-place)
|
|
205
|
+
* @throws {Sass} If arr is not an Array or except is not an Array
|
|
206
|
+
*/
|
|
207
|
+
static trimArray(arr: Array<unknown>, except?: Array<unknown>): Array<unknown>;
|
|
208
|
+
/**
|
|
209
|
+
* Trims falsy values from the right end of an array (in-place).
|
|
210
|
+
* Optionally preserves specific falsy values.
|
|
211
|
+
*
|
|
212
|
+
* @param {Array<unknown>} arr - The array to trim
|
|
213
|
+
* @param {Array<unknown>} [except] - Values to preserve even if falsy. Defaults to empty array
|
|
214
|
+
* @returns {Array<unknown>} The trimmed array (same reference, modified in-place)
|
|
215
|
+
* @throws {Sass} If arr is not an Array or except is not an Array
|
|
216
|
+
*/
|
|
217
|
+
static trimArrayRight(arr: Array<unknown>, except?: Array<unknown>): Array<unknown>;
|
|
218
|
+
/**
|
|
219
|
+
* Trims falsy values from the left end of an array (in-place).
|
|
220
|
+
* Optionally preserves specific falsy values.
|
|
221
|
+
*
|
|
222
|
+
* @param {Array<unknown>} arr - The array to trim
|
|
223
|
+
* @param {Array<unknown>} [except] - Values to preserve even if falsy. Defaults to empty array
|
|
224
|
+
* @returns {Array<unknown>} The trimmed array (same reference, modified in-place)
|
|
225
|
+
* @throws {Sass} If arr is not an Array or except is not an Array
|
|
226
|
+
*/
|
|
227
|
+
static trimArrayLeft(arr: Array<unknown>, except?: Array<unknown>): Array<unknown>;
|
|
228
|
+
/**
|
|
229
|
+
* Transposes an array of objects into an object of arrays.
|
|
230
|
+
* Collects values for each key across all objects into arrays.
|
|
231
|
+
*
|
|
232
|
+
* @param {Array<object>} objects - Array of plain objects to transpose
|
|
233
|
+
* @returns {object} Object with keys from input objects, values as arrays
|
|
234
|
+
* @throws {Sass} If objects is not an Array or contains non-plain objects
|
|
235
|
+
*/
|
|
236
|
+
static transposeObjects(objects: Array<object>): object;
|
|
237
|
+
/**
|
|
238
|
+
* Flattens an array (or nested array) of objects and transposes them.
|
|
239
|
+
* Combines flat() and transposeObjects() operations.
|
|
240
|
+
*
|
|
241
|
+
* @param {Array<object>|Array<Array<object>>} input - Array or nested array of objects
|
|
242
|
+
* @returns {object} Transposed object with arrays of values
|
|
243
|
+
*/
|
|
244
|
+
static flattenObjectArray(input: Array<object> | Array<Array<object>>): object;
|
|
245
|
+
}
|
|
246
|
+
//# sourceMappingURL=Collection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Collection.d.ts","sourceRoot":"","sources":["../../../browser/lib/Collection.js"],"names":[],"mappings":"AAaA;;;GAGG;AACH;IACE;;;;;;;;;OASG;IACH,6BANW,KAAK,CAAC,OAAO,CAAC,aACd,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,CAAC,OAAO,CAAC,KAAK,OAAO,YACjE,OAAO,GACL,OAAO,GAAC,SAAS,CAqB7B;IAED;;;;;;;;OAQG;IACH,8BALW,MAAM,aACN,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,OAAO,GACtD,OAAO,GAAC,SAAS,CAmB7B;IAED;;;;;;;;OAQG;IACH,2BALW,GAAG,CAAC,OAAO,CAAC,aACZ,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,CAAC,OAAO,CAAC,KAAK,OAAO,GAC5C,OAAO,GAAC,SAAS,CAmB7B;IAED;;;;;;;;;OASG;IACH,2BANW,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,aACrB,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,E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