@hichchi/utils 0.0.1-alpha.1 → 0.0.1-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/CHANGELOG.md +9 -1
- package/README.md +6236 -1032
- package/constants/constants.d.ts +223 -0
- package/constants/constants.js +227 -0
- package/constants/constants.js.map +1 -0
- package/constants/english-inflection-rules.d.ts +53 -0
- package/constants/english-inflection-rules.js +360 -0
- package/constants/english-inflection-rules.js.map +1 -0
- package/constants/index.d.ts +2 -0
- package/constants/index.js +6 -0
- package/constants/index.js.map +1 -0
- package/enums/index.d.ts +1 -0
- package/{src → enums}/index.js +1 -1
- package/enums/index.js.map +1 -0
- package/enums/template-tag.enum.d.ts +33 -0
- package/enums/template-tag.enum.js +39 -0
- package/enums/template-tag.enum.js.map +1 -0
- package/index.d.ts +5 -0
- package/index.js +9 -0
- package/index.js.map +1 -0
- package/interfaces/index.d.ts +3 -0
- package/interfaces/index.js +7 -0
- package/interfaces/index.js.map +1 -0
- package/interfaces/infinite-object.interface.d.ts +45 -0
- package/interfaces/infinite-object.interface.js +3 -0
- package/interfaces/infinite-object.interface.js.map +1 -0
- package/interfaces/inflection-rule.interfaces.d.ts +142 -0
- package/interfaces/inflection-rule.interfaces.js +3 -0
- package/interfaces/inflection-rule.interfaces.js.map +1 -0
- package/interfaces/path-value-set.interface.d.ts +79 -0
- package/interfaces/path-value-set.interface.js +3 -0
- package/interfaces/path-value-set.interface.js.map +1 -0
- package/package.json +4 -4
- package/readme-top.md +182 -6
- package/types/deep-partial.type.d.ts +47 -0
- package/types/deep-partial.type.js +3 -0
- package/types/deep-partial.type.js.map +1 -0
- package/types/index.d.ts +34 -0
- package/types/index.js +38 -0
- package/types/index.js.map +1 -0
- package/types/is-already-in-path.type.d.ts +24 -0
- package/types/is-already-in-path.type.js +3 -0
- package/types/is-already-in-path.type.js.map +1 -0
- package/types/is-empty.type.d.ts +25 -0
- package/types/is-empty.type.js +3 -0
- package/types/is-empty.type.js.map +1 -0
- package/types/is-primitive.type.d.ts +27 -0
- package/types/is-primitive.type.js +4 -0
- package/types/is-primitive.type.js.map +1 -0
- package/types/literal-object.type.d.ts +49 -0
- package/types/literal-object.type.js +3 -0
- package/types/literal-object.type.js.map +1 -0
- package/{src/lib/types.d.ts → types/loose-autocomplete.type.d.ts} +18 -6
- package/types/loose-autocomplete.type.js +3 -0
- package/types/loose-autocomplete.type.js.map +1 -0
- package/types/partial-with-null.type.d.ts +27 -0
- package/types/partial-with-null.type.js +3 -0
- package/types/partial-with-null.type.js.map +1 -0
- package/types/prettify.type.d.ts +23 -0
- package/types/prettify.type.js +3 -0
- package/types/prettify.type.js.map +1 -0
- package/types/type.type.d.ts +21 -0
- package/{src/lib/interfaces.js → types/type.type.js} +1 -1
- package/types/type.type.js.map +1 -0
- package/utils/assertions.utils.d.ts +150 -0
- package/utils/assertions.utils.js +163 -0
- package/utils/assertions.utils.js.map +1 -0
- package/utils/file.utils.d.ts +87 -0
- package/{src/lib → utils}/file.utils.js +78 -26
- package/utils/file.utils.js.map +1 -0
- package/{src/lib → utils}/index.d.ts +3 -5
- package/{src/lib → utils}/index.js +3 -5
- package/utils/index.js.map +1 -0
- package/utils/object.utils.d.ts +912 -0
- package/utils/object.utils.js +1069 -0
- package/utils/object.utils.js.map +1 -0
- package/utils/string-template.utils.d.ts +169 -0
- package/utils/string-template.utils.js +269 -0
- package/utils/string-template.utils.js.map +1 -0
- package/utils/string.utils.d.ts +932 -0
- package/utils/string.utils.js +1255 -0
- package/utils/string.utils.js.map +1 -0
- package/utils/url.utils.d.ts +99 -0
- package/utils/url.utils.js +112 -0
- package/utils/url.utils.js.map +1 -0
- package/src/index.d.ts +0 -1
- package/src/index.js.map +0 -1
- package/src/lib/assertions.utils.d.ts +0 -55
- package/src/lib/assertions.utils.js +0 -68
- package/src/lib/assertions.utils.js.map +0 -1
- package/src/lib/file.utils.d.ts +0 -25
- package/src/lib/file.utils.js.map +0 -1
- package/src/lib/index.js.map +0 -1
- package/src/lib/interfaces.d.ts +0 -6
- package/src/lib/interfaces.js.map +0 -1
- package/src/lib/object.utils.d.ts +0 -265
- package/src/lib/object.utils.js +0 -414
- package/src/lib/object.utils.js.map +0 -1
- package/src/lib/string-template.utils.d.ts +0 -25
- package/src/lib/string-template.utils.js +0 -40
- package/src/lib/string-template.utils.js.map +0 -1
- package/src/lib/string.utils.d.ts +0 -217
- package/src/lib/string.utils.js +0 -314
- package/src/lib/string.utils.js.map +0 -1
- package/src/lib/types.js +0 -4
- package/src/lib/types.js.map +0 -1
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rule type for word inflection transformation
|
|
3
|
+
*
|
|
4
|
+
* This interface defines the structure of a single inflection rule, which consists of:
|
|
5
|
+
* - A regular expression pattern to match words that the rule applies to
|
|
6
|
+
* - A replacement string or function to transform the matched word
|
|
7
|
+
*
|
|
8
|
+
* The replacement can be either a static string with capture group references
|
|
9
|
+
* (e.g., "$1s") or a function that takes the matched string and returns the
|
|
10
|
+
* transformed version.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* // Simple string replacement rule (add 's' to the end)
|
|
15
|
+
* const pluralRule: InflectionRule = {
|
|
16
|
+
* regex: /(.*)$/i,
|
|
17
|
+
* replacement: "$1s"
|
|
18
|
+
* };
|
|
19
|
+
*
|
|
20
|
+
* // Function-based replacement rule
|
|
21
|
+
* const singularRule: InflectionRule = {
|
|
22
|
+
* regex: /(buses|dishes|matches)$/i,
|
|
23
|
+
* replacement: (match: string): string => match.slice(0, -2)
|
|
24
|
+
* };
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @see {@link PluralSingularRulePair} Interface that uses InflectionRule for rule pairs
|
|
28
|
+
* @see {@link EnglishInflectionRules} Constant that implements these rules
|
|
29
|
+
*/
|
|
30
|
+
export interface InflectionRule {
|
|
31
|
+
/**
|
|
32
|
+
* Regular expression pattern to match words this rule applies to
|
|
33
|
+
*/
|
|
34
|
+
regex: RegExp;
|
|
35
|
+
/**
|
|
36
|
+
* Replacement string with capture group references or function to transform the matched word
|
|
37
|
+
*/
|
|
38
|
+
replacement: string | ((match: string) => string);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Pair of rule sets for bidirectional singular/plural transformations
|
|
42
|
+
*
|
|
43
|
+
* This interface defines a pair of rule sets for transforming words between
|
|
44
|
+
* singular and plural forms:
|
|
45
|
+
* - toPlural: Rules for converting singular words to plural form
|
|
46
|
+
* - toSingular: Rules for converting plural words to singular form
|
|
47
|
+
*
|
|
48
|
+
* Each rule set is an array of InflectionRule objects that are applied in order
|
|
49
|
+
* until a matching rule is found.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```typescript
|
|
53
|
+
* // Rule pair for words ending in -y
|
|
54
|
+
* const yRules: PluralSingularRulePair = {
|
|
55
|
+
* toPlural: [
|
|
56
|
+
* { regex: /([^aeiou])y$/i, replacement: "$1ies" }, // city -> cities
|
|
57
|
+
* { regex: /([aeiou]y)$/i, replacement: "$1s" } // boy -> boys
|
|
58
|
+
* ],
|
|
59
|
+
* toSingular: [
|
|
60
|
+
* { regex: /([^aeiou])ies$/i, replacement: "$1y" } // cities -> city
|
|
61
|
+
* ]
|
|
62
|
+
* };
|
|
63
|
+
* ```
|
|
64
|
+
*
|
|
65
|
+
* @see {@link InflectionRule} Interface for individual transformation rules
|
|
66
|
+
* @see {@link InflectionRuleCategories} Interface that uses PluralSingularRulePair for categories
|
|
67
|
+
*/
|
|
68
|
+
export interface PluralSingularRulePair {
|
|
69
|
+
/**
|
|
70
|
+
* Array of rules for converting singular words to plural form
|
|
71
|
+
*/
|
|
72
|
+
toPlural: InflectionRule[];
|
|
73
|
+
/**
|
|
74
|
+
* Array of rules for converting plural words to singular form
|
|
75
|
+
*/
|
|
76
|
+
toSingular: InflectionRule[];
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Categories of English inflection rules
|
|
80
|
+
*
|
|
81
|
+
* This interface defines the structure for organizing English inflection rules
|
|
82
|
+
* into linguistic categories. Each category represents a different type of
|
|
83
|
+
* inflection pattern in English:
|
|
84
|
+
*
|
|
85
|
+
* - INVARIANT: Words that are the same in singular and plural form (e.g., "fish", "sheep")
|
|
86
|
+
* - IRREGULAR: Words with irregular plural forms (e.g., "child/children", "man/men")
|
|
87
|
+
* - LATIN_GREEK: Words borrowed from Latin and Greek (e.g., "cactus/cacti", "analysis/analyses")
|
|
88
|
+
* - PATTERN_RULES: Words with specific ending patterns (e.g., words ending in -y, -f, -o)
|
|
89
|
+
* - DEFAULT: Default rules for standard transformations (adding/removing 's')
|
|
90
|
+
*
|
|
91
|
+
* Rules are typically applied in the order listed above, from most specific to most general.
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```typescript
|
|
95
|
+
* // Using the categories in a word inflection function
|
|
96
|
+
* function plural(word: string): string {
|
|
97
|
+
* // Combine all rules in priority order
|
|
98
|
+
* const rules: InflectionRule[] = [
|
|
99
|
+
* ...EnglishInflectionRules.INVARIANT,
|
|
100
|
+
* ...EnglishInflectionRules.IRREGULAR.toPlural,
|
|
101
|
+
* ...EnglishInflectionRules.LATIN_GREEK.toPlural,
|
|
102
|
+
* ...EnglishInflectionRules.PATTERN_RULES.toPlural,
|
|
103
|
+
* ...EnglishInflectionRules.DEFAULT.toPlural,
|
|
104
|
+
* ];
|
|
105
|
+
*
|
|
106
|
+
* // Apply the first matching rule
|
|
107
|
+
* for (const rule of rules) {
|
|
108
|
+
* if (rule.regex.test(word)) {
|
|
109
|
+
* return word.replace(rule.regex, rule.replacement as string);
|
|
110
|
+
* }
|
|
111
|
+
* }
|
|
112
|
+
*
|
|
113
|
+
* return word;
|
|
114
|
+
* }
|
|
115
|
+
* ```
|
|
116
|
+
*
|
|
117
|
+
* @see {@link EnglishInflectionRules} Constant that implements this interface
|
|
118
|
+
* @see {@link plural} Function that uses these categories for pluralization
|
|
119
|
+
* @see {@link singular} Function that uses these categories for singularization
|
|
120
|
+
*/
|
|
121
|
+
export interface InflectionRuleCategories {
|
|
122
|
+
/**
|
|
123
|
+
* Words that are the same in singular and plural form
|
|
124
|
+
*/
|
|
125
|
+
INVARIANT: InflectionRule[];
|
|
126
|
+
/**
|
|
127
|
+
* Words with irregular plural forms
|
|
128
|
+
*/
|
|
129
|
+
IRREGULAR: PluralSingularRulePair;
|
|
130
|
+
/**
|
|
131
|
+
* Words borrowed from Latin and Greek
|
|
132
|
+
*/
|
|
133
|
+
LATIN_GREEK: PluralSingularRulePair;
|
|
134
|
+
/**
|
|
135
|
+
* Words with specific ending patterns
|
|
136
|
+
*/
|
|
137
|
+
PATTERN_RULES: PluralSingularRulePair;
|
|
138
|
+
/**
|
|
139
|
+
* Default rules for standard transformations
|
|
140
|
+
*/
|
|
141
|
+
DEFAULT: PluralSingularRulePair;
|
|
142
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inflection-rule.interfaces.js","sourceRoot":"","sources":["../../../../libs/utils/src/interfaces/inflection-rule.interfaces.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents a flattened object where keys are dot-notation paths and values are primitive types.
|
|
3
|
+
*
|
|
4
|
+
* This interface defines a data structure that transforms nested objects into a flat, key-value
|
|
5
|
+
* dictionary where:
|
|
6
|
+
* - Keys are string paths using dot notation to represent the original object hierarchy
|
|
7
|
+
* - Values are limited to primitive types (string, number, boolean)
|
|
8
|
+
*
|
|
9
|
+
* PathValueSet provides a serialization-friendly format for complex nested objects, making them
|
|
10
|
+
* easier to store, transmit, or manipulate in certain contexts (like databases, query params,
|
|
11
|
+
* or form handling).
|
|
12
|
+
*
|
|
13
|
+
* @remarks
|
|
14
|
+
* The PathValueSet format offers several benefits:
|
|
15
|
+
*
|
|
16
|
+
* - **Simplicity**: Eliminates nested structure complexity, making it easier to iterate over all properties
|
|
17
|
+
* - **Queryability**: Enables direct access to deeply nested values without traversal logic
|
|
18
|
+
* - **Serializability**: Flattened structure is more amenable to certain serialization formats
|
|
19
|
+
* - **Transformability**: Easier to apply transformations to all values regardless of nesting level
|
|
20
|
+
*
|
|
21
|
+
* Common use cases include:
|
|
22
|
+
* - Flattening complex objects for storage in key-value databases
|
|
23
|
+
* - Representing form data with nested field structures
|
|
24
|
+
* - Simplifying diff operations between complex objects
|
|
25
|
+
* - Creating update operations that target specific nested properties
|
|
26
|
+
*
|
|
27
|
+
* @see {@link InfiniteObject} The complementary nested object representation
|
|
28
|
+
* @see {@link objectToPathValueSet} Utility to convert nested objects to PathValueSet
|
|
29
|
+
* @see {@link pathValueSetToObject} Utility to convert PathValueSet back to nested objects
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```typescript
|
|
33
|
+
* // A PathValueSet representing a nested user object
|
|
34
|
+
* const userPathValues: PathValueSet = {
|
|
35
|
+
* 'id': 123,
|
|
36
|
+
* 'name': 'John Doe',
|
|
37
|
+
* 'isActive': true,
|
|
38
|
+
* 'profile.age': 30,
|
|
39
|
+
* 'profile.address.city': 'New York',
|
|
40
|
+
* 'profile.address.zip': '10001'
|
|
41
|
+
* };
|
|
42
|
+
* ```
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```typescript
|
|
46
|
+
* // Converting between nested objects and PathValueSet
|
|
47
|
+
* import { objectToPathValueSet, pathValueSetToObject } from './object.utils';
|
|
48
|
+
*
|
|
49
|
+
* const user = {
|
|
50
|
+
* id: 123,
|
|
51
|
+
* name: 'John Doe',
|
|
52
|
+
* profile: {
|
|
53
|
+
* age: 30,
|
|
54
|
+
* address: {
|
|
55
|
+
* city: 'New York',
|
|
56
|
+
* zip: '10001'
|
|
57
|
+
* }
|
|
58
|
+
* }
|
|
59
|
+
* };
|
|
60
|
+
*
|
|
61
|
+
* // Convert to PathValueSet
|
|
62
|
+
* const pathValues = objectToPathValueSet(user);
|
|
63
|
+
*
|
|
64
|
+
* // Convert back to nested object
|
|
65
|
+
* const reconstructedUser = pathValueSetToObject(pathValues);
|
|
66
|
+
* ```
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```typescript
|
|
70
|
+
* // Directly accessing a deeply nested value
|
|
71
|
+
* const cityValue = userPathValues['profile.address.city']; // 'New York'
|
|
72
|
+
*
|
|
73
|
+
* // Updating a specific nested value without touching the rest
|
|
74
|
+
* userPathValues['profile.address.city'] = 'Boston';
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
export interface PathValueSet {
|
|
78
|
+
[path: string]: string | number | boolean;
|
|
79
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"path-value-set.interface.js","sourceRoot":"","sources":["../../../../libs/utils/src/interfaces/path-value-set.interface.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hichchi/utils",
|
|
3
|
-
"version": "0.0.1-
|
|
3
|
+
"version": "0.0.1-beta.1",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -11,12 +11,12 @@
|
|
|
11
11
|
"keywords": [],
|
|
12
12
|
"author": "Waruna Udayanga",
|
|
13
13
|
"license": "MIT",
|
|
14
|
-
"main": "./
|
|
15
|
-
"typings": "./
|
|
14
|
+
"main": "./index.js",
|
|
15
|
+
"typings": "./index.d.ts",
|
|
16
16
|
"sideEffects": false,
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"tslib": "^2.3.0"
|
|
19
19
|
},
|
|
20
|
-
"types": "./
|
|
20
|
+
"types": "./index.d.ts",
|
|
21
21
|
"type": "commonjs"
|
|
22
22
|
}
|
package/readme-top.md
CHANGED
|
@@ -1,11 +1,187 @@
|
|
|
1
|
-
|
|
1
|
+
<!--suppress ALL -->
|
|
2
|
+
<div align="center">
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
# 🛠️ @hichchi/utils
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
**A comprehensive utility library with essential helper functions for JavaScript/TypeScript applications**
|
|
6
7
|
|
|
7
|
-
|
|
8
|
+
[](https://www.npmjs.com/package/@hichchi/utils)
|
|
9
|
+
[](https://www.npmjs.com/package/@hichchi/utils)
|
|
10
|
+
[](https://github.com/hichchidev/hichchi/blob/main/LICENSE)
|
|
11
|
+
[](https://www.typescriptlang.org/)
|
|
8
12
|
|
|
9
|
-
|
|
13
|
+
*Part of the [Hichchi](https://github.com/hichchidev/hichchi) ecosystem - A powerful, scalable application built with Nx workspace*
|
|
10
14
|
|
|
11
|
-
|
|
15
|
+
[📚 Jump to Documentation](#-api-documentation)
|
|
16
|
+
|
|
17
|
+
</div>
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## 📋 Table Of Contents
|
|
22
|
+
|
|
23
|
+
- [📦 Installation](#-installation)
|
|
24
|
+
- [⚡ Quick Start](#-quick-start)
|
|
25
|
+
- [📋 Prerequisites](#-prerequisites)
|
|
26
|
+
- [🌟 Overview](#-overview)
|
|
27
|
+
- [✨ Features](#-features)
|
|
28
|
+
- [🛠️ Troubleshooting](#️-troubleshooting)
|
|
29
|
+
- [🔧 Development](#-development)
|
|
30
|
+
- [📖 API Documentation](#-api-documentation)
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## 📦 Installation
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
npm install @hichchi/utils
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## ⚡ Quick Start
|
|
41
|
+
|
|
42
|
+
Get up and running with powerful utility functions in just a few minutes:
|
|
43
|
+
|
|
44
|
+
```typescript
|
|
45
|
+
// 1. Install the package
|
|
46
|
+
npm install @hichchi/utils
|
|
47
|
+
|
|
48
|
+
// 2. Import utility functions
|
|
49
|
+
import { pathValueSetToObject } from '@hichchi/utils';
|
|
50
|
+
|
|
51
|
+
// 3. Use utility functions in your application
|
|
52
|
+
const nestedObject = pathValueSetToObject({
|
|
53
|
+
"id": 123,
|
|
54
|
+
"name": "John Doe",
|
|
55
|
+
"profile.age": 30,
|
|
56
|
+
"profile.address.city": "New York",
|
|
57
|
+
"profile.address.zip": "10001"
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
Result:
|
|
61
|
+
// {
|
|
62
|
+
// id: 123,
|
|
63
|
+
// name: "John Doe",
|
|
64
|
+
// profile: {
|
|
65
|
+
// age: 30,
|
|
66
|
+
// address: {
|
|
67
|
+
// city: "New York",
|
|
68
|
+
// zip: "10001"
|
|
69
|
+
// }
|
|
70
|
+
// }
|
|
71
|
+
// }
|
|
72
|
+
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## 📋 Prerequisites
|
|
76
|
+
|
|
77
|
+
Before installing @hichchi/utils, ensure you have:
|
|
78
|
+
|
|
79
|
+
### Required Dependencies
|
|
80
|
+
- **Node.js**: >= 18.0.0
|
|
81
|
+
- **TypeScript**: >= 5.0.0 (for TypeScript projects)
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
## 🌟 Overview
|
|
85
|
+
|
|
86
|
+
🎯 **Your essential toolkit** for JavaScript and TypeScript development. From string manipulation to file operations, from object utilities to URL handling - everything you need to streamline your development workflow with battle-tested, performance-optimized utility functions.
|
|
87
|
+
|
|
88
|
+
## ✨ Features
|
|
89
|
+
|
|
90
|
+
### 🔤 String Utilities
|
|
91
|
+
- 🎨 **Case Conversion** - camelCase, PascalCase, snake_case, kebab-case transformations
|
|
92
|
+
- 🔍 **String Analysis** - Pattern matching, validation, and content analysis
|
|
93
|
+
- ✂️ **String Manipulation** - Truncation, padding, cleaning, and formatting
|
|
94
|
+
- 🏷️ **Slug Generation** - URL-friendly string generation with customizable options
|
|
95
|
+
- 📝 **Template Processing** - Advanced string templating with variable substitution
|
|
96
|
+
|
|
97
|
+
### 🗂️ Object Utilities
|
|
98
|
+
- 🔄 **Deep Operations** - Deep merge, clone, compare, and transformation
|
|
99
|
+
- 🎯 **Property Access** - Safe property getting/setting with dot notation
|
|
100
|
+
- 🔍 **Object Analysis** - Type checking, validation, and structure analysis
|
|
101
|
+
- 📊 **Data Transformation** - Object flattening, nesting, and restructuring
|
|
102
|
+
- 🧹 **Object Cleaning** - Remove null/undefined values, empty objects
|
|
103
|
+
|
|
104
|
+
### 📝 String Template Utilities
|
|
105
|
+
- 🎨 **Template Processing** - Advanced string templating with variable substitution
|
|
106
|
+
- 🔄 **Dynamic Content** - Apply templates with custom prefixes and transformations
|
|
107
|
+
- 🏷️ **Tag-based Processing** - Support for various template tags and formats
|
|
108
|
+
|
|
109
|
+
### 🌐 URL Utilities
|
|
110
|
+
- 🔒 **Redirect Validation** - Secure redirect URL validation against allowed domains
|
|
111
|
+
- 🛡️ **Security Features** - Prevent open redirect vulnerabilities
|
|
112
|
+
|
|
113
|
+
### ✅ Assertion Utilities
|
|
114
|
+
- 🔍 **Type Guards** - TypeScript type guards for arrays and objects
|
|
115
|
+
- 🎯 **Property Checking** - Check if objects have specific properties
|
|
116
|
+
- 🛡️ **Safe Type Narrowing** - Runtime type validation with TypeScript support
|
|
117
|
+
|
|
118
|
+
### 🎨 Developer Experience
|
|
119
|
+
- 📝 **Full TypeScript Support** - Complete type definitions and IntelliSense
|
|
120
|
+
- 🔧 **Tree Shaking** - Import only what you need for optimal bundle size
|
|
121
|
+
- 📚 **Comprehensive Documentation** - Detailed JSDoc comments for all functions
|
|
122
|
+
- 🧪 **Well Tested** - Extensive test coverage for reliability
|
|
123
|
+
- 🚀 **Performance Optimized** - Efficient algorithms and minimal overhead
|
|
124
|
+
|
|
125
|
+
## 🔒 Security Best Practices
|
|
126
|
+
|
|
127
|
+
Detailed security best practices will be added here
|
|
128
|
+
|
|
129
|
+
## 🛠️ Troubleshooting
|
|
130
|
+
|
|
131
|
+
### Common Issues
|
|
132
|
+
|
|
133
|
+
#### TypeScript Compilation Issues
|
|
134
|
+
```bash
|
|
135
|
+
# Ensure you have the correct TypeScript version
|
|
136
|
+
npm install typescript@^5.0.0 --save-dev
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
## 🔧 Development
|
|
140
|
+
|
|
141
|
+
### Building the Library
|
|
142
|
+
```bash
|
|
143
|
+
nx build utils
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
### Running Tests
|
|
147
|
+
```bash
|
|
148
|
+
nx test utils
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### Linting
|
|
152
|
+
```bash
|
|
153
|
+
nx lint utils
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
### Performance Testing
|
|
157
|
+
```bash
|
|
158
|
+
nx run utils:benchmark
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
---
|
|
162
|
+
|
|
163
|
+
<div align="center">
|
|
164
|
+
|
|
165
|
+
**Made with ❤️ by [Hichchi Dev](https://github.com/hichchidev)**
|
|
166
|
+
|
|
167
|
+
[](https://github.com/hichchidev/hichchi)
|
|
168
|
+
[](https://github.com/hichchidev/hichchi/issues)
|
|
169
|
+
[](https://github.com/hichchidev/hichchi/issues)
|
|
170
|
+
|
|
171
|
+
*Building the future of development utilities, one commit at a time*
|
|
172
|
+
|
|
173
|
+
</div>
|
|
174
|
+
|
|
175
|
+
---
|
|
176
|
+
|
|
177
|
+
# 📖 API Documentation
|
|
178
|
+
|
|
179
|
+
Complete technical reference for all classes, interfaces, methods, and types in this library.
|
|
180
|
+
|
|
181
|
+
**Auto-generated by TypeDoc** - Browse through detailed API references, code examples, and implementation guides below.
|
|
182
|
+
|
|
183
|
+
<!-- TypeDoc generated documentation will be appended below this point -->
|
|
184
|
+
|
|
185
|
+
---
|
|
186
|
+
|
|
187
|
+
## 📋 API Table of Contents
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A utility type that recursively makes all properties of an object optional.
|
|
3
|
+
*
|
|
4
|
+
* Unlike TypeScript's built-in `Partial<T>` type which only makes top-level properties
|
|
5
|
+
* optional, `DeepPartial<T>` recursively applies the transformation to nested objects,
|
|
6
|
+
* arrays, maps, and sets. This makes it ideal for working with complex nested data
|
|
7
|
+
* structures where you only want to provide a subset of the data.
|
|
8
|
+
*
|
|
9
|
+
* Features:
|
|
10
|
+
* - Makes all object properties optional at every level of nesting
|
|
11
|
+
* - Handles arrays by making each element a deep partial
|
|
12
|
+
* - Supports Map objects by making both keys and values deep partials
|
|
13
|
+
* - Supports Set objects by making each member a deep partial
|
|
14
|
+
* - Preserves primitive values unchanged
|
|
15
|
+
*
|
|
16
|
+
* Common use cases:
|
|
17
|
+
* - Creating update DTOs where only changed fields need to be provided
|
|
18
|
+
* - Building test fixtures with minimal required properties
|
|
19
|
+
* - Implementing patch operations for REST APIs
|
|
20
|
+
* - Constructing partial configuration objects
|
|
21
|
+
*
|
|
22
|
+
* @template T The type to transform into a deep partial
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* interface User {
|
|
27
|
+
* id: string;
|
|
28
|
+
* name: string;
|
|
29
|
+
* profile: {
|
|
30
|
+
* avatar: string;
|
|
31
|
+
* preferences: {
|
|
32
|
+
* theme: string;
|
|
33
|
+
* notifications: boolean;
|
|
34
|
+
* };
|
|
35
|
+
* };
|
|
36
|
+
* roles: string[];
|
|
37
|
+
* }
|
|
38
|
+
*
|
|
39
|
+
* // All these are valid DeepPartial<User>
|
|
40
|
+
* const update1: DeepPartial<User> = { name: 'New Name' };
|
|
41
|
+
* const update2: DeepPartial<User> = { profile: { preferences: { theme: 'dark' } } };
|
|
42
|
+
* const update3: DeepPartial<User> = { roles: ['admin'] };
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
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
|
+
[K in keyof T]?: DeepPartial<T[K]>;
|
|
47
|
+
} : T);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deep-partial.type.js","sourceRoot":"","sources":["../../../../libs/utils/src/types/deep-partial.type.ts"],"names":[],"mappings":""}
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility types for TypeScript development
|
|
3
|
+
*
|
|
4
|
+
* This module exports a collection of utility types that enhance TypeScript's
|
|
5
|
+
* type system with additional functionality. These types help with common
|
|
6
|
+
* type manipulation tasks and provide solutions for advanced typing scenarios.
|
|
7
|
+
*
|
|
8
|
+
* Key categories of types included:
|
|
9
|
+
* - Object type utilities (DeepPartial, PartialWithNull, LiteralObject)
|
|
10
|
+
* - Type predicates (IsEmpty, IsPrimitive, IsAlreadyInPath)
|
|
11
|
+
* - Type transformation utilities (Prettify, LooseAutocomplete)
|
|
12
|
+
* - Constructor and class utilities (Type)
|
|
13
|
+
*
|
|
14
|
+
* Import these types individually or from this barrel file to enhance
|
|
15
|
+
* your TypeScript code with more expressive and precise type definitions.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* // Import all types
|
|
20
|
+
* import * as Types from '@hichchi/utils/types';
|
|
21
|
+
*
|
|
22
|
+
* // Or import specific types
|
|
23
|
+
* import { DeepPartial, LiteralObject } from '@hichchi/utils/types';
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export * from "./type.type";
|
|
27
|
+
export * from "./is-empty.type";
|
|
28
|
+
export * from "./prettify.type";
|
|
29
|
+
export * from "./deep-partial.type";
|
|
30
|
+
export * from "./is-primitive.type";
|
|
31
|
+
export * from "./literal-object.type";
|
|
32
|
+
export * from "./partial-with-null.type";
|
|
33
|
+
export * from "./is-already-in-path.type";
|
|
34
|
+
export * from "./loose-autocomplete.type";
|
package/types/index.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
/**
|
|
5
|
+
* Utility types for TypeScript development
|
|
6
|
+
*
|
|
7
|
+
* This module exports a collection of utility types that enhance TypeScript's
|
|
8
|
+
* type system with additional functionality. These types help with common
|
|
9
|
+
* type manipulation tasks and provide solutions for advanced typing scenarios.
|
|
10
|
+
*
|
|
11
|
+
* Key categories of types included:
|
|
12
|
+
* - Object type utilities (DeepPartial, PartialWithNull, LiteralObject)
|
|
13
|
+
* - Type predicates (IsEmpty, IsPrimitive, IsAlreadyInPath)
|
|
14
|
+
* - Type transformation utilities (Prettify, LooseAutocomplete)
|
|
15
|
+
* - Constructor and class utilities (Type)
|
|
16
|
+
*
|
|
17
|
+
* Import these types individually or from this barrel file to enhance
|
|
18
|
+
* your TypeScript code with more expressive and precise type definitions.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* // Import all types
|
|
23
|
+
* import * as Types from '@hichchi/utils/types';
|
|
24
|
+
*
|
|
25
|
+
* // Or import specific types
|
|
26
|
+
* import { DeepPartial, LiteralObject } from '@hichchi/utils/types';
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
tslib_1.__exportStar(require("./type.type"), exports);
|
|
30
|
+
tslib_1.__exportStar(require("./is-empty.type"), exports);
|
|
31
|
+
tslib_1.__exportStar(require("./prettify.type"), exports);
|
|
32
|
+
tslib_1.__exportStar(require("./deep-partial.type"), exports);
|
|
33
|
+
tslib_1.__exportStar(require("./is-primitive.type"), exports);
|
|
34
|
+
tslib_1.__exportStar(require("./literal-object.type"), exports);
|
|
35
|
+
tslib_1.__exportStar(require("./partial-with-null.type"), exports);
|
|
36
|
+
tslib_1.__exportStar(require("./is-already-in-path.type"), exports);
|
|
37
|
+
tslib_1.__exportStar(require("./loose-autocomplete.type"), exports);
|
|
38
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../libs/utils/src/types/index.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,sDAA4B;AAC5B,0DAAgC;AAChC,0DAAgC;AAChC,8DAAoC;AACpC,8DAAoC;AACpC,gEAAsC;AACtC,mEAAyC;AACzC,oEAA0C;AAC1C,oEAA0C"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type predicate that detects circular references in type paths.
|
|
3
|
+
*
|
|
4
|
+
* The `IsAlreadyInPath` type evaluates to `true` if type T is already part of the path U,
|
|
5
|
+
* indicating a potential circular reference. It returns `false` otherwise.
|
|
6
|
+
*
|
|
7
|
+
* This utility type is crucial for preventing infinite recursion in recursive type
|
|
8
|
+
* definitions, particularly when working with deeply nested structures or graphs.
|
|
9
|
+
*
|
|
10
|
+
* @template T The type to check if it's in the path
|
|
11
|
+
* @template U The current path of types
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* // Example usage in a recursive type definition
|
|
16
|
+
* type RecursivelyProcess<T, Path = never> =
|
|
17
|
+
* IsAlreadyInPath<T, Path> extends true
|
|
18
|
+
* ? any // Break recursion to prevent infinite type expansion
|
|
19
|
+
* : T extends object
|
|
20
|
+
* ? { [K in keyof T]: RecursivelyProcess<T[K], Path | T> }
|
|
21
|
+
* : T;
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export type IsAlreadyInPath<T, U> = U extends object ? (T extends U ? true : false) : false;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-already-in-path.type.js","sourceRoot":"","sources":["../../../../libs/utils/src/types/is-already-in-path.type.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type predicate that determines if a type is an empty object type.
|
|
3
|
+
*
|
|
4
|
+
* The `IsEmpty` type evaluates to `true` if the provided type T has no properties
|
|
5
|
+
* (i.e., it is an empty object type), and `false` otherwise. This is determined by
|
|
6
|
+
* checking if `keyof T extends never`.
|
|
7
|
+
*
|
|
8
|
+
* This utility type is useful for conditional types that need special handling
|
|
9
|
+
* for empty objects versus objects with properties.
|
|
10
|
+
*
|
|
11
|
+
* @template T The type to check
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* // Example with conditional types
|
|
16
|
+
* type ProcessObject<T> = IsEmpty<T> extends true
|
|
17
|
+
* ? { defaultProp: string } // Provide default for empty objects
|
|
18
|
+
* : T; // Keep non-empty objects as-is
|
|
19
|
+
*
|
|
20
|
+
* // Usage
|
|
21
|
+
* type ProcessedEmpty = ProcessObject<{}>; // { defaultProp: string }
|
|
22
|
+
* type ProcessedNonEmpty = ProcessObject<{ name: string }>; // { name: string }
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export type IsEmpty<T> = keyof T extends never ? true : false;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-empty.type.js","sourceRoot":"","sources":["../../../../libs/utils/src/types/is-empty.type.ts"],"names":[],"mappings":""}
|