@estjs/shared 0.0.14-beta.9 → 0.0.15-beta.1
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 +14 -0
- package/dist/shared.cjs.js +2 -0
- package/dist/shared.cjs.js.map +1 -0
- package/dist/shared.d.cts +287 -42
- package/dist/shared.d.ts +287 -42
- package/dist/shared.dev.cjs.js +395 -0
- package/dist/shared.dev.cjs.js.map +1 -0
- package/dist/shared.dev.esm.js +311 -0
- package/dist/shared.dev.esm.js.map +1 -0
- package/dist/shared.esm.js +2 -0
- package/dist/shared.esm.js.map +1 -0
- package/package.json +22 -7
- package/dist/shared.cjs +0 -224
- package/dist/shared.cjs.map +0 -1
- package/dist/shared.js +0 -165
- package/dist/shared.js.map +0 -1
package/dist/shared.d.ts
CHANGED
|
@@ -1,80 +1,325 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Reference to Object.assign
|
|
3
|
+
* @type {Function}
|
|
4
|
+
*/
|
|
2
5
|
declare const extend: {
|
|
3
6
|
<T extends {}, U>(target: T, source: U): T & U;
|
|
4
7
|
<T extends {}, U, V>(target: T, source1: U, source2: V): T & U & V;
|
|
5
8
|
<T extends {}, U, V, W>(target: T, source1: U, source2: V, source3: W): T & U & V & W;
|
|
6
9
|
(target: object, ...sources: any[]): any;
|
|
7
10
|
};
|
|
11
|
+
/**
|
|
12
|
+
* Checks if an object has a specific property
|
|
13
|
+
* @template T
|
|
14
|
+
* @param {object} val - The target object to check
|
|
15
|
+
* @param {string | symbol} key - The property name to check for
|
|
16
|
+
* @returns {key is keyof T} - Returns true if the object has the property, false otherwise
|
|
17
|
+
*/
|
|
8
18
|
declare const hasOwn: (val: object, key: string | symbol) => key is keyof typeof val;
|
|
19
|
+
/**
|
|
20
|
+
* Forces a value to be an array
|
|
21
|
+
* @template T - The type of array elements
|
|
22
|
+
* @param {T | T[]} data - The data to convert, can be a single element or an array
|
|
23
|
+
* @returns {T[]} - The resulting array
|
|
24
|
+
*/
|
|
9
25
|
declare function coerceArray<T>(data: T | T[]): T[];
|
|
10
|
-
|
|
26
|
+
/**
|
|
27
|
+
* Checks if a value has changed
|
|
28
|
+
* @param {unknown } value - The new value
|
|
29
|
+
* @param {unknown } oldValue - The old value
|
|
30
|
+
* @returns {boolean} - Returns true if the value has changed, false otherwise
|
|
31
|
+
*/
|
|
32
|
+
declare const hasChanged: (value: unknown, oldValue: unknown) => boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Empty function, used for defaults and placeholders
|
|
35
|
+
* @type {Function}
|
|
36
|
+
*/
|
|
11
37
|
declare const noop: () => void;
|
|
12
38
|
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
39
|
+
* Checks if a string starts with a specified substring
|
|
40
|
+
*
|
|
41
|
+
* Uses indexOf for better performance in most cases
|
|
15
42
|
* @see https://www.measurethat.net/Benchmarks/Show/12350/0/startswith-vs-test-vs-match-vs-indexof#latest_results_block
|
|
16
|
-
|
|
17
|
-
* @param {string}
|
|
18
|
-
* @
|
|
19
|
-
|
|
43
|
+
* @param {string} str - The string to check
|
|
44
|
+
* @param {string} searchString - The substring to search for
|
|
45
|
+
* @returns {boolean} - Returns true if the string starts with the substring, false otherwise
|
|
46
|
+
*/
|
|
47
|
+
declare function startsWith(str: string, searchString: string): boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Generates an 8-character random string as a unique identifier
|
|
50
|
+
*
|
|
51
|
+
* Note: Uses Math.random() which is not cryptographically secure.
|
|
52
|
+
* For security-sensitive use cases, consider using crypto.getRandomValues()
|
|
53
|
+
* @returns {string} - The generated unique identifier
|
|
54
|
+
*/
|
|
55
|
+
declare function generateUniqueId(): string;
|
|
56
|
+
/**
|
|
57
|
+
* Checks if the current environment is a browser
|
|
58
|
+
* @returns {boolean} - Returns true if in a browser environment, false otherwise
|
|
59
|
+
*/
|
|
60
|
+
declare function isBrowser(): boolean;
|
|
61
|
+
/**
|
|
62
|
+
* Creates a cached version of a string processing function
|
|
63
|
+
* @template T - The function type
|
|
64
|
+
* @param {T} fn - The string processing function to cache
|
|
65
|
+
* @returns {T} - The cached function
|
|
66
|
+
*/
|
|
67
|
+
declare const cacheStringFunction: <T extends (str: string) => string>(fn: T) => T;
|
|
68
|
+
/**
|
|
69
|
+
* Read-only empty object
|
|
70
|
+
* @type {Readonly<Record<string, unknown >>}
|
|
71
|
+
*/
|
|
72
|
+
declare const EMPTY_OBJ: {
|
|
73
|
+
readonly [key: string]: unknown;
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* Read-only empty array
|
|
77
|
+
* @type {readonly never[]}
|
|
78
|
+
*/
|
|
79
|
+
declare const EMPTY_ARR: readonly never[];
|
|
80
|
+
/**
|
|
81
|
+
* Checks if a property name is an event handler (starts with 'on' followed by uppercase letter)
|
|
82
|
+
*
|
|
83
|
+
* Matches patterns like: onClick, onChange, onKeyDown (but not 'onclick' or 'on123')
|
|
84
|
+
* @param {string} key - The property name to check
|
|
85
|
+
* @returns {boolean} - Returns true if the property is an event handler, false otherwise
|
|
20
86
|
*/
|
|
21
|
-
declare
|
|
87
|
+
declare const isOn: (key: string) => boolean;
|
|
22
88
|
/**
|
|
23
|
-
*
|
|
24
|
-
* @
|
|
25
|
-
* @returns The escaped string.
|
|
89
|
+
* Gets the global object for the current environment
|
|
90
|
+
* @returns {unknown } - The global object for the current environment
|
|
26
91
|
*/
|
|
27
|
-
declare
|
|
92
|
+
declare const getGlobalThis: () => unknown;
|
|
28
93
|
type ExcludeType = ((key: string | symbol) => boolean) | (string | symbol)[];
|
|
29
94
|
/**
|
|
30
|
-
* Checks if a key should be excluded
|
|
31
|
-
* @param key - The key to check
|
|
32
|
-
* @param exclude - The exclusion
|
|
33
|
-
* @returns
|
|
95
|
+
* Checks if a key should be excluded
|
|
96
|
+
* @param {string | symbol} key - The key to check
|
|
97
|
+
* @param {ExcludeType} [exclude] - The exclusion condition, can be a function or array
|
|
98
|
+
* @returns {boolean} - Returns true if the key should be excluded, false otherwise
|
|
34
99
|
*/
|
|
35
100
|
declare function isExclude(key: string | symbol, exclude?: ExcludeType): boolean;
|
|
101
|
+
|
|
36
102
|
/**
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
* @returns
|
|
103
|
+
* Checks if a value is an object
|
|
104
|
+
* @param {unknown} val - The value to check
|
|
105
|
+
* @returns {boolean} - Returns true if the value is an object, false otherwise
|
|
40
106
|
*/
|
|
41
|
-
declare
|
|
107
|
+
declare const isObject: (val: unknown) => val is Record<any, unknown>;
|
|
42
108
|
/**
|
|
43
|
-
* Checks if
|
|
44
|
-
* @
|
|
109
|
+
* Checks if a value is a Promise
|
|
110
|
+
* @template T - The type of the Promise's resolved value
|
|
111
|
+
* @param {unknown} val - The value to check
|
|
112
|
+
* @returns {boolean} - Returns true if the value is a Promise, false otherwise
|
|
113
|
+
*/
|
|
114
|
+
declare function isPromise<T = unknown>(val: unknown): val is Promise<T>;
|
|
115
|
+
/**
|
|
116
|
+
* Checks if a value is an Array
|
|
117
|
+
* @type {(arg: unknown ) => arg is unknown []}
|
|
45
118
|
*/
|
|
46
|
-
declare function isBrowser(): boolean;
|
|
47
|
-
|
|
48
|
-
declare const isObject: (val: unknown) => val is Record<any, any>;
|
|
49
|
-
declare function isPromise(val: any): val is Promise<any>;
|
|
50
119
|
declare const isArray: (arg: any) => arg is any[];
|
|
120
|
+
/**
|
|
121
|
+
* Checks if a value is a string
|
|
122
|
+
* @param {unknown} val - The value to check
|
|
123
|
+
* @returns {boolean} - Returns true if the value is a string, false otherwise
|
|
124
|
+
*/
|
|
51
125
|
declare function isString(val: unknown): val is string;
|
|
126
|
+
/**
|
|
127
|
+
* Checks if a value is a number
|
|
128
|
+
* @param {unknown} val - The value to check
|
|
129
|
+
* @returns {boolean} - Returns true if the value is a number, false otherwise
|
|
130
|
+
*/
|
|
131
|
+
declare function isNumber(val: unknown): val is number;
|
|
132
|
+
/**
|
|
133
|
+
* Checks if a value is null
|
|
134
|
+
* @param {unknown} val - The value to check
|
|
135
|
+
* @returns {boolean} - Returns true if the value is null, false otherwise
|
|
136
|
+
*/
|
|
137
|
+
declare function isNull(val: unknown): val is null;
|
|
138
|
+
/**
|
|
139
|
+
* Checks if a value is a Symbol
|
|
140
|
+
* @param {unknown} val - The value to check
|
|
141
|
+
* @returns {boolean} - Returns true if the value is a Symbol, false otherwise
|
|
142
|
+
*/
|
|
52
143
|
declare function isSymbol(val: unknown): val is symbol;
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
144
|
+
/**
|
|
145
|
+
* Checks if a value is a Set
|
|
146
|
+
* @param {unknown} val - The value to check
|
|
147
|
+
* @returns {boolean} - Returns true if the value is a Set, false otherwise
|
|
148
|
+
*/
|
|
149
|
+
declare function isSet(val: unknown): val is Set<unknown>;
|
|
150
|
+
/**
|
|
151
|
+
* Checks if a value is a WeakMap
|
|
152
|
+
* @param {unknown} val - The value to check
|
|
153
|
+
* @returns {boolean} - Returns true if the value is a WeakMap, false otherwise
|
|
154
|
+
*/
|
|
155
|
+
declare function isWeakMap(val: unknown): val is WeakMap<any, unknown>;
|
|
156
|
+
/**
|
|
157
|
+
* Checks if a value is a WeakSet
|
|
158
|
+
* @param {unknown} val - The value to check
|
|
159
|
+
* @returns {boolean} - Returns true if the value is a WeakSet, false otherwise
|
|
160
|
+
*/
|
|
161
|
+
declare function isWeakSet(val: unknown): val is WeakSet<any>;
|
|
162
|
+
/**
|
|
163
|
+
* Checks if a value is a Map
|
|
164
|
+
* @param {unknown} val - The value to check
|
|
165
|
+
* @returns {boolean} - Returns true if the value is a Map, false otherwise
|
|
166
|
+
*/
|
|
167
|
+
declare function isMap(val: unknown): val is Map<unknown, unknown>;
|
|
168
|
+
/**
|
|
169
|
+
* Checks if a value is null or undefined
|
|
170
|
+
* @param {unknown} val - The value to check
|
|
171
|
+
* @returns {boolean} - Returns true if the value is null or undefined, false otherwise
|
|
172
|
+
*/
|
|
173
|
+
declare function isNil(val: unknown): val is null | undefined;
|
|
174
|
+
/**
|
|
175
|
+
* Checks if a value is a function
|
|
176
|
+
* @param {unknown} val - The value to check
|
|
177
|
+
* @returns {boolean} - Returns true if the value is a function, false otherwise
|
|
178
|
+
*/
|
|
58
179
|
declare const isFunction: (val: unknown) => val is Function;
|
|
59
|
-
|
|
180
|
+
/**
|
|
181
|
+
* Checks if a value is falsy (false, null, or undefined)
|
|
182
|
+
* @param {unknown} val - The value to check
|
|
183
|
+
* @returns {boolean} - Returns true if the value is falsy, false otherwise
|
|
184
|
+
*/
|
|
185
|
+
declare function isFalsy(val: unknown): val is false | null | undefined;
|
|
186
|
+
/**
|
|
187
|
+
* Checks if a value is a primitive type (string, number, boolean, symbol, null, or undefined)
|
|
188
|
+
* @param {unknown} val - The value to check
|
|
189
|
+
* @returns {boolean} - Returns true if the value is a primitive type, false otherwise
|
|
190
|
+
*/
|
|
60
191
|
declare const isPrimitive: (val: unknown) => val is string | number | boolean | symbol | null | undefined;
|
|
61
|
-
|
|
192
|
+
/**
|
|
193
|
+
* Checks if a value is an HTMLElement
|
|
194
|
+
* @param {unknown} val - The value to check
|
|
195
|
+
* @returns {boolean} - Returns true if the value is an HTMLElement, false otherwise
|
|
196
|
+
*/
|
|
197
|
+
declare function isHTMLElement(val: unknown): val is HTMLElement;
|
|
198
|
+
/**
|
|
199
|
+
* Checks if a value is a plain object (created using Object constructor)
|
|
200
|
+
* @param {unknown} val - The value to check
|
|
201
|
+
* @returns {boolean} - Returns true if the value is a plain object, false otherwise
|
|
202
|
+
*/
|
|
62
203
|
declare const isPlainObject: (val: unknown) => val is object;
|
|
204
|
+
/**
|
|
205
|
+
* String representation of a number
|
|
206
|
+
* @typedef {`${number}`} StringNumber
|
|
207
|
+
*/
|
|
63
208
|
type StringNumber = `${number}`;
|
|
209
|
+
/**
|
|
210
|
+
* Checks if a value is a string representation of a number
|
|
211
|
+
* @param {unknown} val - The value to check
|
|
212
|
+
* @returns {boolean} - Returns true if the value is a string number, false otherwise
|
|
213
|
+
*/
|
|
64
214
|
declare function isStringNumber(val: unknown): val is StringNumber;
|
|
215
|
+
/**
|
|
216
|
+
* Checks if a value is undefined
|
|
217
|
+
* @param {unknown} val - The value to check
|
|
218
|
+
* @returns {boolean} - Returns true if the value is undefined, false otherwise
|
|
219
|
+
*/
|
|
220
|
+
declare function isUndefined(val: unknown): val is undefined;
|
|
221
|
+
/**
|
|
222
|
+
* Checks if a value is a boolean
|
|
223
|
+
* @param {unknown} val - The value to check
|
|
224
|
+
* @returns {boolean} - Returns true if the value is a boolean, false otherwise
|
|
225
|
+
*/
|
|
226
|
+
declare function isBoolean(val: unknown): val is boolean;
|
|
227
|
+
declare function isNaN(val: unknown): val is number;
|
|
65
228
|
|
|
229
|
+
/**
|
|
230
|
+
* Converts a camelCase string to kebab-case
|
|
231
|
+
* Example: myFunction -> my-function
|
|
232
|
+
* @param {string} str - The camelCase string to convert
|
|
233
|
+
* @returns {string} - The kebab-case string
|
|
234
|
+
*/
|
|
66
235
|
declare const kebabCase: (str: string) => string;
|
|
236
|
+
/**
|
|
237
|
+
* Converts a kebab-case or snake_case string to camelCase
|
|
238
|
+
* Example: my-function or my_function -> myFunction
|
|
239
|
+
* @param {string} str - The kebab-case or snake_case string to convert
|
|
240
|
+
* @returns {string} - The camelCase string
|
|
241
|
+
*/
|
|
67
242
|
declare const camelCase: (str: string) => string;
|
|
68
243
|
/**
|
|
69
|
-
* Capitalizes the first letter of a string
|
|
70
|
-
*
|
|
71
|
-
* @
|
|
72
|
-
* @
|
|
244
|
+
* Capitalizes the first letter of a string
|
|
245
|
+
* Example: hello -> Hello
|
|
246
|
+
* @template T - The input string type
|
|
247
|
+
* @param {T} str - The string to capitalize
|
|
248
|
+
* @returns {Capitalize<T>} - The capitalized string
|
|
73
249
|
*/
|
|
74
250
|
declare const capitalize: <T extends string>(str: T) => Capitalize<T>;
|
|
75
251
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
252
|
+
/**
|
|
253
|
+
* Outputs a warning level log message
|
|
254
|
+
* @param {string} msg - The warning message
|
|
255
|
+
* @param {...unknown } args - Additional arguments to log
|
|
256
|
+
*/
|
|
257
|
+
declare function warn(msg: string, ...args: unknown[]): void;
|
|
258
|
+
/**
|
|
259
|
+
* Outputs an info level log message
|
|
260
|
+
* @param {string} msg - The info message
|
|
261
|
+
* @param {...unknown } args - Additional arguments to log
|
|
262
|
+
*/
|
|
263
|
+
declare function info(msg: string, ...args: unknown[]): void;
|
|
264
|
+
/**
|
|
265
|
+
* Outputs an error level log message
|
|
266
|
+
* @param {string} msg - The error message
|
|
267
|
+
* @param {...unknown } args - Additional arguments to log
|
|
268
|
+
*/
|
|
269
|
+
declare function error(msg: string, ...args: unknown[]): void;
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Escapes HTML special characters in a string to their corresponding entity references
|
|
273
|
+
* @param {unknown} string - The string to escapeHTML
|
|
274
|
+
* @returns {string} - The escaped string
|
|
275
|
+
*/
|
|
276
|
+
declare function escapeHTML(string: unknown): string;
|
|
277
|
+
/**
|
|
278
|
+
* Strips special characters from HTML comments
|
|
279
|
+
* @param {string} src - The source string
|
|
280
|
+
* @returns {string} - The cleaned string
|
|
281
|
+
*/
|
|
282
|
+
declare function escapeHTMLComment(src: string): string;
|
|
283
|
+
/**
|
|
284
|
+
* Escapes special characters in CSS variable names
|
|
285
|
+
* @param {string} key - The CSS variable name
|
|
286
|
+
* @param {boolean} doubleEscape - Whether to apply double escaping
|
|
287
|
+
* @returns {string} - The escaped CSS variable name
|
|
288
|
+
*/
|
|
289
|
+
declare function getEscapedCssVarName(key: string, doubleEscape: boolean): string;
|
|
290
|
+
|
|
291
|
+
declare const isSpecialBooleanAttr: (key: string) => boolean;
|
|
292
|
+
/**
|
|
293
|
+
* The full list is needed during SSR to produce the correct initial markup.
|
|
294
|
+
*/
|
|
295
|
+
declare const isBooleanAttr: (key: string) => boolean;
|
|
296
|
+
/**
|
|
297
|
+
* Boolean attributes should be included if the value is truthy or ''.
|
|
298
|
+
* e.g. `<select multiple>` compiles to `{ multiple: '' }`
|
|
299
|
+
*/
|
|
300
|
+
declare function includeBooleanAttr(value: unknown): boolean;
|
|
301
|
+
declare function isSSRSafeAttrName(name: string): boolean;
|
|
302
|
+
declare const propsToAttrMap: Record<string, string | undefined>;
|
|
303
|
+
/**
|
|
304
|
+
* Known attributes, this is used for stringification of runtime static nodes
|
|
305
|
+
* so that we don't stringify bindings that cannot be set from HTML.
|
|
306
|
+
* Don't also forget to allow `data-*` and `aria-*`!
|
|
307
|
+
* Generated from https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes
|
|
308
|
+
*/
|
|
309
|
+
declare const isKnownHtmlAttr: (key: string) => boolean;
|
|
310
|
+
/**
|
|
311
|
+
* Generated from https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute
|
|
312
|
+
*/
|
|
313
|
+
declare const isKnownSvgAttr: (key: string) => boolean;
|
|
314
|
+
/**
|
|
315
|
+
* Shared between server-renderer and runtime-core hydration logic
|
|
316
|
+
*/
|
|
317
|
+
declare function isRenderAbleAttrValue(value: unknown): boolean;
|
|
318
|
+
declare const isHTMLTag: (key: string) => boolean;
|
|
319
|
+
declare const isSVGTag: (key: string) => boolean;
|
|
320
|
+
declare const isMathMLTag: (key: string) => boolean;
|
|
321
|
+
declare const isVoidTag: (key: string) => boolean;
|
|
322
|
+
declare const isSelfClosingTag: (key: string) => boolean;
|
|
323
|
+
declare const isDelegatedEvent: (key: string) => boolean;
|
|
79
324
|
|
|
80
|
-
export { type ExcludeType, type StringNumber,
|
|
325
|
+
export { EMPTY_ARR, EMPTY_OBJ, type ExcludeType, type StringNumber, cacheStringFunction, camelCase, capitalize, coerceArray, error, escapeHTML, escapeHTMLComment, extend, generateUniqueId, getEscapedCssVarName, getGlobalThis, hasChanged, hasOwn, includeBooleanAttr, info, isArray, isBoolean, isBooleanAttr, isBrowser, isDelegatedEvent, isExclude, isFalsy, isFunction, isHTMLElement, isHTMLTag, isKnownHtmlAttr, isKnownSvgAttr, isMap, isMathMLTag, isNaN, isNil, isNull, isNumber, isObject, isOn, isPlainObject, isPrimitive, isPromise, isRenderAbleAttrValue, isSSRSafeAttrName, isSVGTag, isSelfClosingTag, isSet, isSpecialBooleanAttr, isString, isStringNumber, isSymbol, isUndefined, isVoidTag, isWeakMap, isWeakSet, kebabCase, noop, propsToAttrMap, startsWith, warn };
|