@bquery/bquery 1.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.
Files changed (80) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +266 -0
  3. package/dist/component/index.d.ts +155 -0
  4. package/dist/component/index.d.ts.map +1 -0
  5. package/dist/component.es.mjs +128 -0
  6. package/dist/component.es.mjs.map +1 -0
  7. package/dist/core/collection.d.ts +198 -0
  8. package/dist/core/collection.d.ts.map +1 -0
  9. package/dist/core/element.d.ts +301 -0
  10. package/dist/core/element.d.ts.map +1 -0
  11. package/dist/core/index.d.ts +5 -0
  12. package/dist/core/index.d.ts.map +1 -0
  13. package/dist/core/selector.d.ts +11 -0
  14. package/dist/core/selector.d.ts.map +1 -0
  15. package/dist/core/shared.d.ts +7 -0
  16. package/dist/core/shared.d.ts.map +1 -0
  17. package/dist/core/utils.d.ts +300 -0
  18. package/dist/core/utils.d.ts.map +1 -0
  19. package/dist/core.es.mjs +1015 -0
  20. package/dist/core.es.mjs.map +1 -0
  21. package/dist/full.d.ts +48 -0
  22. package/dist/full.d.ts.map +1 -0
  23. package/dist/full.es.mjs +43 -0
  24. package/dist/full.es.mjs.map +1 -0
  25. package/dist/full.iife.js +2 -0
  26. package/dist/full.iife.js.map +1 -0
  27. package/dist/full.umd.js +2 -0
  28. package/dist/full.umd.js.map +1 -0
  29. package/dist/index.d.ts +16 -0
  30. package/dist/index.d.ts.map +1 -0
  31. package/dist/index.es.mjs +43 -0
  32. package/dist/index.es.mjs.map +1 -0
  33. package/dist/motion/index.d.ts +145 -0
  34. package/dist/motion/index.d.ts.map +1 -0
  35. package/dist/motion.es.mjs +104 -0
  36. package/dist/motion.es.mjs.map +1 -0
  37. package/dist/platform/buckets.d.ts +44 -0
  38. package/dist/platform/buckets.d.ts.map +1 -0
  39. package/dist/platform/cache.d.ts +71 -0
  40. package/dist/platform/cache.d.ts.map +1 -0
  41. package/dist/platform/index.d.ts +15 -0
  42. package/dist/platform/index.d.ts.map +1 -0
  43. package/dist/platform/notifications.d.ts +52 -0
  44. package/dist/platform/notifications.d.ts.map +1 -0
  45. package/dist/platform/storage.d.ts +69 -0
  46. package/dist/platform/storage.d.ts.map +1 -0
  47. package/dist/platform.es.mjs +245 -0
  48. package/dist/platform.es.mjs.map +1 -0
  49. package/dist/reactive/index.d.ts +8 -0
  50. package/dist/reactive/index.d.ts.map +1 -0
  51. package/dist/reactive/signal.d.ts +204 -0
  52. package/dist/reactive/signal.d.ts.map +1 -0
  53. package/dist/reactive.es.mjs +123 -0
  54. package/dist/reactive.es.mjs.map +1 -0
  55. package/dist/security/index.d.ts +8 -0
  56. package/dist/security/index.d.ts.map +1 -0
  57. package/dist/security/sanitize.d.ts +99 -0
  58. package/dist/security/sanitize.d.ts.map +1 -0
  59. package/dist/security.es.mjs +194 -0
  60. package/dist/security.es.mjs.map +1 -0
  61. package/package.json +120 -0
  62. package/src/component/index.ts +360 -0
  63. package/src/core/collection.ts +339 -0
  64. package/src/core/element.ts +493 -0
  65. package/src/core/index.ts +4 -0
  66. package/src/core/selector.ts +29 -0
  67. package/src/core/shared.ts +13 -0
  68. package/src/core/utils.ts +425 -0
  69. package/src/full.ts +101 -0
  70. package/src/index.ts +27 -0
  71. package/src/motion/index.ts +365 -0
  72. package/src/platform/buckets.ts +115 -0
  73. package/src/platform/cache.ts +130 -0
  74. package/src/platform/index.ts +18 -0
  75. package/src/platform/notifications.ts +87 -0
  76. package/src/platform/storage.ts +208 -0
  77. package/src/reactive/index.ts +9 -0
  78. package/src/reactive/signal.ts +347 -0
  79. package/src/security/index.ts +18 -0
  80. package/src/security/sanitize.ts +446 -0
