@bsb/base 9.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/LICENSE +665 -0
- package/LICENSE.commercial +32 -0
- package/README.md +263 -0
- package/bsb-plugin.json +62 -0
- package/lib/base/BSBConfig.d.ts +130 -0
- package/lib/base/BSBConfig.js +95 -0
- package/lib/base/BSBConfig.js.map +1 -0
- package/lib/base/BSBEvents.d.ts +207 -0
- package/lib/base/BSBEvents.js +101 -0
- package/lib/base/BSBEvents.js.map +1 -0
- package/lib/base/BSBObservable.d.ts +178 -0
- package/lib/base/BSBObservable.js +91 -0
- package/lib/base/BSBObservable.js.map +1 -0
- package/lib/base/BSBService.d.ts +277 -0
- package/lib/base/BSBService.js +366 -0
- package/lib/base/BSBService.js.map +1 -0
- package/lib/base/BSBServiceClient.d.ts +135 -0
- package/lib/base/BSBServiceClient.js +130 -0
- package/lib/base/BSBServiceClient.js.map +1 -0
- package/lib/base/EventValidator.d.ts +137 -0
- package/lib/base/EventValidator.js +210 -0
- package/lib/base/EventValidator.js.map +1 -0
- package/lib/base/ObservableBackend.d.ts +281 -0
- package/lib/base/ObservableBackend.js +515 -0
- package/lib/base/ObservableBackend.js.map +1 -0
- package/lib/base/PluginConfig.d.ts +196 -0
- package/lib/base/PluginConfig.js +96 -0
- package/lib/base/PluginConfig.js.map +1 -0
- package/lib/base/PluginEvents.d.ts +140 -0
- package/lib/base/PluginEvents.js +268 -0
- package/lib/base/PluginEvents.js.map +1 -0
- package/lib/base/PluginObservable.d.ts +196 -0
- package/lib/base/PluginObservable.js +250 -0
- package/lib/base/PluginObservable.js.map +1 -0
- package/lib/base/ResourceContext.d.ts +70 -0
- package/lib/base/ResourceContext.js +54 -0
- package/lib/base/ResourceContext.js.map +1 -0
- package/lib/base/base.d.ts +264 -0
- package/lib/base/base.js +182 -0
- package/lib/base/base.js.map +1 -0
- package/lib/base/errorMessages.d.ts +56 -0
- package/lib/base/errorMessages.js +70 -0
- package/lib/base/errorMessages.js.map +1 -0
- package/lib/base/factory.d.ts +58 -0
- package/lib/base/factory.js +167 -0
- package/lib/base/factory.js.map +1 -0
- package/lib/base/functions.d.ts +117 -0
- package/lib/base/functions.js +152 -0
- package/lib/base/functions.js.map +1 -0
- package/lib/base/index.d.ts +44 -0
- package/lib/base/index.js +64 -0
- package/lib/base/index.js.map +1 -0
- package/lib/base/logFormatter.d.ts +50 -0
- package/lib/base/logFormatter.js +105 -0
- package/lib/base/logFormatter.js.map +1 -0
- package/lib/base/tools.d.ts +316 -0
- package/lib/base/tools.js +666 -0
- package/lib/base/tools.js.map +1 -0
- package/lib/cli.d.ts +28 -0
- package/lib/cli.js +254 -0
- package/lib/cli.js.map +1 -0
- package/lib/dev.d.ts +27 -0
- package/lib/dev.js +200 -0
- package/lib/dev.js.map +1 -0
- package/lib/index.d.ts +32 -0
- package/lib/index.js +49 -0
- package/lib/index.js.map +1 -0
- package/lib/interfaces/events.d.ts +67 -0
- package/lib/interfaces/events.js +44 -0
- package/lib/interfaces/events.js.map +1 -0
- package/lib/interfaces/index.d.ts +38 -0
- package/lib/interfaces/index.js +59 -0
- package/lib/interfaces/index.js.map +1 -0
- package/lib/interfaces/logging.d.ts +106 -0
- package/lib/interfaces/logging.js +39 -0
- package/lib/interfaces/logging.js.map +1 -0
- package/lib/interfaces/metrics.d.ts +365 -0
- package/lib/interfaces/metrics.js +46 -0
- package/lib/interfaces/metrics.js.map +1 -0
- package/lib/interfaces/observable-types.d.ts +63 -0
- package/lib/interfaces/observable-types.js +49 -0
- package/lib/interfaces/observable-types.js.map +1 -0
- package/lib/interfaces/observable.d.ts +297 -0
- package/lib/interfaces/observable.js +29 -0
- package/lib/interfaces/observable.js.map +1 -0
- package/lib/interfaces/options.d.ts +164 -0
- package/lib/interfaces/options.js +56 -0
- package/lib/interfaces/options.js.map +1 -0
- package/lib/interfaces/plugins.d.ts +143 -0
- package/lib/interfaces/plugins.js +45 -0
- package/lib/interfaces/plugins.js.map +1 -0
- package/lib/interfaces/result.d.ts +129 -0
- package/lib/interfaces/result.js +162 -0
- package/lib/interfaces/result.js.map +1 -0
- package/lib/interfaces/schema-events.d.ts +378 -0
- package/lib/interfaces/schema-events.js +247 -0
- package/lib/interfaces/schema-events.js.map +1 -0
- package/lib/interfaces/schema-types.d.ts +407 -0
- package/lib/interfaces/schema-types.js +581 -0
- package/lib/interfaces/schema-types.js.map +1 -0
- package/lib/interfaces/service.d.ts +48 -0
- package/lib/interfaces/service.js +29 -0
- package/lib/interfaces/service.js.map +1 -0
- package/lib/interfaces/tools.d.ts +65 -0
- package/lib/interfaces/tools.js +50 -0
- package/lib/interfaces/tools.js.map +1 -0
- package/lib/plugins/config-default/index.d.ts +59 -0
- package/lib/plugins/config-default/index.js +197 -0
- package/lib/plugins/config-default/index.js.map +1 -0
- package/lib/plugins/config-default/interfaces.d.ts +92 -0
- package/lib/plugins/config-default/interfaces.js +36 -0
- package/lib/plugins/config-default/interfaces.js.map +1 -0
- package/lib/plugins/events-default/events/broadcast.d.ts +36 -0
- package/lib/plugins/events-default/events/broadcast.js +85 -0
- package/lib/plugins/events-default/events/broadcast.js.map +1 -0
- package/lib/plugins/events-default/events/emit.d.ts +38 -0
- package/lib/plugins/events-default/events/emit.js +104 -0
- package/lib/plugins/events-default/events/emit.js.map +1 -0
- package/lib/plugins/events-default/events/emitAndReturn.d.ts +36 -0
- package/lib/plugins/events-default/events/emitAndReturn.js +100 -0
- package/lib/plugins/events-default/events/emitAndReturn.js.map +1 -0
- package/lib/plugins/events-default/events/emitStreamAndReceiveStream.d.ts +38 -0
- package/lib/plugins/events-default/events/emitStreamAndReceiveStream.js +134 -0
- package/lib/plugins/events-default/events/emitStreamAndReceiveStream.js.map +1 -0
- package/lib/plugins/events-default/events/index.d.ts +30 -0
- package/lib/plugins/events-default/events/index.js +38 -0
- package/lib/plugins/events-default/events/index.js.map +1 -0
- package/lib/plugins/events-default/index.d.ts +57 -0
- package/lib/plugins/events-default/index.js +86 -0
- package/lib/plugins/events-default/index.js.map +1 -0
- package/lib/plugins/observable-default/index.d.ts +43 -0
- package/lib/plugins/observable-default/index.js +151 -0
- package/lib/plugins/observable-default/index.js.map +1 -0
- package/lib/schemas/config-default.json +34 -0
- package/lib/schemas/config-default.plugin.json +36 -0
- package/lib/schemas/events-default.json +18 -0
- package/lib/schemas/events-default.plugin.json +17 -0
- package/lib/schemas/observable-default.json +33 -0
- package/lib/schemas/observable-default.plugin.json +24 -0
- package/lib/scripts/bsb-client-cli.d.ts +21 -0
- package/lib/scripts/bsb-client-cli.js +701 -0
- package/lib/scripts/bsb-client-cli.js.map +1 -0
- package/lib/scripts/bsb-plugin-cli.d.ts +15 -0
- package/lib/scripts/bsb-plugin-cli.js +547 -0
- package/lib/scripts/bsb-plugin-cli.js.map +1 -0
- package/lib/scripts/export-schemas.d.ts +17 -0
- package/lib/scripts/export-schemas.js +205 -0
- package/lib/scripts/export-schemas.js.map +1 -0
- package/lib/scripts/extract-schemas-from-source.d.ts +23 -0
- package/lib/scripts/extract-schemas-from-source.js +604 -0
- package/lib/scripts/extract-schemas-from-source.js.map +1 -0
- package/lib/scripts/generate-client-types.d.ts +22 -0
- package/lib/scripts/generate-client-types.js +537 -0
- package/lib/scripts/generate-client-types.js.map +1 -0
- package/lib/scripts/generate-plugin-json.d.ts +17 -0
- package/lib/scripts/generate-plugin-json.js +219 -0
- package/lib/scripts/generate-plugin-json.js.map +1 -0
- package/lib/serviceBase/config.d.ts +83 -0
- package/lib/serviceBase/config.js +236 -0
- package/lib/serviceBase/config.js.map +1 -0
- package/lib/serviceBase/events.d.ts +91 -0
- package/lib/serviceBase/events.js +519 -0
- package/lib/serviceBase/events.js.map +1 -0
- package/lib/serviceBase/index.d.ts +33 -0
- package/lib/serviceBase/index.js +50 -0
- package/lib/serviceBase/index.js.map +1 -0
- package/lib/serviceBase/observable.d.ts +249 -0
- package/lib/serviceBase/observable.js +551 -0
- package/lib/serviceBase/observable.js.map +1 -0
- package/lib/serviceBase/plugins.d.ts +48 -0
- package/lib/serviceBase/plugins.js +184 -0
- package/lib/serviceBase/plugins.js.map +1 -0
- package/lib/serviceBase/serviceBase.d.ts +228 -0
- package/lib/serviceBase/serviceBase.js +420 -0
- package/lib/serviceBase/serviceBase.js.map +1 -0
- package/lib/serviceBase/services.d.ts +63 -0
- package/lib/serviceBase/services.js +346 -0
- package/lib/serviceBase/services.js.map +1 -0
- package/lib/tests.d.ts +27 -0
- package/lib/tests.js +44 -0
- package/lib/tests.js.map +1 -0
- package/package.json +91 -0
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
import { CleanStringStrength, MergeObjectsKey, SimpleStatu } from "../interfaces";
|
|
2
|
+
/**
|
|
3
|
+
* Just a bunch of utility functions - some are used within the framework, others are just general purpose.
|
|
4
|
+
* You can use any of these functions instead of writing your own or importing from an additional library.
|
|
5
|
+
*
|
|
6
|
+
* This class only has static methods, so don't going creating instances of it.
|
|
7
|
+
*
|
|
8
|
+
* If you want to use it, like for isNullOrUndefined, you can just call it directly on the class: `Tools.isNullOrUndefined(value)`.
|
|
9
|
+
* @category Tools
|
|
10
|
+
* @see {@link https://bsbcode.dev/languages/nodejs/types/classes/Tools.html | API: Tools}
|
|
11
|
+
*/
|
|
12
|
+
export declare class Tools {
|
|
13
|
+
/**
|
|
14
|
+
* @hidden
|
|
15
|
+
*/
|
|
16
|
+
constructor();
|
|
17
|
+
/**
|
|
18
|
+
* Predefined regular expressions for common string cleaning operations.
|
|
19
|
+
* @see {@link https://bsbcode.dev/languages/nodejs/types/classes/Tools.html#regexes | API: Tools#regexes}
|
|
20
|
+
*/
|
|
21
|
+
static readonly regexes: {
|
|
22
|
+
exhard: RegExp;
|
|
23
|
+
hard: RegExp;
|
|
24
|
+
soft: RegExp;
|
|
25
|
+
url: RegExp;
|
|
26
|
+
ip: RegExp;
|
|
27
|
+
email: RegExp;
|
|
28
|
+
};
|
|
29
|
+
static cleanString(objectToClean: any): string;
|
|
30
|
+
static cleanString(objectToClean: any, maxLimit: number): string;
|
|
31
|
+
static cleanString(objectToClean: any, maxLimit: number, strength: RegExp): string;
|
|
32
|
+
static cleanString(objectToClean: any, maxLimit: number, strength: CleanStringStrength): string;
|
|
33
|
+
static cleanString(objectToClean: any, maxLimit: number, strength: RegExp, returnNullAndUndefined: true): undefined | null | string;
|
|
34
|
+
static cleanString(objectToClean: any, maxLimit: number, strength: RegExp, returnNullAndUndefined: false): string;
|
|
35
|
+
static cleanString(objectToClean: any, maxLimit: number, strength: CleanStringStrength, returnNullAndUndefined: true): undefined | null | string;
|
|
36
|
+
static cleanString(objectToClean: any, maxLimit: number, strength: CleanStringStrength, returnNullAndUndefined: false): string;
|
|
37
|
+
static cleanString(objectToClean: any, maxLimit: number, strength: CleanStringStrength.custom, returnNullAndUndefined: true, customRegex: RegExp): undefined | null | string;
|
|
38
|
+
static cleanString(objectToClean: any, maxLimit: number, strength: CleanStringStrength.custom, returnNullAndUndefined: false, customRegex: RegExp): string;
|
|
39
|
+
/**
|
|
40
|
+
* Automatically capitalize the first letter of each word in a string.
|
|
41
|
+
* @param data - The string to capitalize
|
|
42
|
+
* @returns The string with each word capitalized
|
|
43
|
+
* @see {@link https://bsbcode.dev/languages/nodejs/types/classes/Tools.html#autoCapitalizeWords | API: Tools#autoCapitalizeWords}
|
|
44
|
+
*/
|
|
45
|
+
static autoCapitalizeWords(data: string): string;
|
|
46
|
+
/**
|
|
47
|
+
* Get the string keys from an enum object, filtering out numeric keys.
|
|
48
|
+
* @param obj - The enum object
|
|
49
|
+
* @returns Array of string keys
|
|
50
|
+
* @see {@link https://bsbcode.dev/languages/nodejs/types/classes/Tools.html#enumKeys | API: Tools#enumKeys}
|
|
51
|
+
*/
|
|
52
|
+
static enumKeys<O extends object, K extends keyof O = keyof O>(obj: O): K[];
|
|
53
|
+
/**
|
|
54
|
+
* @hidden
|
|
55
|
+
*/
|
|
56
|
+
private static _flattenObject;
|
|
57
|
+
/**
|
|
58
|
+
* Flatten a nested object into a single level with dot notation keys.
|
|
59
|
+
* @param obj - The object to flatten
|
|
60
|
+
* @returns The flattened object
|
|
61
|
+
* @throws Error if the input is not a valid object
|
|
62
|
+
* @see {@link https://bsbcode.dev/languages/nodejs/types/classes/Tools.html#flattenObject | API: Tools#flattenObject}
|
|
63
|
+
*/
|
|
64
|
+
static flattenObject<T = unknown, TR = object>(obj: T): TR;
|
|
65
|
+
/**
|
|
66
|
+
* Get hierarchical availability of objects based on key-parent relationships.
|
|
67
|
+
* @param listOfObjects - Array of objects to search through
|
|
68
|
+
* @param key - The key property name
|
|
69
|
+
* @param parentkey - The parent key property name
|
|
70
|
+
* @param value - The value to match against
|
|
71
|
+
* @returns Array of matching objects including hierarchical children
|
|
72
|
+
* @see {@link https://bsbcode.dev/languages/nodejs/types/classes/Tools.html#hierachialGetAvailibility | API: Tools#hierachialGetAvailibility}
|
|
73
|
+
*/
|
|
74
|
+
static hierachialGetAvailibility<T>(listOfObjects: Array<T>, key: string, parentkey: string, value: T): Array<T>;
|
|
75
|
+
/**
|
|
76
|
+
* Decode a base64 data URL string and extract the image type and data.
|
|
77
|
+
* @param dataString - Base64 data URL string (e.g., "data:image/png;base64,...")
|
|
78
|
+
* @returns Object with type and data properties, or Error if invalid
|
|
79
|
+
* @see {@link https://bsbcode.dev/languages/nodejs/types/classes/Tools.html#decodeBase64Image | API: Tools#decodeBase64Image}
|
|
80
|
+
*/
|
|
81
|
+
static decodeBase64Image(dataString: string): any;
|
|
82
|
+
private static GetValueFromObjectBasedOnStringPathSearcher;
|
|
83
|
+
/**
|
|
84
|
+
* Get a value from a nested object using a string path (e.g., "user.profile.name").
|
|
85
|
+
* Supports comma-separated paths for concatenation and "*" wildcard for all properties.
|
|
86
|
+
* @param workingObj - The object to search in
|
|
87
|
+
* @param stringToGet - Dot-notation path string or comma-separated paths
|
|
88
|
+
* @returns The value at the specified path, or null if not found
|
|
89
|
+
* @see {@link https://bsbcode.dev/languages/nodejs/types/classes/Tools.html#GetValueFromObjectBasedOnStringPath | API: Tools#GetValueFromObjectBasedOnStringPath}
|
|
90
|
+
*/
|
|
91
|
+
static GetValueFromObjectBasedOnStringPath(workingObj: any, stringToGet: string): any;
|
|
92
|
+
/**
|
|
93
|
+
* Merge two objects deeply, with the second object taking precedence.
|
|
94
|
+
* @param src - Source object to merge into
|
|
95
|
+
* @param against - Object to merge from (takes precedence)
|
|
96
|
+
* @param initialMigration - Whether to clone objects before merging (default: true)
|
|
97
|
+
* @param referenceKey - Optional reference key for merge operations
|
|
98
|
+
* @returns The merged object
|
|
99
|
+
* @see {@link https://bsbcode.dev/languages/nodejs/types/classes/Tools.html#mergeObjects | API: Tools#mergeObjects}
|
|
100
|
+
*/
|
|
101
|
+
static mergeObjects(src: any, against: any, initialMigration?: boolean, referenceKey?: MergeObjectsKey): any;
|
|
102
|
+
/**
|
|
103
|
+
* Replace placeholders in a string with values from an object using {key} syntax.
|
|
104
|
+
* @param obj - Object containing replacement values
|
|
105
|
+
* @param str - String with placeholders (e.g., "Hello {name}")
|
|
106
|
+
* @returns String with placeholders replaced by object values
|
|
107
|
+
* @see {@link https://bsbcode.dev/languages/nodejs/types/classes/Tools.html#StringReplaceWithObject | API: Tools#StringReplaceWithObject}
|
|
108
|
+
*/
|
|
109
|
+
static StringReplaceWithObject(obj: any, str: string): string;
|
|
110
|
+
/**
|
|
111
|
+
* Convert milliseconds to a human-readable time string.
|
|
112
|
+
* @param time - Time in milliseconds
|
|
113
|
+
* @returns Human-readable time string (e.g., "5 minutes", "2 hours")
|
|
114
|
+
* @see {@link https://bsbcode.dev/languages/nodejs/types/classes/Tools.html#getTimeFromMilliseconds | API: Tools#getTimeFromMilliseconds}
|
|
115
|
+
*/
|
|
116
|
+
static getTimeFromMilliseconds(time: number): string;
|
|
117
|
+
/**
|
|
118
|
+
* Create a delay/sleep for the specified number of milliseconds.
|
|
119
|
+
* @param time - Time to delay in milliseconds (default: 1000)
|
|
120
|
+
* @returns Promise that resolves after the specified time
|
|
121
|
+
* @see {@link https://bsbcode.dev/languages/nodejs/types/classes/Tools.html#delay | API: Tools#delay}
|
|
122
|
+
*/
|
|
123
|
+
static delay(time?: number): Promise<void>;
|
|
124
|
+
/**
|
|
125
|
+
* Wait with delays while checking a condition, throwing an error on timeout.
|
|
126
|
+
* @param checkFunc - Function that returns true while waiting should continue
|
|
127
|
+
* @param rejectFunc - Function to call on timeout (before throwing)
|
|
128
|
+
* @param time - Delay between checks in milliseconds (default: 1000)
|
|
129
|
+
* @param timeout - Maximum number of check attempts (default: 10)
|
|
130
|
+
* @throws "Timeout!" when the timeout is exceeded
|
|
131
|
+
* @see {@link https://bsbcode.dev/languages/nodejs/types/classes/Tools.html#waitDelayThenThrow | API: Tools#waitDelayThenThrow}
|
|
132
|
+
*/
|
|
133
|
+
static waitDelayThenThrow(checkFunc: Function, rejectFunc: Function, time?: number, timeout?: number): Promise<void>;
|
|
134
|
+
/**
|
|
135
|
+
* Check if a value is a simple primitive type (string, number, or boolean).
|
|
136
|
+
* @param value - The value to check
|
|
137
|
+
* @returns True if the value is a string, number, or boolean
|
|
138
|
+
* @see {@link https://bsbcode.dev/languages/nodejs/types/classes/Tools.html#isSimpleType | API: Tools#isSimpleType}
|
|
139
|
+
*/
|
|
140
|
+
static isSimpleType(value: unknown): boolean;
|
|
141
|
+
/**
|
|
142
|
+
* Type guard to check if a value is a string.
|
|
143
|
+
* @param value - The value to check
|
|
144
|
+
* @returns True if the value is a string
|
|
145
|
+
* @see {@link https://bsbcode.dev/languages/nodejs/types/classes/Tools.html#isString | API: Tools#isString}
|
|
146
|
+
*/
|
|
147
|
+
static isString(value: unknown): value is string;
|
|
148
|
+
/**
|
|
149
|
+
* Type guard to check if a value is a Date object.
|
|
150
|
+
* @param value - The value to check
|
|
151
|
+
* @param matchString - Currently unused parameter for potential string date matching
|
|
152
|
+
* @returns True if the value is a Date instance
|
|
153
|
+
* @see {@link https://bsbcode.dev/languages/nodejs/types/classes/Tools.html#isDate | API: Tools#isDate}
|
|
154
|
+
*/
|
|
155
|
+
static isDate(value: unknown, matchString?: boolean): value is Date;
|
|
156
|
+
/**
|
|
157
|
+
* Type guard to check if a value is an array.
|
|
158
|
+
* @param value - The value to check
|
|
159
|
+
* @returns True if the value is an array
|
|
160
|
+
* @see {@link https://bsbcode.dev/languages/nodejs/types/classes/Tools.html#isArray | API: Tools#isArray}
|
|
161
|
+
*/
|
|
162
|
+
static isArray<T = unknown>(value: unknown): value is Array<T>;
|
|
163
|
+
/**
|
|
164
|
+
* Type guard to check if a value is a function.
|
|
165
|
+
* @param value - The value to check
|
|
166
|
+
* @returns True if the value is a function
|
|
167
|
+
* @see {@link https://bsbcode.dev/languages/nodejs/types/classes/Tools.html#isFunction | API: Tools#isFunction}
|
|
168
|
+
*/
|
|
169
|
+
static isFunction(value: any): value is Function;
|
|
170
|
+
/**
|
|
171
|
+
* Type guard to check if a value is a symbol.
|
|
172
|
+
* @param value - The value to check
|
|
173
|
+
* @returns True if the value is a symbol
|
|
174
|
+
* @see {@link https://bsbcode.dev/languages/nodejs/types/classes/Tools.html#isSymbol | API: Tools#isSymbol}
|
|
175
|
+
*/
|
|
176
|
+
static isSymbol(value: any): value is symbol;
|
|
177
|
+
/**
|
|
178
|
+
* Type guard to check if a value is a valid number (not NaN).
|
|
179
|
+
* @param value - The value to check
|
|
180
|
+
* @returns True if the value is a number and not NaN
|
|
181
|
+
* @see {@link https://bsbcode.dev/languages/nodejs/types/classes/Tools.html#isNumber | API: Tools#isNumber}
|
|
182
|
+
*/
|
|
183
|
+
static isNumber(value: any): value is number;
|
|
184
|
+
/**
|
|
185
|
+
* Check if a value can be parsed as a valid number and return the parsed result.
|
|
186
|
+
* @param value - The value to check and parse
|
|
187
|
+
* @returns Object with status (true if valid) and value (the parsed number)
|
|
188
|
+
* @see {@link https://bsbcode.dev/languages/nodejs/types/classes/Tools.html#isStringNumber | API: Tools#isStringNumber}
|
|
189
|
+
*/
|
|
190
|
+
static isStringNumber(value: any): SimpleStatu<number>;
|
|
191
|
+
/**
|
|
192
|
+
* Type guard to check if a value is a boolean.
|
|
193
|
+
* @param value - The value to check
|
|
194
|
+
* @returns True if the value is a boolean
|
|
195
|
+
* @see {@link https://bsbcode.dev/languages/nodejs/types/classes/Tools.html#isBoolean | API: Tools#isBoolean}
|
|
196
|
+
*/
|
|
197
|
+
static isBoolean(value: unknown): value is boolean;
|
|
198
|
+
/**
|
|
199
|
+
* Type guard to check if a value is undefined.
|
|
200
|
+
* @param value - The value to check
|
|
201
|
+
* @returns True if the value is undefined
|
|
202
|
+
* @see {@link https://bsbcode.dev/languages/nodejs/types/classes/Tools.html#isUndefined | API: Tools#isUndefined}
|
|
203
|
+
*/
|
|
204
|
+
static isUndefined(value: unknown): value is undefined;
|
|
205
|
+
/**
|
|
206
|
+
* Type guard to check if a value is null.
|
|
207
|
+
* @param value - The value to check
|
|
208
|
+
* @returns True if the value is null
|
|
209
|
+
* @see {@link https://bsbcode.dev/languages/nodejs/types/classes/Tools.html#isNull | API: Tools#isNull}
|
|
210
|
+
*/
|
|
211
|
+
static isNull(value: unknown): value is null;
|
|
212
|
+
/**
|
|
213
|
+
* Type guard to check if a value is a plain object (not array, null, etc.).
|
|
214
|
+
* @param value - The value to check
|
|
215
|
+
* @returns True if the value is a plain object
|
|
216
|
+
* @see {@link https://bsbcode.dev/languages/nodejs/types/classes/Tools.html#isObject | API: Tools#isObject}
|
|
217
|
+
*/
|
|
218
|
+
static isObject(value: unknown): value is Object;
|
|
219
|
+
/**
|
|
220
|
+
* Type guard to check object constructor type (array or object).
|
|
221
|
+
* @param value - The value to check
|
|
222
|
+
* @param type - The type to check for ("array" or "object")
|
|
223
|
+
* @returns True if the value matches the specified constructor type
|
|
224
|
+
* @see {@link https://bsbcode.dev/languages/nodejs/types/classes/Tools.html#TypeofObjectConstructor | API: Tools#TypeofObjectConstructor}
|
|
225
|
+
*/
|
|
226
|
+
static TypeofObjectConstructor<TR = unknown>(value: unknown, type: "array" | "object"): value is TR;
|
|
227
|
+
/**
|
|
228
|
+
* Type guard to check if a value is a plain object with string keys.
|
|
229
|
+
* @param value - The value to check
|
|
230
|
+
* @returns True if the value is a plain object
|
|
231
|
+
* @see {@link https://bsbcode.dev/languages/nodejs/types/classes/Tools.html#isPlainObject | API: Tools#isPlainObject}
|
|
232
|
+
*/
|
|
233
|
+
static isPlainObject(value: unknown): value is Record<string, any>;
|
|
234
|
+
/**
|
|
235
|
+
* Type guard to check if a value is null or undefined.
|
|
236
|
+
* @param value - The value to check
|
|
237
|
+
* @returns True if the value is null or undefined
|
|
238
|
+
* @see {@link https://bsbcode.dev/languages/nodejs/types/classes/Tools.html#isNullOrUndefined | API: Tools#isNullOrUndefined}
|
|
239
|
+
*/
|
|
240
|
+
static isNullOrUndefined(value: unknown): value is null | undefined;
|
|
241
|
+
/**
|
|
242
|
+
* Generate a random integer between min and max (inclusive).
|
|
243
|
+
* @param min - Minimum value (inclusive)
|
|
244
|
+
* @param max - Maximum value (inclusive)
|
|
245
|
+
* @returns Random integer between min and max
|
|
246
|
+
* @see {@link https://bsbcode.dev/languages/nodejs/types/classes/Tools.html#genRandomNumber | API: Tools#genRandomNumber}
|
|
247
|
+
*/
|
|
248
|
+
static genRandomNumber(min: number, max: number): number;
|
|
249
|
+
/**
|
|
250
|
+
* Clamp a number between a minimum and maximum value.
|
|
251
|
+
* @param min - Minimum allowed value
|
|
252
|
+
* @param max - Maximum allowed value
|
|
253
|
+
* @param value - Value to clamp
|
|
254
|
+
* @returns The clamped value
|
|
255
|
+
* @throws Error if min is greater than max
|
|
256
|
+
* @see {@link https://bsbcode.dev/languages/nodejs/types/classes/Tools.html#clampNumber | API: Tools#clampNumber}
|
|
257
|
+
*/
|
|
258
|
+
static clampNumber(min: number, max: number, value: number): number;
|
|
259
|
+
/**
|
|
260
|
+
* Sleep/delay execution for the specified number of milliseconds.
|
|
261
|
+
* @param milliseconds - Time to sleep in milliseconds (default: 1000)
|
|
262
|
+
* @returns Promise that resolves after the specified time
|
|
263
|
+
* @see {@link https://bsbcode.dev/languages/nodejs/types/classes/Tools.html#sleep | API: Tools#sleep}
|
|
264
|
+
*/
|
|
265
|
+
static sleep(milliseconds?: number): Promise<void>;
|
|
266
|
+
/**
|
|
267
|
+
* Collection of utility functions for working with arrays.
|
|
268
|
+
* @see {@link https://bsbcode.dev/languages/nodejs/types/classes/Tools.html#arrays | API: Tools#arrays}
|
|
269
|
+
*/
|
|
270
|
+
static arrays: {
|
|
271
|
+
/**
|
|
272
|
+
* Asynchronously map over an array with async callback functions.
|
|
273
|
+
* @param arr - The array to map over
|
|
274
|
+
* @param asyncCallback - Async function to call for each item
|
|
275
|
+
* @returns Promise resolving to the mapped array
|
|
276
|
+
* @see {@link https://bsbcode.dev/languages/nodejs/types/classes/Tools.html#arrays | API: Tools#arrays}
|
|
277
|
+
*/
|
|
278
|
+
mapAsync: <Input = any, Output = any>(arr: Array<Input>, asyncCallback: {
|
|
279
|
+
(item: Input): Promise<Output>;
|
|
280
|
+
}) => Promise<Array<Output>>;
|
|
281
|
+
/**
|
|
282
|
+
* Group array items by a key generated from a function.
|
|
283
|
+
* @param groupFunc - Function that returns a string key for grouping
|
|
284
|
+
* @param list - Array to group
|
|
285
|
+
* @returns Object with keys as group names and values as arrays of grouped items
|
|
286
|
+
* @see {@link https://bsbcode.dev/languages/nodejs/types/classes/Tools.html#arrays | API: Tools#arrays}
|
|
287
|
+
*/
|
|
288
|
+
groupListBy: <T = any>(groupFunc: {
|
|
289
|
+
(object: T): string;
|
|
290
|
+
}, list: Array<T>) => Record<string, Array<T>>;
|
|
291
|
+
/**
|
|
292
|
+
* Collect array items into groups using a grouping function, returning only the grouped arrays.
|
|
293
|
+
* @param groupFunc - Function that returns a string key for grouping
|
|
294
|
+
* @param list - Array to collect
|
|
295
|
+
* @returns Array of arrays where each sub-array contains grouped items
|
|
296
|
+
* @see {@link https://bsbcode.dev/languages/nodejs/types/classes/Tools.html#arrays | API: Tools#arrays}
|
|
297
|
+
*/
|
|
298
|
+
collectListBy: <T = any>(groupFunc: {
|
|
299
|
+
(object: T): string;
|
|
300
|
+
}, list: Array<T>) => Array<Array<T>>;
|
|
301
|
+
/**
|
|
302
|
+
* Get the first item in the array.
|
|
303
|
+
* @param list - The array to get the first item from
|
|
304
|
+
* @returns The first item or undefined if array is empty
|
|
305
|
+
* @see {@link https://bsbcode.dev/languages/nodejs/types/classes/Tools.html#arrays | API: Tools#arrays}
|
|
306
|
+
*/
|
|
307
|
+
head: <T = any>(list: Array<T>) => T | undefined;
|
|
308
|
+
/**
|
|
309
|
+
* Get the last item in the array.
|
|
310
|
+
* @param list - The array to get the last item from
|
|
311
|
+
* @returns The last item or undefined if array is empty
|
|
312
|
+
* @see {@link https://bsbcode.dev/languages/nodejs/types/classes/Tools.html#arrays | API: Tools#arrays}
|
|
313
|
+
*/
|
|
314
|
+
tail: <T = any>(list: Array<T>) => T | undefined;
|
|
315
|
+
};
|
|
316
|
+
}
|