@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,223 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base for hexadecimal number conversion
|
|
3
|
+
*
|
|
4
|
+
* This constant defines the radix (base) used for hexadecimal number conversion.
|
|
5
|
+
* The value 16 represents the standard hexadecimal numbering system (0-9, A-F).
|
|
6
|
+
* It's used in toString() and parseInt() operations involving hex values.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* // Converting a number to hexadecimal string
|
|
11
|
+
* const hexString = number.toString(HEX_RADIX);
|
|
12
|
+
*
|
|
13
|
+
* // Converting a hexadecimal string to a number
|
|
14
|
+
* const number = parseInt(hexString, HEX_RADIX);
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* @see {@link HEX_PADDING_LENGTH} Related constant for hex string formatting
|
|
18
|
+
* @see {@link HEX_PADDING_CHAR} Related constant for hex string padding
|
|
19
|
+
*/
|
|
20
|
+
export declare const HEX_RADIX = 16;
|
|
21
|
+
/**
|
|
22
|
+
* Minimum length for padded hexadecimal strings
|
|
23
|
+
*
|
|
24
|
+
* This constant defines the minimum length for hexadecimal strings after padding.
|
|
25
|
+
* It ensures that hex values have a consistent length (e.g., "0A" instead of "A").
|
|
26
|
+
* The value 2 ensures that single-digit hex values are padded with a leading zero.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```typescript
|
|
30
|
+
* // Padding a hex string to ensure consistent length
|
|
31
|
+
* const paddedHex = hexString.padStart(HEX_PADDING_LENGTH, HEX_PADDING_CHAR);
|
|
32
|
+
*
|
|
33
|
+
* // Full example with conversion and padding
|
|
34
|
+
* const byteValue = 10;
|
|
35
|
+
* const hexByte = byteValue.toString(HEX_RADIX).padStart(HEX_PADDING_LENGTH, HEX_PADDING_CHAR);
|
|
36
|
+
* // hexByte = "0A"
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
39
|
+
* @see {@link HEX_RADIX} Related constant for hex conversion
|
|
40
|
+
* @see {@link HEX_PADDING_CHAR} Related constant for the padding character
|
|
41
|
+
*/
|
|
42
|
+
export declare const HEX_PADDING_LENGTH = 2;
|
|
43
|
+
/**
|
|
44
|
+
* Character used for padding hexadecimal strings
|
|
45
|
+
*
|
|
46
|
+
* This constant defines the character used to pad hexadecimal strings to reach
|
|
47
|
+
* the minimum length defined by HEX_PADDING_LENGTH. The value "0" is the standard
|
|
48
|
+
* padding character for hexadecimal values.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```typescript
|
|
52
|
+
* // Padding a hex string with zeros
|
|
53
|
+
* const paddedHex = hexString.padStart(HEX_PADDING_LENGTH, HEX_PADDING_CHAR);
|
|
54
|
+
*
|
|
55
|
+
* // Example with a single-digit hex value
|
|
56
|
+
* const hexValue = "F";
|
|
57
|
+
* const paddedHex = hexValue.padStart(HEX_PADDING_LENGTH, HEX_PADDING_CHAR);
|
|
58
|
+
* // paddedHex = "0F"
|
|
59
|
+
* ```
|
|
60
|
+
*
|
|
61
|
+
* @see {@link HEX_RADIX} Related constant for hex conversion
|
|
62
|
+
* @see {@link HEX_PADDING_LENGTH} Related constant for the minimum length
|
|
63
|
+
*/
|
|
64
|
+
export declare const HEX_PADDING_CHAR = "0";
|
|
65
|
+
/**
|
|
66
|
+
* Number of characters to remove in string truncation operations
|
|
67
|
+
*
|
|
68
|
+
* This constant defines the default number of characters to remove when
|
|
69
|
+
* truncating strings in various utility functions. The value 2 is commonly
|
|
70
|
+
* used when removing the last two characters of a string (e.g., removing
|
|
71
|
+
* a trailing comma and space).
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```typescript
|
|
75
|
+
* // Removing trailing characters from a string
|
|
76
|
+
* const items = ["apple", "banana", "cherry"];
|
|
77
|
+
* let result = "";
|
|
78
|
+
*
|
|
79
|
+
* for (const item of items) {
|
|
80
|
+
* result += item + ", ";
|
|
81
|
+
* }
|
|
82
|
+
*
|
|
83
|
+
* // Remove trailing comma and space
|
|
84
|
+
* if (result.length > 0) {
|
|
85
|
+
* result = result.slice(0, -CHARACTERS_TO_REMOVE);
|
|
86
|
+
* }
|
|
87
|
+
* // result = "apple, banana, cherry"
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
export declare const CHARACTERS_TO_REMOVE = 2;
|
|
91
|
+
/**
|
|
92
|
+
* Default maximum line length for word wrapping
|
|
93
|
+
*
|
|
94
|
+
* This constant defines the default maximum length of a line when performing
|
|
95
|
+
* word wrapping operations. The value 80 is a common standard for line length
|
|
96
|
+
* in many text formats and terminal displays.
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* ```typescript
|
|
100
|
+
* // Wrapping a long text to the default line length
|
|
101
|
+
* function wrapText(text: string, maxLength = DEFAULT_LINE_LENGTH, breakChar = DEFAULT_BREAK_CHAR): string {
|
|
102
|
+
* // Word wrapping implementation
|
|
103
|
+
* const result = [];
|
|
104
|
+
* let line = "";
|
|
105
|
+
*
|
|
106
|
+
* for (const word of text.split(" ")) {
|
|
107
|
+
* if ((line + word).length > maxLength) {
|
|
108
|
+
* result.push(line);
|
|
109
|
+
* line = word;
|
|
110
|
+
* } else {
|
|
111
|
+
* line += (line ? " " : "") + word;
|
|
112
|
+
* }
|
|
113
|
+
* }
|
|
114
|
+
*
|
|
115
|
+
* if (line) {
|
|
116
|
+
* result.push(line);
|
|
117
|
+
* }
|
|
118
|
+
*
|
|
119
|
+
* return result.join(breakChar);
|
|
120
|
+
* }
|
|
121
|
+
* ```
|
|
122
|
+
*
|
|
123
|
+
* @see {@link DEFAULT_BREAK_CHAR} Related constant for line break character
|
|
124
|
+
*/
|
|
125
|
+
export declare const DEFAULT_LINE_LENGTH = 80;
|
|
126
|
+
/**
|
|
127
|
+
* Default line break character for word wrapping
|
|
128
|
+
*
|
|
129
|
+
* This constant defines the default character or string used to separate lines
|
|
130
|
+
* when performing word wrapping operations. The value "\n" represents a standard
|
|
131
|
+
* line feed character used for line breaks in most text formats.
|
|
132
|
+
*
|
|
133
|
+
* @example
|
|
134
|
+
* ```typescript
|
|
135
|
+
* // Using the default break character in word wrapping
|
|
136
|
+
* const wrappedText = longText.match(new RegExp(`.{1,${DEFAULT_LINE_LENGTH}}(\\s|$)`, 'g'))
|
|
137
|
+
* ?.join(DEFAULT_BREAK_CHAR) || longText;
|
|
138
|
+
* ```
|
|
139
|
+
*
|
|
140
|
+
* @see {@link DEFAULT_LINE_LENGTH} Related constant for maximum line length
|
|
141
|
+
*/
|
|
142
|
+
export declare const DEFAULT_BREAK_CHAR = "\n";
|
|
143
|
+
/**
|
|
144
|
+
* Default context length for text excerpts
|
|
145
|
+
*
|
|
146
|
+
* This constant defines the default number of characters to include before and after
|
|
147
|
+
* a search term when generating text excerpts or snippets. The value 40 provides
|
|
148
|
+
* enough context to understand the meaning while keeping the excerpt concise.
|
|
149
|
+
*
|
|
150
|
+
* @example
|
|
151
|
+
* ```typescript
|
|
152
|
+
* // Generating an excerpt around a search term
|
|
153
|
+
* function generateExcerpt(text: string, searchTerm: string): string {
|
|
154
|
+
* const index = text.toLowerCase().indexOf(searchTerm.toLowerCase());
|
|
155
|
+
* if (index === -1) return text.substring(0, DEFAULT_CONTEXT_LENGTH * 2) + DEFAULT_ELLIPSIS;
|
|
156
|
+
*
|
|
157
|
+
* const start = Math.max(0, index - DEFAULT_CONTEXT_LENGTH);
|
|
158
|
+
* const end = Math.min(text.length, index + searchTerm.length + DEFAULT_CONTEXT_LENGTH);
|
|
159
|
+
*
|
|
160
|
+
* let excerpt = text.substring(start, end);
|
|
161
|
+
* if (start > 0) excerpt = DEFAULT_ELLIPSIS + excerpt;
|
|
162
|
+
* if (end < text.length) excerpt = excerpt + DEFAULT_ELLIPSIS;
|
|
163
|
+
*
|
|
164
|
+
* return excerpt;
|
|
165
|
+
* }
|
|
166
|
+
* ```
|
|
167
|
+
*
|
|
168
|
+
* @see {@link DEFAULT_ELLIPSIS} Related constant for indicating truncated text
|
|
169
|
+
* @see {@link CONTEXT_MULTIPLIER} Related constant for adjusting context length
|
|
170
|
+
*/
|
|
171
|
+
export declare const DEFAULT_CONTEXT_LENGTH = 40;
|
|
172
|
+
/**
|
|
173
|
+
* Default ellipsis string for indicating truncated text
|
|
174
|
+
*
|
|
175
|
+
* This constant defines the default string used to indicate that text has been
|
|
176
|
+
* truncated or omitted in excerpts and summaries. The value "..." is the standard
|
|
177
|
+
* ellipsis used to represent omitted content.
|
|
178
|
+
*
|
|
179
|
+
* @example
|
|
180
|
+
* ```typescript
|
|
181
|
+
* // Truncating a long string with ellipsis
|
|
182
|
+
* function truncate(text: string, maxLength: number): string {
|
|
183
|
+
* if (text.length <= maxLength) return text;
|
|
184
|
+
* return text.substring(0, maxLength - DEFAULT_ELLIPSIS.length) + DEFAULT_ELLIPSIS;
|
|
185
|
+
* }
|
|
186
|
+
*
|
|
187
|
+
* const longText = "This is a very long text that needs to be truncated";
|
|
188
|
+
* const truncated = truncate(longText, 20);
|
|
189
|
+
* // truncated = "This is a very lo..."
|
|
190
|
+
* ```
|
|
191
|
+
*
|
|
192
|
+
* @see {@link DEFAULT_CONTEXT_LENGTH} Related constant for excerpt generation
|
|
193
|
+
*/
|
|
194
|
+
export declare const DEFAULT_ELLIPSIS = "...";
|
|
195
|
+
/**
|
|
196
|
+
* Multiplier for adjusting context length in excerpts
|
|
197
|
+
*
|
|
198
|
+
* This constant defines a multiplier used to adjust the context length when
|
|
199
|
+
* generating excerpts under different conditions. The value 2 is typically
|
|
200
|
+
* used to double the context length for certain scenarios, such as when no
|
|
201
|
+
* search term is found.
|
|
202
|
+
*
|
|
203
|
+
* @example
|
|
204
|
+
* ```typescript
|
|
205
|
+
* // Using the multiplier to adjust context length
|
|
206
|
+
* function getContextLength(hasSearchTerm: boolean): number {
|
|
207
|
+
* return hasSearchTerm
|
|
208
|
+
* ? DEFAULT_CONTEXT_LENGTH
|
|
209
|
+
* : DEFAULT_CONTEXT_LENGTH * CONTEXT_MULTIPLIER;
|
|
210
|
+
* }
|
|
211
|
+
*
|
|
212
|
+
* // Getting the first part of a text when no search term is found
|
|
213
|
+
* function getFirstPart(text: string): string {
|
|
214
|
+
* const length = DEFAULT_CONTEXT_LENGTH * CONTEXT_MULTIPLIER;
|
|
215
|
+
* return text.length > length
|
|
216
|
+
* ? text.substring(0, length) + DEFAULT_ELLIPSIS
|
|
217
|
+
* : text;
|
|
218
|
+
* }
|
|
219
|
+
* ```
|
|
220
|
+
*
|
|
221
|
+
* @see {@link DEFAULT_CONTEXT_LENGTH} Related constant for base context length
|
|
222
|
+
*/
|
|
223
|
+
export declare const CONTEXT_MULTIPLIER = 2;
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CONTEXT_MULTIPLIER = exports.DEFAULT_ELLIPSIS = exports.DEFAULT_CONTEXT_LENGTH = exports.DEFAULT_BREAK_CHAR = exports.DEFAULT_LINE_LENGTH = exports.CHARACTERS_TO_REMOVE = exports.HEX_PADDING_CHAR = exports.HEX_PADDING_LENGTH = exports.HEX_RADIX = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Base for hexadecimal number conversion
|
|
6
|
+
*
|
|
7
|
+
* This constant defines the radix (base) used for hexadecimal number conversion.
|
|
8
|
+
* The value 16 represents the standard hexadecimal numbering system (0-9, A-F).
|
|
9
|
+
* It's used in toString() and parseInt() operations involving hex values.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* // Converting a number to hexadecimal string
|
|
14
|
+
* const hexString = number.toString(HEX_RADIX);
|
|
15
|
+
*
|
|
16
|
+
* // Converting a hexadecimal string to a number
|
|
17
|
+
* const number = parseInt(hexString, HEX_RADIX);
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* @see {@link HEX_PADDING_LENGTH} Related constant for hex string formatting
|
|
21
|
+
* @see {@link HEX_PADDING_CHAR} Related constant for hex string padding
|
|
22
|
+
*/
|
|
23
|
+
exports.HEX_RADIX = 16;
|
|
24
|
+
/**
|
|
25
|
+
* Minimum length for padded hexadecimal strings
|
|
26
|
+
*
|
|
27
|
+
* This constant defines the minimum length for hexadecimal strings after padding.
|
|
28
|
+
* It ensures that hex values have a consistent length (e.g., "0A" instead of "A").
|
|
29
|
+
* The value 2 ensures that single-digit hex values are padded with a leading zero.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```typescript
|
|
33
|
+
* // Padding a hex string to ensure consistent length
|
|
34
|
+
* const paddedHex = hexString.padStart(HEX_PADDING_LENGTH, HEX_PADDING_CHAR);
|
|
35
|
+
*
|
|
36
|
+
* // Full example with conversion and padding
|
|
37
|
+
* const byteValue = 10;
|
|
38
|
+
* const hexByte = byteValue.toString(HEX_RADIX).padStart(HEX_PADDING_LENGTH, HEX_PADDING_CHAR);
|
|
39
|
+
* // hexByte = "0A"
|
|
40
|
+
* ```
|
|
41
|
+
*
|
|
42
|
+
* @see {@link HEX_RADIX} Related constant for hex conversion
|
|
43
|
+
* @see {@link HEX_PADDING_CHAR} Related constant for the padding character
|
|
44
|
+
*/
|
|
45
|
+
exports.HEX_PADDING_LENGTH = 2;
|
|
46
|
+
/**
|
|
47
|
+
* Character used for padding hexadecimal strings
|
|
48
|
+
*
|
|
49
|
+
* This constant defines the character used to pad hexadecimal strings to reach
|
|
50
|
+
* the minimum length defined by HEX_PADDING_LENGTH. The value "0" is the standard
|
|
51
|
+
* padding character for hexadecimal values.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```typescript
|
|
55
|
+
* // Padding a hex string with zeros
|
|
56
|
+
* const paddedHex = hexString.padStart(HEX_PADDING_LENGTH, HEX_PADDING_CHAR);
|
|
57
|
+
*
|
|
58
|
+
* // Example with a single-digit hex value
|
|
59
|
+
* const hexValue = "F";
|
|
60
|
+
* const paddedHex = hexValue.padStart(HEX_PADDING_LENGTH, HEX_PADDING_CHAR);
|
|
61
|
+
* // paddedHex = "0F"
|
|
62
|
+
* ```
|
|
63
|
+
*
|
|
64
|
+
* @see {@link HEX_RADIX} Related constant for hex conversion
|
|
65
|
+
* @see {@link HEX_PADDING_LENGTH} Related constant for the minimum length
|
|
66
|
+
*/
|
|
67
|
+
exports.HEX_PADDING_CHAR = "0";
|
|
68
|
+
/**
|
|
69
|
+
* Number of characters to remove in string truncation operations
|
|
70
|
+
*
|
|
71
|
+
* This constant defines the default number of characters to remove when
|
|
72
|
+
* truncating strings in various utility functions. The value 2 is commonly
|
|
73
|
+
* used when removing the last two characters of a string (e.g., removing
|
|
74
|
+
* a trailing comma and space).
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```typescript
|
|
78
|
+
* // Removing trailing characters from a string
|
|
79
|
+
* const items = ["apple", "banana", "cherry"];
|
|
80
|
+
* let result = "";
|
|
81
|
+
*
|
|
82
|
+
* for (const item of items) {
|
|
83
|
+
* result += item + ", ";
|
|
84
|
+
* }
|
|
85
|
+
*
|
|
86
|
+
* // Remove trailing comma and space
|
|
87
|
+
* if (result.length > 0) {
|
|
88
|
+
* result = result.slice(0, -CHARACTERS_TO_REMOVE);
|
|
89
|
+
* }
|
|
90
|
+
* // result = "apple, banana, cherry"
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
exports.CHARACTERS_TO_REMOVE = 2;
|
|
94
|
+
/**
|
|
95
|
+
* Default maximum line length for word wrapping
|
|
96
|
+
*
|
|
97
|
+
* This constant defines the default maximum length of a line when performing
|
|
98
|
+
* word wrapping operations. The value 80 is a common standard for line length
|
|
99
|
+
* in many text formats and terminal displays.
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* ```typescript
|
|
103
|
+
* // Wrapping a long text to the default line length
|
|
104
|
+
* function wrapText(text: string, maxLength = DEFAULT_LINE_LENGTH, breakChar = DEFAULT_BREAK_CHAR): string {
|
|
105
|
+
* // Word wrapping implementation
|
|
106
|
+
* const result = [];
|
|
107
|
+
* let line = "";
|
|
108
|
+
*
|
|
109
|
+
* for (const word of text.split(" ")) {
|
|
110
|
+
* if ((line + word).length > maxLength) {
|
|
111
|
+
* result.push(line);
|
|
112
|
+
* line = word;
|
|
113
|
+
* } else {
|
|
114
|
+
* line += (line ? " " : "") + word;
|
|
115
|
+
* }
|
|
116
|
+
* }
|
|
117
|
+
*
|
|
118
|
+
* if (line) {
|
|
119
|
+
* result.push(line);
|
|
120
|
+
* }
|
|
121
|
+
*
|
|
122
|
+
* return result.join(breakChar);
|
|
123
|
+
* }
|
|
124
|
+
* ```
|
|
125
|
+
*
|
|
126
|
+
* @see {@link DEFAULT_BREAK_CHAR} Related constant for line break character
|
|
127
|
+
*/
|
|
128
|
+
exports.DEFAULT_LINE_LENGTH = 80;
|
|
129
|
+
/**
|
|
130
|
+
* Default line break character for word wrapping
|
|
131
|
+
*
|
|
132
|
+
* This constant defines the default character or string used to separate lines
|
|
133
|
+
* when performing word wrapping operations. The value "\n" represents a standard
|
|
134
|
+
* line feed character used for line breaks in most text formats.
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* ```typescript
|
|
138
|
+
* // Using the default break character in word wrapping
|
|
139
|
+
* const wrappedText = longText.match(new RegExp(`.{1,${DEFAULT_LINE_LENGTH}}(\\s|$)`, 'g'))
|
|
140
|
+
* ?.join(DEFAULT_BREAK_CHAR) || longText;
|
|
141
|
+
* ```
|
|
142
|
+
*
|
|
143
|
+
* @see {@link DEFAULT_LINE_LENGTH} Related constant for maximum line length
|
|
144
|
+
*/
|
|
145
|
+
exports.DEFAULT_BREAK_CHAR = "\n";
|
|
146
|
+
/**
|
|
147
|
+
* Default context length for text excerpts
|
|
148
|
+
*
|
|
149
|
+
* This constant defines the default number of characters to include before and after
|
|
150
|
+
* a search term when generating text excerpts or snippets. The value 40 provides
|
|
151
|
+
* enough context to understand the meaning while keeping the excerpt concise.
|
|
152
|
+
*
|
|
153
|
+
* @example
|
|
154
|
+
* ```typescript
|
|
155
|
+
* // Generating an excerpt around a search term
|
|
156
|
+
* function generateExcerpt(text: string, searchTerm: string): string {
|
|
157
|
+
* const index = text.toLowerCase().indexOf(searchTerm.toLowerCase());
|
|
158
|
+
* if (index === -1) return text.substring(0, DEFAULT_CONTEXT_LENGTH * 2) + DEFAULT_ELLIPSIS;
|
|
159
|
+
*
|
|
160
|
+
* const start = Math.max(0, index - DEFAULT_CONTEXT_LENGTH);
|
|
161
|
+
* const end = Math.min(text.length, index + searchTerm.length + DEFAULT_CONTEXT_LENGTH);
|
|
162
|
+
*
|
|
163
|
+
* let excerpt = text.substring(start, end);
|
|
164
|
+
* if (start > 0) excerpt = DEFAULT_ELLIPSIS + excerpt;
|
|
165
|
+
* if (end < text.length) excerpt = excerpt + DEFAULT_ELLIPSIS;
|
|
166
|
+
*
|
|
167
|
+
* return excerpt;
|
|
168
|
+
* }
|
|
169
|
+
* ```
|
|
170
|
+
*
|
|
171
|
+
* @see {@link DEFAULT_ELLIPSIS} Related constant for indicating truncated text
|
|
172
|
+
* @see {@link CONTEXT_MULTIPLIER} Related constant for adjusting context length
|
|
173
|
+
*/
|
|
174
|
+
exports.DEFAULT_CONTEXT_LENGTH = 40;
|
|
175
|
+
/**
|
|
176
|
+
* Default ellipsis string for indicating truncated text
|
|
177
|
+
*
|
|
178
|
+
* This constant defines the default string used to indicate that text has been
|
|
179
|
+
* truncated or omitted in excerpts and summaries. The value "..." is the standard
|
|
180
|
+
* ellipsis used to represent omitted content.
|
|
181
|
+
*
|
|
182
|
+
* @example
|
|
183
|
+
* ```typescript
|
|
184
|
+
* // Truncating a long string with ellipsis
|
|
185
|
+
* function truncate(text: string, maxLength: number): string {
|
|
186
|
+
* if (text.length <= maxLength) return text;
|
|
187
|
+
* return text.substring(0, maxLength - DEFAULT_ELLIPSIS.length) + DEFAULT_ELLIPSIS;
|
|
188
|
+
* }
|
|
189
|
+
*
|
|
190
|
+
* const longText = "This is a very long text that needs to be truncated";
|
|
191
|
+
* const truncated = truncate(longText, 20);
|
|
192
|
+
* // truncated = "This is a very lo..."
|
|
193
|
+
* ```
|
|
194
|
+
*
|
|
195
|
+
* @see {@link DEFAULT_CONTEXT_LENGTH} Related constant for excerpt generation
|
|
196
|
+
*/
|
|
197
|
+
exports.DEFAULT_ELLIPSIS = "...";
|
|
198
|
+
/**
|
|
199
|
+
* Multiplier for adjusting context length in excerpts
|
|
200
|
+
*
|
|
201
|
+
* This constant defines a multiplier used to adjust the context length when
|
|
202
|
+
* generating excerpts under different conditions. The value 2 is typically
|
|
203
|
+
* used to double the context length for certain scenarios, such as when no
|
|
204
|
+
* search term is found.
|
|
205
|
+
*
|
|
206
|
+
* @example
|
|
207
|
+
* ```typescript
|
|
208
|
+
* // Using the multiplier to adjust context length
|
|
209
|
+
* function getContextLength(hasSearchTerm: boolean): number {
|
|
210
|
+
* return hasSearchTerm
|
|
211
|
+
* ? DEFAULT_CONTEXT_LENGTH
|
|
212
|
+
* : DEFAULT_CONTEXT_LENGTH * CONTEXT_MULTIPLIER;
|
|
213
|
+
* }
|
|
214
|
+
*
|
|
215
|
+
* // Getting the first part of a text when no search term is found
|
|
216
|
+
* function getFirstPart(text: string): string {
|
|
217
|
+
* const length = DEFAULT_CONTEXT_LENGTH * CONTEXT_MULTIPLIER;
|
|
218
|
+
* return text.length > length
|
|
219
|
+
* ? text.substring(0, length) + DEFAULT_ELLIPSIS
|
|
220
|
+
* : text;
|
|
221
|
+
* }
|
|
222
|
+
* ```
|
|
223
|
+
*
|
|
224
|
+
* @see {@link DEFAULT_CONTEXT_LENGTH} Related constant for base context length
|
|
225
|
+
*/
|
|
226
|
+
exports.CONTEXT_MULTIPLIER = 2;
|
|
227
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../libs/utils/src/constants/constants.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACU,QAAA,SAAS,GAAG,EAAE,CAAC;AAE5B;;;;;;;;;;;;;;;;;;;;GAoBG;AACU,QAAA,kBAAkB,GAAG,CAAC,CAAC;AAEpC;;;;;;;;;;;;;;;;;;;;GAoBG;AACU,QAAA,gBAAgB,GAAG,GAAG,CAAC;AAEpC;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACU,QAAA,oBAAoB,GAAG,CAAC,CAAC;AAEtC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACU,QAAA,mBAAmB,GAAG,EAAE,CAAC;AAEtC;;;;;;;;;;;;;;;GAeG;AACU,QAAA,kBAAkB,GAAG,IAAI,CAAC;AAEvC;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACU,QAAA,sBAAsB,GAAG,EAAE,CAAC;AAEzC;;;;;;;;;;;;;;;;;;;;;GAqBG;AACU,QAAA,gBAAgB,GAAG,KAAK,CAAC;AAEtC;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACU,QAAA,kBAAkB,GAAG,CAAC,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { InflectionRuleCategories } from "../interfaces";
|
|
2
|
+
/**
|
|
3
|
+
* Comprehensive rules for English word inflection (singular/plural transformations)
|
|
4
|
+
*
|
|
5
|
+
* This module provides a structured collection of rules for transforming English words
|
|
6
|
+
* between singular and plural forms. The rules are organized into categories based on
|
|
7
|
+
* linguistic patterns and exceptions, ensuring accurate transformations for various
|
|
8
|
+
* word types.
|
|
9
|
+
*
|
|
10
|
+
* Key features:
|
|
11
|
+
* - Invariant words that are identical in singular and plural forms
|
|
12
|
+
* - Irregular plural forms that don't follow standard patterns
|
|
13
|
+
* - Latin and Greek origin words with their specific plural formations
|
|
14
|
+
* - Pattern-based rules for common English word endings
|
|
15
|
+
* - Default fallback rules for standard English pluralization
|
|
16
|
+
*
|
|
17
|
+
* The rules are applied in a specific priority order, from most specific to most general,
|
|
18
|
+
* to ensure correct handling of special cases. Each rule consists of a regular expression
|
|
19
|
+
* pattern and a replacement string or function.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* // Using the rules with the plural() function
|
|
24
|
+
* import { EnglishInflectionRules } from '@hichchi/utils/constants';
|
|
25
|
+
* import { InflectionRule } from '@hichchi/utils/interfaces';
|
|
26
|
+
*
|
|
27
|
+
* function plural(word: string): string {
|
|
28
|
+
* // Combine all rules in priority order
|
|
29
|
+
* const rules: InflectionRule[] = [
|
|
30
|
+
* ...EnglishInflectionRules.INVARIANT,
|
|
31
|
+
* ...EnglishInflectionRules.IRREGULAR.toPlural,
|
|
32
|
+
* ...EnglishInflectionRules.LATIN_GREEK.toPlural,
|
|
33
|
+
* ...EnglishInflectionRules.PATTERN_RULES.toPlural,
|
|
34
|
+
* ...EnglishInflectionRules.DEFAULT.toPlural,
|
|
35
|
+
* ];
|
|
36
|
+
*
|
|
37
|
+
* // Apply the first matching rule
|
|
38
|
+
* for (const rule of rules) {
|
|
39
|
+
* if (rule.regex.test(word)) {
|
|
40
|
+
* return word.replace(rule.regex, rule.replacement as string);
|
|
41
|
+
* }
|
|
42
|
+
* }
|
|
43
|
+
*
|
|
44
|
+
* return word;
|
|
45
|
+
* }
|
|
46
|
+
* ```
|
|
47
|
+
*
|
|
48
|
+
* @see {@link plural} Function that uses these rules to convert words to plural form
|
|
49
|
+
* @see {@link singular} Function that uses these rules to convert words to singular form
|
|
50
|
+
* @see {@link InflectionRuleCategories} Interface defining the structure of the rules
|
|
51
|
+
* @see {@link InflectionRule} Interface for individual transformation rules
|
|
52
|
+
*/
|
|
53
|
+
export declare const EnglishInflectionRules: InflectionRuleCategories;
|