@@ -0,0 +1,300 @@
1
+ /**
2
+ * Utility helpers used across the framework.
3
+ * These are intentionally small and framework-agnostic to keep the core tiny.
4
+ *
5
+ * @module bquery/core/utils
6
+ */
7
+ /**
8
+ * Utility object containing common helper functions.
9
+ * All utilities are designed to be tree-shakeable and have zero dependencies.
10
+ */
11
+ export declare const utils: {
12
+ /**
13
+ * Creates a deep clone using structuredClone if available, otherwise fallback to JSON.
14
+ *
15
+ * @template T - The type of value being cloned
16
+ * @param value - The value to clone
17
+ * @returns A deep copy of the value
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * const original = { nested: { value: 1 } };
22
+ * const copy = utils.clone(original);
23
+ * copy.nested.value = 2;
24
+ * console.log(original.nested.value); // 1
25
+ * ```
26
+ */
27
+ clone<T>(value: T): T;
28
+ /**
29
+ * Deep-merges plain objects into a new object.
30
+ * Later sources override earlier ones for primitive values.
31
+ * Objects are recursively merged.
32
+ *
33
+ * @template T - The type of the merged object
34
+ * @param sources - Objects to merge
35
+ * @returns A new object with all sources merged
36
+ *
37
+ * @example
38
+ * ```ts
39
+ * const result = utils.merge(
40
+ * { a: 1, nested: { x: 1 } },
41
+ * { b: 2, nested: { y: 2 } }
42
+ * );
43
+ * // Result: { a: 1, b: 2, nested: { x: 1, y: 2 } }
44
+ * ```
45
+ */
46
+ merge<T extends Record<string, unknown>>(...sources: T[]): T;
47
+ /**
48
+ * Creates a debounced function that delays execution until after
49
+ * the specified delay has elapsed since the last call.
50
+ *
51
+ * @template TArgs - The argument types of the function
52
+ * @param fn - The function to debounce
53
+ * @param delayMs - Delay in milliseconds
54
+ * @returns A debounced version of the function
55
+ *
56
+ * @example
57
+ * ```ts
58
+ * const search = utils.debounce((query: string) => {
59
+ * console.log('Searching:', query);
60
+ * }, 300);
61
+ *
62
+ * search('h');
63
+ * search('he');
64
+ * search('hello'); // Only this call executes after 300ms
65
+ * ```
66
+ */
67
+ debounce<TArgs extends unknown[]>(fn: (...args: TArgs) => void, delayMs: number): (...args: TArgs) => void;
68
+ /**
69
+ * Creates a throttled function that runs at most once per interval.
70
+ *
71
+ * @template TArgs - The argument types of the function
72
+ * @param fn - The function to throttle
73
+ * @param intervalMs - Minimum interval between calls in milliseconds
74
+ * @returns A throttled version of the function
75
+ *
76
+ * @example
77
+ * ```ts
78
+ * const handleScroll = utils.throttle(() => {
79
+ * console.log('Scroll position:', window.scrollY);
80
+ * }, 100);
81
+ *
82
+ * window.addEventListener('scroll', handleScroll);
83
+ * ```
84
+ */
85
+ throttle<TArgs extends unknown[]>(fn: (...args: TArgs) => void, intervalMs: number): (...args: TArgs) => void;
86
+ /**
87
+ * Creates a stable unique ID for DOM usage.
88
+ *
89
+ * @param prefix - Optional prefix for the ID (default: 'bQuery')
90
+ * @returns A unique identifier string
91
+ *
92
+ * @example
93
+ * ```ts
94
+ * const id = utils.uid('modal'); // 'modal_x7k2m9p'
95
+ * ```
96
+ */
97
+ uid(prefix?: string): string;
98
+ /**
99
+ * Checks if a value is a DOM Element.
100
+ *
101
+ * @param value - The value to check
102
+ * @returns True if the value is an Element
103
+ */
104
+ isElement(value: unknown): value is Element;
105
+ /**
106
+ * Checks if a value is a BQueryCollection-like object.
107
+ *
108
+ * @param value - The value to check
109
+ * @returns True if the value has an elements array property
110
+ */
111
+ isCollection(value: unknown): value is {
112
+ elements: Element[];
113
+ };
114
+ /**
115
+ * Checks for emptiness across common value types.
116
+ *
117
+ * @param value - The value to check
118
+ * @returns True if the value is empty (null, undefined, empty string, empty array, or empty object)
119
+ *
120
+ * @example
121
+ * ```ts
122
+ * utils.isEmpty(''); // true
123
+ * utils.isEmpty([]); // true
124
+ * utils.isEmpty({}); // true
125
+ * utils.isEmpty(null); // true
126
+ * utils.isEmpty('hello'); // false
127
+ * utils.isEmpty([1, 2]); // false
128
+ * ```
129
+ */
130
+ isEmpty(value: unknown): boolean;
131
+ /**
132
+ * Checks if a value is a plain object (not null, array, or class instance).
133
+ *
134
+ * @param value - The value to check
135
+ * @returns True if the value is a plain object
136
+ */
137
+ isPlainObject(value: unknown): value is Record<string, unknown>;
138
+ /**
139
+ * Checks if a value is a function.
140
+ *
141
+ * @param value - The value to check
142
+ * @returns True if the value is a function
143
+ */
144
+ isFunction(value: unknown): value is (...args: unknown[]) => unknown;
145
+ /**
146
+ * Checks if a value is a string.
147
+ *
148
+ * @param value - The value to check
149
+ * @returns True if the value is a string
150
+ */
151
+ isString(value: unknown): value is string;
152
+ /**
153
+ * Checks if a value is a number (excluding NaN).
154
+ *
155
+ * @param value - The value to check
156
+ * @returns True if the value is a valid number
157
+ */
158
+ isNumber(value: unknown): value is number;
159
+ /**
160
+ * Checks if a value is a boolean.
161
+ *
162
+ * @param value - The value to check
163
+ * @returns True if the value is a boolean
164
+ */
165
+ isBoolean(value: unknown): value is boolean;
166
+ /**
167
+ * Checks if a value is an array.
168
+ *
169
+ * @template T - The type of array elements
170
+ * @param value - The value to check
171
+ * @returns True if the value is an array
172
+ */
173
+ isArray<T = unknown>(value: unknown): value is T[];
174
+ /**
175
+ * Safely parses a JSON string, returning a default value on error.
176
+ *
177
+ * @template T - The expected type of the parsed value
178
+ * @param json - The JSON string to parse
179
+ * @param fallback - The default value if parsing fails
180
+ * @returns The parsed value or the fallback
181
+ *
182
+ * @example
183
+ * ```ts
184
+ * utils.parseJson('{"name":"bQuery"}', {}); // { name: 'bQuery' }
185
+ * utils.parseJson('invalid', {}); // {}
186
+ * ```
187
+ */
188
+ parseJson<T>(json: string, fallback: T): T;
189
+ /**
190
+ * Picks specified keys from an object.
191
+ *
192
+ * @template T - The object type
193
+ * @template K - The key type
194
+ * @param obj - The source object
195
+ * @param keys - Keys to pick
196
+ * @returns A new object with only the specified keys
197
+ *
198
+ * @example
199
+ * ```ts
200
+ * const user = { name: 'John', age: 30, email: 'john@example.com' };
201
+ * utils.pick(user, ['name', 'email']); // { name: 'John', email: 'john@example.com' }
202
+ * ```
203
+ */
204
+ pick<T extends Record<string, unknown>, K extends keyof T>(obj: T, keys: K[]): Pick<T, K>;
205
+ /**
206
+ * Omits specified keys from an object.
207
+ *
208
+ * @template T - The object type
209
+ * @template K - The key type
210
+ * @param obj - The source object
211
+ * @param keys - Keys to omit
212
+ * @returns A new object without the specified keys
213
+ *
214
+ * @example
215
+ * ```ts
216
+ * const user = { name: 'John', age: 30, password: 'secret' };
217
+ * utils.omit(user, ['password']); // { name: 'John', age: 30 }
218
+ * ```
219
+ */
220
+ omit<T extends Record<string, unknown>, K extends keyof T>(obj: T, keys: K[]): Omit<T, K>;
221
+ /**
222
+ * Delays execution for a specified number of milliseconds.
223
+ *
224
+ * @param ms - Milliseconds to delay
225
+ * @returns A promise that resolves after the delay
226
+ *
227
+ * @example
228
+ * ```ts
229
+ * await utils.sleep(1000); // Wait 1 second
230
+ * console.log('Done!');
231
+ * ```
232
+ */
233
+ sleep(ms: number): Promise<void>;
234
+ /**
235
+ * Generates a random integer between min and max (inclusive).
236
+ *
237
+ * @param min - Minimum value
238
+ * @param max - Maximum value
239
+ * @returns A random integer in the range [min, max]
240
+ *
241
+ * @example
242
+ * ```ts
243
+ * const roll = utils.randomInt(1, 6); // Random dice roll
244
+ * ```
245
+ */
246
+ randomInt(min: number, max: number): number;
247
+ /**
248
+ * Clamps a number between a minimum and maximum value.
249
+ *
250
+ * @param value - The value to clamp
251
+ * @param min - Minimum value
252
+ * @param max - Maximum value
253
+ * @returns The clamped value
254
+ *
255
+ * @example
256
+ * ```ts
257
+ * utils.clamp(150, 0, 100); // 100
258
+ * utils.clamp(-10, 0, 100); // 0
259
+ * utils.clamp(50, 0, 100); // 50
260
+ * ```
261
+ */
262
+ clamp(value: number, min: number, max: number): number;
263
+ /**
264
+ * Capitalizes the first letter of a string.
265
+ *
266
+ * @param str - The string to capitalize
267
+ * @returns The capitalized string
268
+ *
269
+ * @example
270
+ * ```ts
271
+ * utils.capitalize('hello'); // 'Hello'
272
+ * ```
273
+ */
274
+ capitalize(str: string): string;
275
+ /**
276
+ * Converts a string to kebab-case.
277
+ *
278
+ * @param str - The string to convert
279
+ * @returns The kebab-cased string
280
+ *
281
+ * @example
282
+ * ```ts
283
+ * utils.toKebabCase('myVariableName'); // 'my-variable-name'
284
+ * ```
285
+ */
286
+ toKebabCase(str: string): string;
287
+ /**
288
+ * Converts a string to camelCase.
289
+ *
290
+ * @param str - The string to convert
291
+ * @returns The camelCased string
292
+ *
293
+ * @example
294
+ * ```ts
295
+ * utils.toCamelCase('my-variable-name'); // 'myVariableName'
296
+ * ```
297
+ */
298
+ toCamelCase(str: string): string;
299
+ };
300
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/core/utils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;GAGG;AACH,eAAO,MAAM,KAAK;IAChB;;;;;;;;;;;;;;OAcG;UACG,CAAC,SAAS,CAAC,GAAG,CAAC;IAOrB;;;;;;;;;;;;;;;;;OAiBG;UACG,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,cAAc,CAAC,EAAE,GAAG,CAAC;IAiB5D;;;;;;;;;;;;;;;;;;;OAmBG;aACM,KAAK,SAAS,OAAO,EAAE,MAC1B,CAAC,GAAG,IAAI,EAAE,KAAK,KAAK,IAAI,WACnB,MAAM,GACd,CAAC,GAAG,IAAI,EAAE,KAAK,KAAK,IAAI;IAU3B;;;;;;;;;;;;;;;;OAgBG;aACM,KAAK,SAAS,OAAO,EAAE,MAC1B,CAAC,GAAG,IAAI,EAAE,KAAK,KAAK,IAAI,cAChB,MAAM,GACjB,CAAC,GAAG,IAAI,EAAE,KAAK,KAAK,IAAI;IAW3B;;;;;;;;;;OAUG;0BACqB,MAAM;IAI9B;;;;;OAKG;qBACc,OAAO,GAAG,KAAK,IAAI,OAAO;IAI3C;;;;;OAKG;wBACiB,OAAO,GAAG,KAAK,IAAI;QAAE,QAAQ,EAAE,OAAO,EAAE,CAAA;KAAE;IAI9D;;;;;;;;;;;;;;;OAeG;mBACY,OAAO,GAAG,OAAO;IAQhC;;;;;OAKG;yBACkB,OAAO,GAAG,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAI/D;;;;;OAKG;sBACe,OAAO,GAAG,KAAK,IAAI,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO;IAIpE;;;;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