@hichchi/utils 0.0.1-beta.2 → 0.0.2
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/index.cjs.default.js +1 -0
- package/index.cjs.js +3645 -0
- package/index.cjs.mjs +2 -0
- package/index.d.ts +1 -5
- package/index.esm.js +3575 -0
- package/package.json +13 -8
- package/src/index.d.ts +5 -0
- package/{interfaces → src/interfaces}/infinite-object.interface.d.ts +3 -3
- package/{interfaces → src/interfaces}/path-value-set.interface.d.ts +12 -12
- package/{types → src/types}/deep-partial.type.d.ts +6 -0
- package/{types → src/types}/literal-object.type.d.ts +2 -2
- package/{utils → src/utils}/index.d.ts +1 -0
- package/{utils → src/utils}/object.utils.d.ts +23 -19
- package/CHANGELOG.md +0 -19
- package/README.md +0 -7944
- package/constants/constants.js +0 -227
- package/constants/constants.js.map +0 -1
- package/constants/english-inflection-rules.js +0 -360
- package/constants/english-inflection-rules.js.map +0 -1
- package/constants/index.js +0 -6
- package/constants/index.js.map +0 -1
- package/enums/index.js +0 -5
- package/enums/index.js.map +0 -1
- package/enums/template-tag.enum.js +0 -39
- package/enums/template-tag.enum.js.map +0 -1
- package/index.js +0 -9
- package/index.js.map +0 -1
- package/interfaces/index.js +0 -7
- package/interfaces/index.js.map +0 -1
- package/interfaces/infinite-object.interface.js +0 -3
- package/interfaces/infinite-object.interface.js.map +0 -1
- package/interfaces/inflection-rule.interfaces.js +0 -3
- package/interfaces/inflection-rule.interfaces.js.map +0 -1
- package/interfaces/path-value-set.interface.js +0 -3
- package/interfaces/path-value-set.interface.js.map +0 -1
- package/readme-top.md +0 -187
- package/types/deep-partial.type.js +0 -3
- package/types/deep-partial.type.js.map +0 -1
- package/types/index.js +0 -38
- package/types/index.js.map +0 -1
- package/types/is-already-in-path.type.js +0 -3
- package/types/is-already-in-path.type.js.map +0 -1
- package/types/is-empty.type.js +0 -3
- package/types/is-empty.type.js.map +0 -1
- package/types/is-primitive.type.js +0 -4
- package/types/is-primitive.type.js.map +0 -1
- package/types/literal-object.type.js +0 -3
- package/types/literal-object.type.js.map +0 -1
- package/types/loose-autocomplete.type.js +0 -3
- package/types/loose-autocomplete.type.js.map +0 -1
- package/types/partial-with-null.type.js +0 -3
- package/types/partial-with-null.type.js.map +0 -1
- package/types/prettify.type.js +0 -3
- package/types/prettify.type.js.map +0 -1
- package/types/type.type.js +0 -3
- package/types/type.type.js.map +0 -1
- package/utils/assertions.utils.js +0 -163
- package/utils/assertions.utils.js.map +0 -1
- package/utils/file.utils.js +0 -1315
- package/utils/file.utils.js.map +0 -1
- package/utils/index.js +0 -9
- package/utils/index.js.map +0 -1
- package/utils/object.utils.js +0 -1069
- package/utils/object.utils.js.map +0 -1
- package/utils/string-template.utils.js +0 -269
- package/utils/string-template.utils.js.map +0 -1
- package/utils/string.utils.js +0 -1255
- package/utils/string.utils.js.map +0 -1
- package/utils/url.utils.js +0 -112
- package/utils/url.utils.js.map +0 -1
- /package/{constants → src/constants}/constants.d.ts +0 -0
- /package/{constants → src/constants}/english-inflection-rules.d.ts +0 -0
- /package/{constants → src/constants}/index.d.ts +0 -0
- /package/{enums → src/enums}/index.d.ts +0 -0
- /package/{enums → src/enums}/template-tag.enum.d.ts +0 -0
- /package/{interfaces → src/interfaces}/index.d.ts +0 -0
- /package/{interfaces → src/interfaces}/inflection-rule.interfaces.d.ts +0 -0
- /package/{types → src/types}/index.d.ts +0 -0
- /package/{types → src/types}/is-already-in-path.type.d.ts +0 -0
- /package/{types → src/types}/is-empty.type.d.ts +0 -0
- /package/{types → src/types}/is-primitive.type.d.ts +0 -0
- /package/{types → src/types}/loose-autocomplete.type.d.ts +0 -0
- /package/{types → src/types}/partial-with-null.type.d.ts +0 -0
- /package/{types → src/types}/prettify.type.d.ts +0 -0
- /package/{types → src/types}/type.type.d.ts +0 -0
- /package/{utils → src/utils}/assertions.utils.d.ts +0 -0
- /package/{utils → src/utils}/file.utils.d.ts +0 -0
- /package/{utils → src/utils}/string-template.utils.d.ts +0 -0
- /package/{utils → src/utils}/string.utils.d.ts +0 -0
- /package/{utils → src/utils}/url.utils.d.ts +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hichchi/utils",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -11,12 +11,17 @@
|
|
|
11
11
|
"keywords": [],
|
|
12
12
|
"author": "Waruna Udayanga",
|
|
13
13
|
"license": "MIT",
|
|
14
|
-
"main": "./index.js",
|
|
15
|
-
"typings": "./index.d.ts",
|
|
16
14
|
"sideEffects": false,
|
|
17
|
-
"
|
|
18
|
-
"
|
|
15
|
+
"exports": {
|
|
16
|
+
"./package.json": "./package.json",
|
|
17
|
+
".": {
|
|
18
|
+
"module": "./index.esm.js",
|
|
19
|
+
"types": "./index.d.ts",
|
|
20
|
+
"import": "./index.cjs.mjs",
|
|
21
|
+
"default": "./index.cjs.js"
|
|
22
|
+
}
|
|
19
23
|
},
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
|
|
24
|
+
"module": "./index.esm.js",
|
|
25
|
+
"main": "./index.cjs.js",
|
|
26
|
+
"types": "./index.d.ts"
|
|
27
|
+
}
|
package/src/index.d.ts
ADDED
|
@@ -18,9 +18,9 @@
|
|
|
18
18
|
* This type is often used in conjunction with utility functions for traversing, flattening,
|
|
19
19
|
* or manipulating deeply nested object structures.
|
|
20
20
|
*
|
|
21
|
-
* @see
|
|
22
|
-
* @see {@link
|
|
23
|
-
* @see {@link
|
|
21
|
+
* @see DottedPathValueObject A flattened representation of nested objects
|
|
22
|
+
* @see {@link objectToDottedPathValueObject} Utility to convert nested objects to DottedPathValueObject
|
|
23
|
+
* @see {@link dottedPathObjectToNested} Utility to convert DottedPathValueObject back to nested objects
|
|
24
24
|
*
|
|
25
25
|
* @example
|
|
26
26
|
* ```typescript
|
|
@@ -6,12 +6,12 @@
|
|
|
6
6
|
* - Keys are string paths using dot notation to represent the original object hierarchy
|
|
7
7
|
* - Values are limited to primitive types (string, number, boolean)
|
|
8
8
|
*
|
|
9
|
-
*
|
|
9
|
+
* DottedPathValueObject provides a serialization-friendly format for complex nested objects, making them
|
|
10
10
|
* easier to store, transmit, or manipulate in certain contexts (like databases, query params,
|
|
11
11
|
* or form handling).
|
|
12
12
|
*
|
|
13
13
|
* @remarks
|
|
14
|
-
* The
|
|
14
|
+
* The DottedPathValueObject format offers several benefits:
|
|
15
15
|
*
|
|
16
16
|
* - **Simplicity**: Eliminates nested structure complexity, making it easier to iterate over all properties
|
|
17
17
|
* - **Queryability**: Enables direct access to deeply nested values without traversal logic
|
|
@@ -25,13 +25,13 @@
|
|
|
25
25
|
* - Creating update operations that target specific nested properties
|
|
26
26
|
*
|
|
27
27
|
* @see {@link InfiniteObject} The complementary nested object representation
|
|
28
|
-
* @see {@link
|
|
29
|
-
* @see {@link
|
|
28
|
+
* @see {@link objectToDottedPathValueObject} Utility to convert nested objects to DottedPathValueObject
|
|
29
|
+
* @see {@link dottedPathObjectToNested} Utility to convert DottedPathValueObject back to nested objects
|
|
30
30
|
*
|
|
31
31
|
* @example
|
|
32
32
|
* ```typescript
|
|
33
|
-
* // A
|
|
34
|
-
* const userPathValues:
|
|
33
|
+
* // A DottedPathValueObject representing a nested user object
|
|
34
|
+
* const userPathValues: DottedPathValueObject = {
|
|
35
35
|
* 'id': 123,
|
|
36
36
|
* 'name': 'John Doe',
|
|
37
37
|
* 'isActive': true,
|
|
@@ -43,8 +43,8 @@
|
|
|
43
43
|
*
|
|
44
44
|
* @example
|
|
45
45
|
* ```typescript
|
|
46
|
-
* // Converting between nested objects and
|
|
47
|
-
* import {
|
|
46
|
+
* // Converting between nested objects and DottedPathValueObject
|
|
47
|
+
* import { objectToDottedPathValueObject, dottedPathObjectToNested } from './object.utils';
|
|
48
48
|
*
|
|
49
49
|
* const user = {
|
|
50
50
|
* id: 123,
|
|
@@ -58,11 +58,11 @@
|
|
|
58
58
|
* }
|
|
59
59
|
* };
|
|
60
60
|
*
|
|
61
|
-
* // Convert to
|
|
62
|
-
* const pathValues =
|
|
61
|
+
* // Convert to DottedPathValueObject
|
|
62
|
+
* const pathValues = objectToDottedPathValueObject(user);
|
|
63
63
|
*
|
|
64
64
|
* // Convert back to nested object
|
|
65
|
-
* const reconstructedUser =
|
|
65
|
+
* const reconstructedUser = dottedPathObjectToNested(pathValues);
|
|
66
66
|
* ```
|
|
67
67
|
*
|
|
68
68
|
* @example
|
|
@@ -74,6 +74,6 @@
|
|
|
74
74
|
* userPathValues['profile.address.city'] = 'Boston';
|
|
75
75
|
* ```
|
|
76
76
|
*/
|
|
77
|
-
export interface
|
|
77
|
+
export interface DottedPathValueObject {
|
|
78
78
|
[path: string]: string | number | boolean;
|
|
79
79
|
}
|
|
@@ -45,3 +45,9 @@
|
|
|
45
45
|
export type DeepPartial<T> = T | (T extends Array<infer U> ? DeepPartial<U>[] : T extends Map<infer K, infer V> ? Map<DeepPartial<K>, DeepPartial<V>> : T extends Set<infer M> ? Set<DeepPartial<M>> : T extends object ? {
|
|
46
46
|
[K in keyof T]?: DeepPartial<T[K]>;
|
|
47
47
|
} : T);
|
|
48
|
+
/**
|
|
49
|
+
* Lightweight recursive partial type for plain object filtering/comparison use-cases.
|
|
50
|
+
*/
|
|
51
|
+
export type SimpleDeepPartial<T> = {
|
|
52
|
+
[K in keyof T]?: T[K] extends object ? SimpleDeepPartial<T[K]> : T[K];
|
|
53
|
+
};
|
|
@@ -41,8 +41,8 @@
|
|
|
41
41
|
* }
|
|
42
42
|
* ```
|
|
43
43
|
*
|
|
44
|
-
* @see {@link
|
|
45
|
-
* @see {@link
|
|
44
|
+
* @see {@link objectToDottedPathValueObject} Utility that uses LiteralObject for object flattening
|
|
45
|
+
* @see {@link DottedPathValueObject} Related interface for flattened object representation
|
|
46
46
|
*/
|
|
47
47
|
export interface LiteralObject<T = any> {
|
|
48
48
|
[key: string]: T;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { InfiniteObject,
|
|
2
|
-
import { LiteralObject, PartialWithNull } from "../types";
|
|
1
|
+
import { InfiniteObject, DottedPathValueObject } from "../interfaces";
|
|
2
|
+
import { LiteralObject, PartialWithNull, SimpleDeepPartial } from "../types";
|
|
3
3
|
/**
|
|
4
4
|
* Deep copy an object.
|
|
5
5
|
* @template T Type of the object.
|
|
@@ -210,7 +210,7 @@ export declare const getMapKeys: (map: Map<string, string>, partialValue: string
|
|
|
210
210
|
* - Works with any type of grouping key (string, number, boolean, objects, etc.)
|
|
211
211
|
* - Empty arrays will return an empty Map
|
|
212
212
|
*/
|
|
213
|
-
export declare const groupBy: <K, V>(list: Array<V>, keyGetter: (input: V) => K) => Map<K
|
|
213
|
+
export declare const groupBy: <K, V>(list: Array<V>, keyGetter: (input: V) => K) => Map<K, Array<V>>;
|
|
214
214
|
/**
|
|
215
215
|
* Retrieves all values from a Map that contain a specified substring.
|
|
216
216
|
*
|
|
@@ -332,7 +332,7 @@ export declare const searchMapValues: (map: Map<string, string>, partialValue: s
|
|
|
332
332
|
*/
|
|
333
333
|
export declare const getValueByPath: <T>(obj: InfiniteObject, path: string) => T | undefined;
|
|
334
334
|
/**
|
|
335
|
-
* Converts a nested object into a flattened
|
|
335
|
+
* Converts a nested object into a flattened DottedPathValueObject representation.
|
|
336
336
|
*
|
|
337
337
|
* This function transforms a hierarchical object structure into a flat key-value map
|
|
338
338
|
* where keys represent paths to values in the original object using dot notation.
|
|
@@ -342,7 +342,7 @@ export declare const getValueByPath: <T>(obj: InfiniteObject, path: string) => T
|
|
|
342
342
|
* path-based entries like `{ 'user.name': 'John' }`.
|
|
343
343
|
*
|
|
344
344
|
* @param {LiteralObject} obj - The nested object to flatten
|
|
345
|
-
* @returns {
|
|
345
|
+
* @returns {DottedPathValueObject} - A flattened representation where:
|
|
346
346
|
* - Keys are dot-notation paths to values in the original object
|
|
347
347
|
* - Values are primitive values (strings, numbers, booleans) from the original object
|
|
348
348
|
*
|
|
@@ -351,8 +351,8 @@ export declare const getValueByPath: <T>(obj: InfiniteObject, path: string) => T
|
|
|
351
351
|
* - Only primitive values (string, number, boolean) are supported as leaf values
|
|
352
352
|
* - Circular references are not handled and will cause a stack overflow
|
|
353
353
|
*
|
|
354
|
-
* @see {@link
|
|
355
|
-
* @see {@link
|
|
354
|
+
* @see {@link dottedPathObjectToNested} The inverse operation to convert a DottedPathValueObject back to a nested object
|
|
355
|
+
* @see {@link DottedPathValueObject} The interface for the returned flattened object
|
|
356
356
|
*
|
|
357
357
|
* @example
|
|
358
358
|
* ```typescript
|
|
@@ -370,7 +370,7 @@ export declare const getValueByPath: <T>(obj: InfiniteObject, path: string) => T
|
|
|
370
370
|
* }
|
|
371
371
|
* };
|
|
372
372
|
*
|
|
373
|
-
* const flattened =
|
|
373
|
+
* const flattened = objectToDottedPathValueObject(user);
|
|
374
374
|
*
|
|
375
375
|
* // Result:
|
|
376
376
|
* // {
|
|
@@ -383,19 +383,19 @@ export declare const getValueByPath: <T>(obj: InfiniteObject, path: string) => T
|
|
|
383
383
|
* // }
|
|
384
384
|
* ```
|
|
385
385
|
*/
|
|
386
|
-
export declare function
|
|
386
|
+
export declare function objectToDottedPathValueObject(obj: LiteralObject): DottedPathValueObject;
|
|
387
387
|
/**
|
|
388
|
-
* Converts a flattened
|
|
388
|
+
* Converts a flattened DottedPathValueObject back into a nested object structure.
|
|
389
389
|
*
|
|
390
|
-
* This function is the inverse of `
|
|
390
|
+
* This function is the inverse of `objectToDottedPathValueObject`. It takes a flat map of
|
|
391
391
|
* dot-notation paths to values and reconstructs a hierarchical object structure.
|
|
392
392
|
*
|
|
393
|
-
* Each key in the input
|
|
393
|
+
* Each key in the input DottedPathValueObject represents a path through the object hierarchy,
|
|
394
394
|
* with dots separating each level. The function builds a nested object structure by
|
|
395
395
|
* parsing these paths and placing values at the appropriate locations.
|
|
396
396
|
*
|
|
397
397
|
* @template R - The type of the returned object (defaults to object)
|
|
398
|
-
* @param {
|
|
398
|
+
* @param {DottedPathValueObject} pathValueSet - A flattened object with dot-notation path keys
|
|
399
399
|
* @returns {R} - A reconstructed nested object with the original hierarchy
|
|
400
400
|
*
|
|
401
401
|
* @remarks
|
|
@@ -403,12 +403,12 @@ export declare function objectToPathValueSet(obj: LiteralObject): PathValueSet;
|
|
|
403
403
|
* - Invalid paths are silently skipped (not included in the result)
|
|
404
404
|
* - Path components should contain only alphanumeric characters, underscores, hyphens, and dots
|
|
405
405
|
*
|
|
406
|
-
* @see {@link
|
|
407
|
-
* @see {@link
|
|
406
|
+
* @see {@link objectToDottedPathValueObject} The inverse operation to convert an object to DottedPathValueObject
|
|
407
|
+
* @see {@link DottedPathValueObject} The interface for the input flattened object
|
|
408
408
|
*
|
|
409
409
|
* @example
|
|
410
410
|
* ```typescript
|
|
411
|
-
* // Convert a flat
|
|
411
|
+
* // Convert a flat DottedPathValueObject to a nested object
|
|
412
412
|
* const flatData = {
|
|
413
413
|
* "id": 123,
|
|
414
414
|
* "name": "John Doe",
|
|
@@ -417,7 +417,7 @@ export declare function objectToPathValueSet(obj: LiteralObject): PathValueSet;
|
|
|
417
417
|
* "profile.address.zip": "10001"
|
|
418
418
|
* };
|
|
419
419
|
*
|
|
420
|
-
* const nestedObject =
|
|
420
|
+
* const nestedObject = dottedPathObjectToNested(flatData);
|
|
421
421
|
*
|
|
422
422
|
* Result:
|
|
423
423
|
* // {
|
|
@@ -448,11 +448,11 @@ export declare function objectToPathValueSet(obj: LiteralObject): PathValueSet;
|
|
|
448
448
|
* };
|
|
449
449
|
* }
|
|
450
450
|
*
|
|
451
|
-
* const userData =
|
|
451
|
+
* const userData = dottedPathObjectToNested<User>(flatData);
|
|
452
452
|
* // Returns object with User type
|
|
453
453
|
* ```
|
|
454
454
|
*/
|
|
455
|
-
export declare function
|
|
455
|
+
export declare function dottedPathObjectToNested<R = object>(pathValueSet: Record<string, any>): R;
|
|
456
456
|
/**
|
|
457
457
|
* Creates a new object by omitting specified properties and undefined values from the original object.
|
|
458
458
|
*
|
|
@@ -910,3 +910,7 @@ export declare function hasOwnAll(obj: Record<PropertyKey, unknown>, props: Prop
|
|
|
910
910
|
* @see {@link Object.values} The underlying method used to extract enum entries
|
|
911
911
|
*/
|
|
912
912
|
export declare function getEnumValues<T extends object>(e: T): T[keyof T][];
|
|
913
|
+
/**
|
|
914
|
+
* Filters items by recursively matching nested property values.
|
|
915
|
+
*/
|
|
916
|
+
export declare function filterByObject<T>(items: T[], filters: SimpleDeepPartial<T>): T[];
|
package/CHANGELOG.md
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
## 0.0.1-beta.2 (2025-07-18)
|
|
2
|
-
|
|
3
|
-
This was a version bump only for utils to align it with other projects, there were no code changes.
|
|
4
|
-
|
|
5
|
-
## 0.0.1-beta.1 (2025-07-16)
|
|
6
|
-
|
|
7
|
-
This was a version bump only for utils to align it with other projects, there were no code changes.
|
|
8
|
-
|
|
9
|
-
## 0.0.1-beta.0 (2025-07-15)
|
|
10
|
-
|
|
11
|
-
This was a version bump only for utils to align it with other projects, there were no code changes.
|
|
12
|
-
|
|
13
|
-
## 0.0.1-alpha.1 (2025-06-23)
|
|
14
|
-
|
|
15
|
-
This was a version bump only for utils to align it with other projects, there were no code changes.
|
|
16
|
-
|
|
17
|
-
## 0.0.1-alpha.0 (2025-06-23)
|
|
18
|
-
|
|
19
|
-
This was a version bump only for utils to align it with other projects, there were no code changes.
|