@tspro/ts-utils-lib 1.0.0 → 1.1.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 (50) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/LICENSE +21 -18
  3. package/dist/index.d.mts +347 -0
  4. package/dist/index.d.ts +347 -0
  5. package/dist/index.js +1098 -0
  6. package/dist/index.js.map +1 -0
  7. package/dist/index.mjs +1070 -0
  8. package/dist/index.mjs.map +1 -0
  9. package/package.json +33 -30
  10. package/dist/index.esm.mjs +0 -1101
  11. package/dist/types/array/index.d.ts +0 -13
  12. package/dist/types/array/index.d.ts.map +0 -1
  13. package/dist/types/array/index.test.d.ts +0 -2
  14. package/dist/types/array/index.test.d.ts.map +0 -1
  15. package/dist/types/core/LRU-cache.d.ts +0 -18
  16. package/dist/types/core/LRU-cache.d.ts.map +0 -1
  17. package/dist/types/core/index.d.ts +0 -5
  18. package/dist/types/core/index.d.ts.map +0 -1
  19. package/dist/types/core/small-int-cache.d.ts +0 -11
  20. package/dist/types/core/small-int-cache.d.ts.map +0 -1
  21. package/dist/types/core/stack.d.ts +0 -10
  22. package/dist/types/core/stack.d.ts.map +0 -1
  23. package/dist/types/core/stack.test.d.ts +0 -2
  24. package/dist/types/core/stack.test.d.ts.map +0 -1
  25. package/dist/types/core/vec2.d.ts +0 -11
  26. package/dist/types/core/vec2.d.ts.map +0 -1
  27. package/dist/types/dom/index.d.ts +0 -46
  28. package/dist/types/dom/index.d.ts.map +0 -1
  29. package/dist/types/enum/index.d.ts +0 -8
  30. package/dist/types/enum/index.d.ts.map +0 -1
  31. package/dist/types/index.d.ts +0 -17
  32. package/dist/types/index.d.ts.map +0 -1
  33. package/dist/types/map/index.d.ts +0 -2
  34. package/dist/types/map/index.d.ts.map +0 -1
  35. package/dist/types/math/index.d.ts +0 -17
  36. package/dist/types/math/index.d.ts.map +0 -1
  37. package/dist/types/math/index.test.d.ts +0 -2
  38. package/dist/types/math/index.test.d.ts.map +0 -1
  39. package/dist/types/modules/assert.d.ts +0 -22
  40. package/dist/types/modules/assert.d.ts.map +0 -1
  41. package/dist/types/modules/cookies.d.ts +0 -13
  42. package/dist/types/modules/cookies.d.ts.map +0 -1
  43. package/dist/types/modules/device.d.ts +0 -13
  44. package/dist/types/modules/device.d.ts.map +0 -1
  45. package/dist/types/modules/index.d.ts +0 -4
  46. package/dist/types/modules/index.d.ts.map +0 -1
  47. package/dist/types/string/index.d.ts +0 -8
  48. package/dist/types/string/index.d.ts.map +0 -1
  49. package/dist/types/string/index.test.d.ts +0 -2
  50. package/dist/types/string/index.test.d.ts.map +0 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.1.0] - 2025-07-12
4
+ ### Added
5
+ - Utils.Obj.isObject
6
+ ### Changed
7
+ - Switched bundler from webpack to tsup.
8
+ - Switched license from zlib to MIT.
9
+
10
+ ## [1.0.1] - 2025-06-30
11
+ ### Changed
12
+ - Configured babel for ES6.
13
+
3
14
  ## [1.0.0] - 2025-06-25
4
15
  ### Added
5
16
  - First release.
package/LICENSE CHANGED
@@ -1,22 +1,25 @@
1
1
 
2
- This project is licensed under the zlib License.
2
+ This project is licensed under the MIT License.
3
3
 
4
4
  ---
5
5
 
