@gesslar/toolkit 0.0.3 → 0.0.5
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/package.json +1 -1
- package/src/lib/Data.js +6 -6
- package/src/lib/File.js +1 -1
- package/src/lib/FileObject.js +3 -7
- package/src/lib/Term.js +2 -2
- package/src/lib/Type.js +2 -2
- package/src/lib/Util.js +6 -6
- package/src/types/Cache.d.ts +3 -2
- package/src/types/Data.d.ts +16 -15
- package/src/types/DirectoryObject.d.ts +1 -0
- package/src/types/File.d.ts +4 -3
- package/src/types/FileObject.d.ts +1 -0
- package/src/types/Sass.d.ts +3 -2
- package/src/types/Term.d.ts +6 -5
- package/src/types/Type.d.ts +5 -4
- package/src/types/Util.d.ts +6 -4
- package/src/types/Valid.d.ts +1 -0
- package/src/types/index.d.ts +1 -0
package/package.json
CHANGED
package/src/lib/Data.js
CHANGED
|
@@ -12,7 +12,7 @@ export default class Data {
|
|
|
12
12
|
* Array of JavaScript primitive type names.
|
|
13
13
|
* Includes basic types and object categories from the typeof operator.
|
|
14
14
|
*
|
|
15
|
-
* @type {string
|
|
15
|
+
* @type {Array<string>}
|
|
16
16
|
*/
|
|
17
17
|
static primitives = Object.freeze([
|
|
18
18
|
// Primitives
|
|
@@ -32,7 +32,7 @@ export default class Data {
|
|
|
32
32
|
* Array of JavaScript constructor names for built-in objects.
|
|
33
33
|
* Includes common object types and typed arrays.
|
|
34
34
|
*
|
|
35
|
-
* @type {string
|
|
35
|
+
* @type {Array<string>}
|
|
36
36
|
*/
|
|
37
37
|
static constructors = Object.freeze([
|
|
38
38
|
// Object Constructors
|
|
@@ -57,7 +57,7 @@ export default class Data {
|
|
|
57
57
|
* Combined array of all supported data types (primitives and constructors in lowercase).
|
|
58
58
|
* Used for type validation throughout the utility functions.
|
|
59
59
|
*
|
|
60
|
-
* @type {string
|
|
60
|
+
* @type {Array<string>}
|
|
61
61
|
*/
|
|
62
62
|
static dataTypes = Object.freeze([
|
|
63
63
|
...Data.primitives,
|
|
@@ -68,7 +68,7 @@ export default class Data {
|
|
|
68
68
|
* Array of type names that can be checked for emptiness.
|
|
69
69
|
* These types have meaningful empty states that can be tested.
|
|
70
70
|
*
|
|
71
|
-
* @type {string
|
|
71
|
+
* @type {Array<string>}
|
|
72
72
|
*/
|
|
73
73
|
static emptyableTypes = Object.freeze(["string", "array", "object"])
|
|
74
74
|
|
|
@@ -204,7 +204,7 @@ export default class Data {
|
|
|
204
204
|
* Allocates an object from a source array and a spec array or function.
|
|
205
205
|
*
|
|
206
206
|
* @param {unknown} source The source array
|
|
207
|
-
* @param {Array
|
|
207
|
+
* @param {Array<unknown>|function(Array<unknown>): Promise<Array<unknown>>|Array<unknown>} spec The spec array or function
|
|
208
208
|
* @returns {Promise<object>} The allocated object
|
|
209
209
|
*/
|
|
210
210
|
static async allocateObject(source, spec) {
|
|
@@ -289,7 +289,7 @@ export default class Data {
|
|
|
289
289
|
*
|
|
290
290
|
* @param {string} string - The string to parse into a type spec.
|
|
291
291
|
* @param {object} options - Additional options for parsing.
|
|
292
|
-
* @returns {object
|
|
292
|
+
* @returns {Array<object>} An array of type specs.
|
|
293
293
|
*/
|
|
294
294
|
static newTypeSpec(string, options) {
|
|
295
295
|
return new TypeSpec(string, options)
|
package/src/lib/File.js
CHANGED
|
@@ -178,7 +178,7 @@ export default class File {
|
|
|
178
178
|
/**
|
|
179
179
|
* Retrieve all files matching a specific glob pattern.
|
|
180
180
|
*
|
|
181
|
-
* @param {string|string
|
|
181
|
+
* @param {string|Array<string>} glob - The glob pattern(s) to search.
|
|
182
182
|
* @returns {Promise<Array<FileObject>>} A promise that resolves to an array of file objects
|
|
183
183
|
* @throws {Sass} If the input is not a string or array of strings.
|
|
184
184
|
* @throws {Sass} If the glob pattern array is empty or for other search failures.
|
package/src/lib/FileObject.js
CHANGED
|
@@ -66,13 +66,9 @@ export default class FileObject {
|
|
|
66
66
|
if(!directory)
|
|
67
67
|
directory = new DirectoryObject(dir)
|
|
68
68
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
final = fixedFile
|
|
73
|
-
} else {
|
|
74
|
-
final = path.resolve(directory.path, fixedFile)
|
|
75
|
-
}
|
|
69
|
+
const final = path.isAbsolute(fixedFile)
|
|
70
|
+
? fixedFile
|
|
71
|
+
: path.resolve(directory.path, fixedFile)
|
|
76
72
|
|
|
77
73
|
const resolved = final
|
|
78
74
|
const fileUri = File.pathToUri(resolved)
|
package/src/lib/Term.js
CHANGED
|
@@ -91,7 +91,7 @@ export default class Term {
|
|
|
91
91
|
* Recursion: array input is normalised into a single string then re-dispatched
|
|
92
92
|
* through `status` to leverage the string branch (keeps logic DRY).
|
|
93
93
|
*
|
|
94
|
-
* @param {string | Array<string, string
|
|
94
|
+
* @param {string | Array<string | [string, string] | [string, string, string]>} argList - Message spec.
|
|
95
95
|
* @returns {void}
|
|
96
96
|
*/
|
|
97
97
|
static terminalMessage(argList) {
|
|
@@ -142,7 +142,7 @@ export default class Term {
|
|
|
142
142
|
* This method does not append trailing spaces; callers are responsible for
|
|
143
143
|
* joining multiple segments with appropriate separators.
|
|
144
144
|
*
|
|
145
|
-
* @param {string
|
|
145
|
+
* @param {Array<string>} parts - Tuple: [level, text]. Additional entries ignored.
|
|
146
146
|
* @returns {string} Colourised bracketed segment (e.g. "[TEXT]").
|
|
147
147
|
* @throws {Sass} If any element of `parts` is not a string.
|
|
148
148
|
*/
|
package/src/lib/Type.js
CHANGED
|
@@ -90,7 +90,7 @@ export default class TypeSpec {
|
|
|
90
90
|
* Creates a new array with all type specifications that pass the provided test function.
|
|
91
91
|
*
|
|
92
92
|
* @param {function(unknown): boolean} callback - Function to test each spec
|
|
93
|
-
* @returns {Array} New array with filtered specs
|
|
93
|
+
* @returns {Array<unknown>} New array with filtered specs
|
|
94
94
|
*/
|
|
95
95
|
filter(callback) {
|
|
96
96
|
return this.#specs.filter(callback)
|
|
@@ -100,7 +100,7 @@ export default class TypeSpec {
|
|
|
100
100
|
* Creates a new array populated with the results of calling the provided function on every spec.
|
|
101
101
|
*
|
|
102
102
|
* @param {function(unknown): unknown} callback - Function to call on each spec
|
|
103
|
-
* @returns {Array} New array with mapped values
|
|
103
|
+
* @returns {Array<unknown>} New array with mapped values
|
|
104
104
|
*/
|
|
105
105
|
map(callback) {
|
|
106
106
|
return this.#specs.map(callback)
|
package/src/lib/Util.js
CHANGED
|
@@ -84,7 +84,7 @@ export default class Util {
|
|
|
84
84
|
* (filtered out).
|
|
85
85
|
*
|
|
86
86
|
* @param {object} object - Mapping of option strings to descriptions.
|
|
87
|
-
* @returns {string
|
|
87
|
+
* @returns {Array<string>} Array of canonical option names (long preferred, short if no long present).
|
|
88
88
|
*/
|
|
89
89
|
static generateOptionNames(object) {
|
|
90
90
|
return Object.keys(object)
|
|
@@ -103,8 +103,8 @@ export default class Util {
|
|
|
103
103
|
* Asynchronously awaits all promises in parallel.
|
|
104
104
|
* Wrapper around Promise.all for consistency with other utility methods.
|
|
105
105
|
*
|
|
106
|
-
* @param {Promise
|
|
107
|
-
* @returns {Promise<unknown
|
|
106
|
+
* @param {Array<Promise<unknown>>} promises - Array of promises to await
|
|
107
|
+
* @returns {Promise<Array<unknown>>} Results of all promises
|
|
108
108
|
*/
|
|
109
109
|
static async awaitAll(promises) {
|
|
110
110
|
return await Promise.all(promises)
|
|
@@ -114,8 +114,8 @@ export default class Util {
|
|
|
114
114
|
* Settles all promises (both fulfilled and rejected) in parallel.
|
|
115
115
|
* Wrapper around Promise.allSettled for consistency with other utility methods.
|
|
116
116
|
*
|
|
117
|
-
* @param {Promise
|
|
118
|
-
* @returns {Promise<Array
|
|
117
|
+
* @param {Array<Promise<unknown>>} promises - Array of promises to settle
|
|
118
|
+
* @returns {Promise<Array<object>>} Results of all settled promises with status and value/reason
|
|
119
119
|
*/
|
|
120
120
|
static async settleAll(promises) {
|
|
121
121
|
return await Promise.allSettled(promises)
|
|
@@ -125,7 +125,7 @@ export default class Util {
|
|
|
125
125
|
* Returns the first promise to resolve or reject from an array of promises.
|
|
126
126
|
* Wrapper around Promise.race for consistency with other utility methods.
|
|
127
127
|
*
|
|
128
|
-
* @param {Promise
|
|
128
|
+
* @param {Array<Promise<unknown>>} promises - Array of promises to race
|
|
129
129
|
* @returns {Promise<unknown>} Result of the first settled promise
|
|
130
130
|
*/
|
|
131
131
|
static async race(promises) {
|
package/src/types/Cache.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
// Implementation: ../lib/Cache.js
|
|
2
|
+
import FileObject from './FileObject.js'
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* File system cache for theme compilation data with automatic invalidation.
|
|
@@ -26,4 +27,4 @@ declare class Cache {
|
|
|
26
27
|
loadCachedData(fileObject: FileObject): Promise<object>
|
|
27
28
|
}
|
|
28
29
|
|
|
29
|
-
export default Cache
|
|
30
|
+
export default Cache
|
package/src/types/Data.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// Implementation: ../lib/Data.js
|
|
1
2
|
// Type definitions for Data utilities
|
|
2
3
|
|
|
3
4
|
import Type from './Type.js'
|
|
@@ -7,16 +8,16 @@ import Type from './Type.js'
|
|
|
7
8
|
*/
|
|
8
9
|
export default class Data {
|
|
9
10
|
/** Array of JavaScript primitive type names */
|
|
10
|
-
static readonly primitives:
|
|
11
|
+
static readonly primitives: ReadonlyArray<string>
|
|
11
12
|
|
|
12
13
|
/** Array of JavaScript constructor names for built-in objects */
|
|
13
|
-
static readonly constructors:
|
|
14
|
+
static readonly constructors: ReadonlyArray<string>
|
|
14
15
|
|
|
15
16
|
/** Combined array of all supported data types */
|
|
16
|
-
static readonly dataTypes:
|
|
17
|
+
static readonly dataTypes: ReadonlyArray<string>
|
|
17
18
|
|
|
18
19
|
/** Array of type names that can be checked for emptiness */
|
|
19
|
-
static readonly emptyableTypes:
|
|
20
|
+
static readonly emptyableTypes: ReadonlyArray<string>
|
|
20
21
|
|
|
21
22
|
/** Append a string if it doesn't already end with it */
|
|
22
23
|
static appendString(string: string, append: string): string
|
|
@@ -25,25 +26,25 @@ export default class Data {
|
|
|
25
26
|
static prependString(string: string, prepend: string): string
|
|
26
27
|
|
|
27
28
|
/** Check if all elements in an array are of a specified type */
|
|
28
|
-
static isArrayUniform(arr: unknown
|
|
29
|
+
static isArrayUniform(arr: Array<unknown>, type?: string): boolean
|
|
29
30
|
|
|
30
31
|
/** Remove duplicates from an array */
|
|
31
|
-
static isArrayUnique<T>(arr: T
|
|
32
|
+
static isArrayUnique<T>(arr: Array<T>): Array<T>
|
|
32
33
|
|
|
33
34
|
/** Get the intersection of two arrays */
|
|
34
|
-
static arrayIntersection<T>(arr1: T
|
|
35
|
+
static arrayIntersection<T>(arr1: Array<T>, arr2: Array<T>): Array<T>
|
|
35
36
|
|
|
36
37
|
/** Check if two arrays have any elements in common */
|
|
37
|
-
static arrayIntersects<T>(arr1: T
|
|
38
|
+
static arrayIntersects<T>(arr1: Array<T>, arr2: Array<T>): boolean
|
|
38
39
|
|
|
39
40
|
/** Pad an array to a specified length */
|
|
40
|
-
static arrayPad<T>(arr: T
|
|
41
|
+
static arrayPad<T>(arr: Array<T>, length: number, value: T, position?: number): Array<T>
|
|
41
42
|
|
|
42
43
|
/** Clone an object */
|
|
43
44
|
static cloneObject<T extends Record<string, any>>(obj: T, freeze?: boolean): T
|
|
44
45
|
|
|
45
46
|
/** Allocate an object from a source array and spec */
|
|
46
|
-
static allocateObject(source: unknown
|
|
47
|
+
static allocateObject(source: Array<unknown>, spec: Array<unknown> | ((source: Array<unknown>) => Promise<Array<unknown>> | Array<unknown>)): Promise<Record<string, unknown>>
|
|
47
48
|
|
|
48
49
|
/** Map an object using a transformer function */
|
|
49
50
|
static mapObject<T extends Record<string, any>, R>(
|
|
@@ -80,17 +81,17 @@ export default class Data {
|
|
|
80
81
|
static deepFreezeObject<T>(obj: T): T
|
|
81
82
|
|
|
82
83
|
/** Ensure a nested path of objects exists */
|
|
83
|
-
static assureObjectPath(obj: Record<string, any>, keys: string
|
|
84
|
+
static assureObjectPath(obj: Record<string, any>, keys: Array<string>): Record<string, any>
|
|
84
85
|
|
|
85
86
|
/** Set a value in a nested object structure */
|
|
86
|
-
static setNestedValue(obj: Record<string, any>, keys: string
|
|
87
|
+
static setNestedValue(obj: Record<string, any>, keys: Array<string>, value: unknown): void
|
|
87
88
|
|
|
88
89
|
/** Deeply merge objects */
|
|
89
|
-
static mergeObject<T extends Record<string, any>>(...sources: T
|
|
90
|
+
static mergeObject<T extends Record<string, any>>(...sources: Array<T>): T
|
|
90
91
|
|
|
91
92
|
/** Check if all elements in an array are strings */
|
|
92
|
-
static uniformStringArray(arr: unknown
|
|
93
|
+
static uniformStringArray(arr: Array<unknown>): arr is Array<string>
|
|
93
94
|
|
|
94
95
|
/** Filter an array asynchronously */
|
|
95
|
-
static asyncFilter<T>(arr: T
|
|
96
|
+
static asyncFilter<T>(arr: Array<T>, predicate: (item: T) => Promise<boolean>): Promise<Array<T>>
|
|
96
97
|
}
|
package/src/types/File.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// Implementation: ../lib/File.js
|
|
1
2
|
// Type definitions for File utilities
|
|
2
3
|
|
|
3
4
|
import FileObject from './FileObject.js'
|
|
@@ -14,9 +15,9 @@ export interface FileParts {
|
|
|
14
15
|
|
|
15
16
|
export interface DirectoryListing {
|
|
16
17
|
/** Array of FileObject instances */
|
|
17
|
-
files: FileObject
|
|
18
|
+
files: Array<FileObject>
|
|
18
19
|
/** Array of DirectoryObject instances */
|
|
19
|
-
directories: DirectoryObject
|
|
20
|
+
directories: Array<DirectoryObject>
|
|
20
21
|
}
|
|
21
22
|
|
|
22
23
|
/**
|
|
@@ -54,7 +55,7 @@ export default class File {
|
|
|
54
55
|
static deconstructFilenameToParts(fileName: string): FileParts
|
|
55
56
|
|
|
56
57
|
/** Retrieve files matching glob pattern(s) */
|
|
57
|
-
static getFiles(glob: string | string
|
|
58
|
+
static getFiles(glob: string | Array<string>): Promise<Array<FileObject>>
|
|
58
59
|
|
|
59
60
|
/** List the contents of a directory */
|
|
60
61
|
static ls(directory: string): Promise<DirectoryListing>
|
package/src/types/Sass.d.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
+
// Implementation: ../lib/Sass.js
|
|
1
2
|
// Type definitions for Sass error class
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Custom error class for toolkit errors.
|
|
5
6
|
*/
|
|
6
7
|
export default class Sass extends Error {
|
|
7
|
-
constructor(message: string, ...arg: any
|
|
8
|
+
constructor(message: string, ...arg: Array<any>)
|
|
8
9
|
|
|
9
10
|
/** Array of trace messages */
|
|
10
|
-
readonly trace: string
|
|
11
|
+
readonly trace: Array<string>
|
|
11
12
|
|
|
12
13
|
/** Add a trace message and return this instance for chaining */
|
|
13
14
|
addTrace(message: string): this
|
package/src/types/Term.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
+
// Implementation: ../lib/Term.js
|
|
1
2
|
// Type definitions for Term utility class
|
|
2
3
|
|
|
3
4
|
export default class Term {
|
|
4
|
-
static log(...arg: unknown
|
|
5
|
-
static info(...arg: unknown
|
|
6
|
-
static warn(...arg: unknown
|
|
7
|
-
static error(...arg: unknown
|
|
8
|
-
static debug(...arg: unknown
|
|
5
|
+
static log(...arg: Array<unknown>): void
|
|
6
|
+
static info(...arg: Array<unknown>): void
|
|
7
|
+
static warn(...arg: Array<unknown>): void
|
|
8
|
+
static error(...arg: Array<unknown>): void
|
|
9
|
+
static debug(...arg: Array<unknown>): void
|
|
9
10
|
static status(args: string | Array<string | [string, string]>, options?: { silent?: boolean }): void
|
|
10
11
|
static terminalMessage(argList: string | Array<string | [string, string] | [string, string, string]>): string
|
|
11
12
|
static terminalBracket(parts: [string, string, [string, string]?]): string
|
package/src/types/Type.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// Implementation: ../lib/Type.js
|
|
1
2
|
// Type definitions for Type specification class
|
|
2
3
|
|
|
3
4
|
interface TypeSpecDefinition {
|
|
@@ -8,17 +9,17 @@ interface TypeSpecDefinition {
|
|
|
8
9
|
export default class TypeSpec {
|
|
9
10
|
constructor(string: string, options?: { delimiter?: string })
|
|
10
11
|
|
|
11
|
-
readonly specs:
|
|
12
|
+
readonly specs: ReadonlyArray<TypeSpecDefinition>
|
|
12
13
|
readonly length: number
|
|
13
14
|
readonly stringRepresentation: string
|
|
14
15
|
|
|
15
16
|
toString(): string
|
|
16
|
-
toJSON(): { specs: TypeSpecDefinition
|
|
17
|
+
toJSON(): { specs: Array<TypeSpecDefinition>, length: number, stringRepresentation: string }
|
|
17
18
|
forEach(callback: (spec: TypeSpecDefinition) => void): void
|
|
18
19
|
every(callback: (spec: TypeSpecDefinition) => boolean): boolean
|
|
19
20
|
some(callback: (spec: TypeSpecDefinition) => boolean): boolean
|
|
20
|
-
filter(callback: (spec: TypeSpecDefinition) => boolean): TypeSpecDefinition
|
|
21
|
-
map<T>(callback: (spec: TypeSpecDefinition) => T): T
|
|
21
|
+
filter(callback: (spec: TypeSpecDefinition) => boolean): Array<TypeSpecDefinition>
|
|
22
|
+
map<T>(callback: (spec: TypeSpecDefinition) => T): Array<T>
|
|
22
23
|
reduce<T>(callback: (acc: T, spec: TypeSpecDefinition) => T, initialValue: T): T
|
|
23
24
|
find(callback: (spec: TypeSpecDefinition) => boolean): TypeSpecDefinition | undefined
|
|
24
25
|
match(value: unknown, options?: { allowEmpty?: boolean }): boolean
|
package/src/types/Util.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
// Implementation: ../lib/Util.js
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Utility class providing common helper functions for string manipulation,
|
|
3
5
|
* timing, hashing, and option parsing.
|
|
@@ -51,7 +53,7 @@ declare class Util {
|
|
|
51
53
|
* @param object - Mapping of option strings to descriptions.
|
|
52
54
|
* @returns Array of canonical option names (long preferred, short if no long present).
|
|
53
55
|
*/
|
|
54
|
-
static generateOptionNames(object: Record<string, any>): string
|
|
56
|
+
static generateOptionNames(object: Record<string, any>): Array<string>
|
|
55
57
|
|
|
56
58
|
/**
|
|
57
59
|
* Asynchronously awaits all promises in parallel.
|
|
@@ -60,7 +62,7 @@ declare class Util {
|
|
|
60
62
|
* @param promises - Array of promises to await
|
|
61
63
|
* @returns Results of all promises
|
|
62
64
|
*/
|
|
63
|
-
static awaitAll<T>(promises: Promise<T
|
|
65
|
+
static awaitAll<T>(promises: Array<Promise<T>>): Promise<Array<T>>
|
|
64
66
|
|
|
65
67
|
/**
|
|
66
68
|
* Settles all promises (both fulfilled and rejected) in parallel.
|
|
@@ -69,7 +71,7 @@ declare class Util {
|
|
|
69
71
|
* @param promises - Array of promises to settle
|
|
70
72
|
* @returns Results of all settled promises with status and value/reason
|
|
71
73
|
*/
|
|
72
|
-
static settleAll<T>(promises: Promise<T
|
|
74
|
+
static settleAll<T>(promises: Array<Promise<T>>): Promise<Array<PromiseSettledResult<T>>>
|
|
73
75
|
|
|
74
76
|
/**
|
|
75
77
|
* Returns the first promise to resolve or reject from an array of promises.
|
|
@@ -78,7 +80,7 @@ declare class Util {
|
|
|
78
80
|
* @param promises - Array of promises to race
|
|
79
81
|
* @returns Result of the first settled promise
|
|
80
82
|
*/
|
|
81
|
-
static race<T>(promises: Promise<T
|
|
83
|
+
static race<T>(promises: Array<Promise<T>>): Promise<T>
|
|
82
84
|
}
|
|
83
85
|
|
|
84
86
|
export default Util
|
package/src/types/Valid.d.ts
CHANGED
package/src/types/index.d.ts
CHANGED