6
- Copyright (c) 2023 Stefan++ Software Studio
7
-
8
- This software is provided 'as-is', without any express or implied
9
- warranty. In no event will the authors be held liable for any damages
10
- arising from the use of this software.
11
-
12
- Permission is granted to anyone to use this software for any purpose,
13
- including commercial applications, and to alter it and redistribute it
14
- freely, subject to the following restrictions:
15
-
16
- 1. The origin of this software must not be misrepresented; you must not
17
- claim that you wrote the original software. If you use this software
18
- in a product, an acknowledgment in the product documentation would be
19
- appreciated but is not required.
20
- 2. Altered source versions must be plainly marked as such, and must not be
21
- misrepresented as being the original software.
22
- 3. This notice may not be removed or altered from any source distribution.
6
+ Copyright (c) 2023 PahkaSoft
7
+
8
+ Permission is hereby granted, free of charge, to any person obtaining
9
+ a copy of this software and associated documentation files (the
10
+ "Software"), to deal in the Software without restriction, including
11
+ without limitation the rights to use, copy, modify, merge, publish,
12
+ distribute, sublicense, and/or sell copies of the Software, and to
13
+ permit persons to whom the Software is furnished to do so, subject to
14
+ the following conditions:
15
+
16
+ The above copyright notice and this permission notice shall be included
17
+ in all copies or substantial portions of the Software.
18
+
19
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
23
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,347 @@
1
+ declare function isArray<T>(a: T[] | unknown): a is T[];
2
+ declare function toArray<T>(a: T | T[]): Array<T>;
3
+ declare function duplicate<T>(a: T[] | undefined): T[] | undefined;
4
+ declare function removeDuplicates<T>(a: T[]): T[];
5
+ declare function removeDuplicatesCmp<T>(arr: ReadonlyArray<T>, cmp: (t1: T, t2: T) => boolean): T[];
6
+ declare function fillArray<T>(fillValue: T, fillCount: number): T[];
7
+ declare function mapSequenceArray<T>(len: number, fn: (i: number) => T): T[];
8
+ declare function getSequenceArray(len: number): number[];
9
+ declare function mapRangeArray<T>(start: number, end: number, fn: (i: number) => T): T[];
10
+ declare function getRangeArray(start: number, end: number): number[];
11
+ declare function arrayContains<T extends unknown>(arg: T[], item: T): boolean;
12
+ declare function chunckArray<A>(arr: ReadonlyArray<A>, chunckSize: number): A[][];
13
+
14
+ declare const index$6_arrayContains: typeof arrayContains;
15
+ declare const index$6_chunckArray: typeof chunckArray;
16
+ declare const index$6_duplicate: typeof duplicate;
17
+ declare const index$6_fillArray: typeof fillArray;
18
+ declare const index$6_getRangeArray: typeof getRangeArray;
19
+ declare const index$6_getSequenceArray: typeof getSequenceArray;
20
+ declare const index$6_isArray: typeof isArray;
21
+ declare const index$6_mapRangeArray: typeof mapRangeArray;
22
+ declare const index$6_mapSequenceArray: typeof mapSequenceArray;
23
+ declare const index$6_removeDuplicates: typeof removeDuplicates;
24
+ declare const index$6_removeDuplicatesCmp: typeof removeDuplicatesCmp;
25
+ declare const index$6_toArray: typeof toArray;
26
+ declare namespace index$6 {
27
+ export { index$6_arrayContains as arrayContains, index$6_chunckArray as chunckArray, index$6_duplicate as duplicate, index$6_fillArray as fillArray, index$6_getRangeArray as getRangeArray, index$6_getSequenceArray as getSequenceArray, index$6_isArray as isArray, index$6_mapRangeArray as mapRangeArray, index$6_mapSequenceArray as mapSequenceArray, index$6_removeDuplicates as removeDuplicates, index$6_removeDuplicatesCmp as removeDuplicatesCmp, index$6_toArray as toArray };
28
+ }
29
+
30
+ interface CSSProperties {
31
+ padding?: string | number;
32
+ paddingLeft?: string | number;
33
+ paddingRight?: string | number;
34
+ paddingTop?: string | number;
35
+ paddingBottom?: string | number;
36
+ left?: string | number;
37
+ right?: string | number;
38
+ top?: string | number;
39
+ bottom?: string | number;
40
+ width?: string | number;
41
+ height?: string | number;
42
+ }
43
+ declare function hasClass(el: HTMLElement, className: string): boolean;
44
+ declare function addClass(el: HTMLElement, className: string): void;
45
+ declare function removeClass(el: HTMLElement, className: string): void;
46
+ declare function setOffset(el: HTMLElement, left: number, top: number, unit?: string): void;
47
+ declare function getOffset(el: HTMLElement): {
48
+ left: number;
49
+ top: number;
50
+ };
51
+ declare function getWidth(el: HTMLElement | Window): number;
52
+ declare function setWidth(el: HTMLElement, val: number): void;
53
+ declare function getHeight(el: HTMLElement | Window): number;
54
+ declare function setHeight(el: HTMLElement, val: number): void;
55
+ declare function appendTo(el: HTMLElement | SVGElement, to: HTMLElement | SVGElement): void;
56
+ declare function removeFromParent(el: HTMLElement | SVGElement): void;
57
+ declare function setVisibility(el: HTMLElement | SVGElement, visible: boolean): void;
58
+ declare function setRect(el: HTMLElement, left: number, top: number, width: number, height: number, unit?: string): void;
59
+ declare function getButton(btn: HTMLElement | string): HTMLButtonElement | undefined;
60
+ declare function getCanvas(canvas: HTMLElement | string): HTMLCanvasElement | undefined;
61
+ declare function getPadding(style?: CSSProperties): {
62
+ top: number;
63
+ right: number;
64
+ bottom: number;
65
+ left: number;
66
+ };
67
+ declare function getDimension(style?: CSSProperties): {
68
+ left: number | undefined;
69
+ top: number | undefined;
70
+ width: number | undefined;
71
+ height: number | undefined;
72
+ };
73
+ declare function styleLayoutChanged(style1?: CSSProperties, style2?: CSSProperties): boolean;
74
+ declare function getCanvasTextWidth(text: string, font: string): number;
75
+
76
+ type index$5_CSSProperties = CSSProperties;
77
+ declare const index$5_addClass: typeof addClass;
78
+ declare const index$5_appendTo: typeof appendTo;
79
+ declare const index$5_getButton: typeof getButton;
80
+ declare const index$5_getCanvas: typeof getCanvas;
81
+ declare const index$5_getCanvasTextWidth: typeof getCanvasTextWidth;
82
+ declare const index$5_getDimension: typeof getDimension;
83
+ declare const index$5_getHeight: typeof getHeight;
84
+ declare const index$5_getOffset: typeof getOffset;
85
+ declare const index$5_getPadding: typeof getPadding;
86
+ declare const index$5_getWidth: typeof getWidth;
87
+ declare const index$5_hasClass: typeof hasClass;
88
+ declare const index$5_removeClass: typeof removeClass;
89
+ declare const index$5_removeFromParent: typeof removeFromParent;
90
+ declare const index$5_setHeight: typeof setHeight;
91
+ declare const index$5_setOffset: typeof setOffset;
92
+ declare const index$5_setRect: typeof setRect;
93
+ declare const index$5_setVisibility: typeof setVisibility;
94
+ declare const index$5_setWidth: typeof setWidth;
95
+ declare const index$5_styleLayoutChanged: typeof styleLayoutChanged;
96
+ declare namespace index$5 {
97
+ export { type index$5_CSSProperties as CSSProperties, index$5_addClass as addClass, index$5_appendTo as appendTo, index$5_getButton as getButton, index$5_getCanvas as getCanvas, index$5_getCanvasTextWidth as getCanvasTextWidth, index$5_getDimension as getDimension, index$5_getHeight as getHeight, index$5_getOffset as getOffset, index$5_getPadding as getPadding, index$5_getWidth as getWidth, index$5_hasClass as hasClass, index$5_removeClass as removeClass, index$5_removeFromParent as removeFromParent, index$5_setHeight as setHeight, index$5_setOffset as setOffset, index$5_setRect as setRect, index$5_setVisibility as setVisibility, index$5_setWidth as setWidth, index$5_styleLayoutChanged as styleLayoutChanged };
98
+ }
99
+
100
+ type EnumObject = {
101
+ [key: string]: string | number;
102
+ };
103
+ type EnumValue<E extends EnumObject> = E extends {
104
+ [key: string]: string | infer V;
105
+ } ? V : never;
106
+ declare function getEnumValues<E extends EnumObject>(e: E): Array<EnumValue<E>>;
107
+
108
+ type index$4_EnumObject = EnumObject;
109
+ type index$4_EnumValue<E extends EnumObject> = EnumValue<E>;
110
+ declare const index$4_getEnumValues: typeof getEnumValues;
111
+ declare namespace index$4 {
112
+ export { type index$4_EnumObject as EnumObject, type index$4_EnumValue as EnumValue, index$4_getEnumValues as getEnumValues };
113
+ }
114
+
115
+ declare function getMapKeys<K, V>(map: Map<K, V>): K[];
116
+
117
+ declare const index$3_getMapKeys: typeof getMapKeys;
118
+ declare namespace index$3 {
119
+ export { index$3_getMapKeys as getMapKeys };
120
+ }
121
+
122
+ declare function isInteger(n: unknown): n is number;
123
+ declare function linearToDecibels(linearVolume: number): number;
124
+ declare function mod(m: number, n: number): number;
125
+ /**
126
+ * Convert number to roman number.
127
+ * https://blog.stevenlevithan.com/archives/javascript-roman-numeral-converter
128
+ */
129
+ declare function romanize(n: number): string;
130
+ declare function toOrdinalNumber(n: number): string;
131
+ declare function interpolateCoord(startX: number, startY: number, endX: number, endY: number, t: number): {
132
+ x: number;
133
+ y: number;
134
+ };
135
+ declare function interpolateY(startX: number, startY: number, endX: number, endY: number, x: number): number;
136
+ declare function clamp(num: number, min: number, max: number): number;
137
+ declare function calcNormal(x1: number, y1: number, x2: number, y2: number): {
138
+ nx: number;
139
+ ny: number;
140
+ };
141
+ declare function sum(arr: number[]): number;
142
+
143
+ declare const index$2_calcNormal: typeof calcNormal;
144
+ declare const index$2_clamp: typeof clamp;
145
+ declare const index$2_interpolateCoord: typeof interpolateCoord;
146
+ declare const index$2_interpolateY: typeof interpolateY;
147
+ declare const index$2_isInteger: typeof isInteger;
148
+ declare const index$2_linearToDecibels: typeof linearToDecibels;
149
+ declare const index$2_mod: typeof mod;
150
+ declare const index$2_romanize: typeof romanize;
151
+ declare const index$2_sum: typeof sum;
152
+ declare const index$2_toOrdinalNumber: typeof toOrdinalNumber;
153
+ declare namespace index$2 {
154
+ export { index$2_calcNormal as calcNormal, index$2_clamp as clamp, index$2_interpolateCoord as interpolateCoord, index$2_interpolateY as interpolateY, index$2_isInteger as isInteger, index$2_linearToDecibels as linearToDecibels, index$2_mod as mod, index$2_romanize as romanize, index$2_sum as sum, index$2_toOrdinalNumber as toOrdinalNumber };
155
+ }
156
+
157
+ declare function isObject(value: unknown): value is Record<string, unknown>;
158
+
159
+ declare const index$1_isObject: typeof isObject;
160
+ declare namespace index$1 {
161
+ export { index$1_isObject as isObject };
162
+ }
163
+
164
+ /**
165
+ * toCharArray("abc") => ["a", "b", "c"].
166
+ * @param str
167
+ */
168
+ declare function toCharArray(str: string): string[];
169
+ /**
170
+ * repeat("abc", 3) => "abcabcabc".
171
+ * repeat("abc", 0) => "".
172
+ * @param repeatString
173
+ * @param repeatCount
174
+ */
175
+ declare function repeatString(repeatString: string, repeatCount: number): string;
176
+ /**
177
+ * "abcdefgh":chunkSize = 3 => ["abc", "def", "gh"]
178
+ * @param str
179
+ * @param chunkSize
180
+ */
181
+ declare function chunkString(str: string, chunkSize: number): string[];
182
+ /**
183
+ * Replaces part of string.
184
+ * @param str
185
+ * @param pos
186
+ * @param removeCount
187
+ * @param insert
188
+ */
189
+ declare function replaceAt(str: string, pos: number, removeCount: number, insert: string): string;
190
+ /**
191
+ * Insert string to another.
192
+ * @param str
193
+ * @param pos
194
+ * @param insertStr
195
+ */
196
+ declare function insertAt(str: string, pos: number, insertStr: string): string;
197
+ /**
198
+ * Remove part of string.
199
+ * @param str
200
+ * @param pos
201
+ * @param removeCount
202
+ */
203
+ declare function removeAt(str: string, pos: number, removeCount: number): string;
204
+ /**
205
+ * "UndeclaredVariable" => "Undeclared variable"
206
+ * @param PascalString
207
+ */
208
+ declare function makeSentenceFromPascal(PascalString: string): string;
209
+
210
+ declare const index_chunkString: typeof chunkString;
211
+ declare const index_insertAt: typeof insertAt;
212
+ declare const index_makeSentenceFromPascal: typeof makeSentenceFromPascal;
213
+ declare const index_removeAt: typeof removeAt;
214
+ declare const index_repeatString: typeof repeatString;
215
+ declare const index_replaceAt: typeof replaceAt;
216
+ declare const index_toCharArray: typeof toCharArray;
217
+ declare namespace index {
218
+ export { index_chunkString as chunkString, index_insertAt as insertAt, index_makeSentenceFromPascal as makeSentenceFromPascal, index_removeAt as removeAt, index_repeatString as repeatString, index_replaceAt as replaceAt, index_toCharArray as toCharArray };
219
+ }
220
+
221
+ declare namespace exportUtils {
222
+ export { index$6 as Arr, index$5 as Dom, index$4 as Enum, index$3 as Map, index$2 as Math, index$1 as Obj, index as Str };
223
+ }
224
+
225
+ declare namespace Assert {
226
+ type ErrorConstructor = new (msg: string) => Error;
227
+ function setErrorClass(ec?: ErrorConstructor): void;
228
+ function assert<T>(a: T, userMsg?: string): void;
229
+ function interrupt(userMsg?: string): never;
230
+ function int(a: unknown, userMsg?: string): number;
231
+ function eq<T>(a: T, b: T, userMsg?: string): T;
232
+ function int_eq(a: unknown, b: unknown, userMsg?: string): number;
233
+ function int_lt(a: unknown, b: unknown, userMsg?: string): number;
234
+ function int_lte(a: unknown, b: unknown, userMsg?: string): number;
235
+ function int_gt(a: unknown, b: unknown, userMsg?: string): number;
236
+ function int_gte(a: unknown, b: unknown, userMsg?: string): number;
237
+ function int_between(a: unknown, min: unknown, max: unknown, userMsg?: string): number;
238
+ function odd(a: unknown, userMsg?: string): number;
239
+ function even(a: unknown, userMsg?: string): number;
240
+ function in_group<T>(a: T, group: ReadonlyArray<T>, userMsg?: string): T;
241
+ function finite(a: unknown, userMsg?: string): number;
242
+ function array_id<T>(arr: Readonly<T[]>, id: unknown, userMsg?: string): number;
243
+ function array_elem<T>(arr: Readonly<T[]>, id: number, userMsg?: string): T;
244
+ function require<T>(arg: T, userMsg?: string): NonNullable<T>;
245
+ }
246
+
247
+ declare namespace Cookies {
248
+ function setExpireDays(days: number): void;
249
+ function isConsentPending(): boolean;
250
+ function accept(): void;
251
+ function decline(): void;
252
+ function save<T extends string | number | boolean>(name: string, value: T): T;
253
+ function read(name: string, defaultValue: string): string;
254
+ function readInt(name: string, defaultValue: number): number;
255
+ function readBool(name: string, defaultValue: boolean): boolean;
256
+ function erase(name: string): void;
257
+ function eraseAll(): void;
258
+ }
259
+
260
+ declare namespace Device {
261
+ const DPI: number;
262
+ const PxPerMm: number;
263
+ const ScrollbarWidth: number;
264
+ const FontSize: number;
265
+ const IsTouchDevice: boolean;
266
+ const IsMobileDevice: boolean;
267
+ const HostAddress: string;
268
+ function pxToMm(px: number): number;
269
+ function mmToPx(mm: number): number;
270
+ function toPx(input: string | number): number;
271
+ }
272
+
273
+ declare class Stack<T> {
274
+ private readonly list;
275
+ push(e: T): T;
276
+ pop(): T;
277
+ top(): T;
278
+ toArray(): T[];
279
+ get length(): number;
280
+ clear(): void;
281
+ }
282
+
283
+ declare class Vec2 {
284
+ readonly x: number;
285
+ readonly y: number;
286
+ constructor(x?: number, y?: number);
287
+ length(): number;
288
+ add(a: Vec2): Vec2;
289
+ sub(a: Vec2): Vec2;
290
+ mul(a: number): Vec2;
291
+ div(a: number): Vec2;
292
+ }
293
+
294
+ /**
295
+ * LRUCache class: Least Recently Used cache with a fixed capacity
296
+ *
297
+ * Provided by ChatGPT.
298
+ */
299
+ declare class LRUCache<K extends string, V> {
300
+ private cache;
301
+ private next;
302
+ private prev;
303
+ private head;
304
+ private tail;
305
+ private capacity;
306
+ private size;
307
+ private maxKeyLength;
308
+ constructor(maxSize: number, maxKeyLength?: number);
309
+ get(key: K): V | undefined;
310
+ set(key: K, value: V): void;
311
+ private touch;
312
+ private evict;
313
+ private removeKey;
314
+ private addToTail;
315
+ }
316
+
317
+ /**
318
+ * A cache-like structure optimized for small-range integer keys, including negatives.
319
+ *
320
+ * Internally implemented using two sparse arrays: one for non-negative keys,
321
+ * and one for negative keys (stored by index `-key - 1`).
322
+ *
323
+ * @remarks
324
+ * - Fast access for small integer keys.
325
+ * - Not suitable for large or sparse key ranges — memory usage may grow significantly.
326
+ * - Supports `get`, `set`, `delete`, `has` and `clear`
327
+ *
328
+ * @example
329
+ * ```ts
330
+ * const cache = new SmallIntCache<string>();
331
+ * cache.set(-2, 'A');
332
+ * cache.set(3, 'B');
333
+ * console.log(cache.get(-2)); // 'A'
334
+ * ```
335
+ */
336
+ declare class SmallIntCache<V> {
337
+ private pos;
338
+ private neg;
339
+ constructor();
340
+ set(key: number, value: V): void;
341
+ get(key: number): V | undefined;
342
+ has(key: number): boolean;
343
+ delete(key: number): void;
344
+ clear(): void;
345
+ }
346
+
347
+ export { Assert, Cookies, Device, LRUCache, SmallIntCache, Stack, exportUtils as Utils, Vec2 };