@develia/commons 0.4.12 → 0.4.14
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/dist/cjs/array.js +4 -5
- package/dist/cjs/array.js.map +1 -1
- package/dist/cjs/async-pool-executor.js +0 -0
- package/dist/cjs/async-pool-executor.js.map +0 -0
- package/dist/cjs/browser/form-utilities.js +12 -12
- package/dist/cjs/browser/form-utilities.js.map +1 -1
- package/dist/cjs/browser/geo-location.js +1 -1
- package/dist/cjs/browser/geo-location.js.map +1 -1
- package/dist/cjs/browser/index.js +30 -2
- package/dist/cjs/browser/index.js.map +1 -1
- package/dist/cjs/browser/native-bridge.js +0 -0
- package/dist/cjs/browser/native-bridge.js.map +0 -0
- package/dist/cjs/cancellable-promise.js +0 -0
- package/dist/cjs/cancellable-promise.js.map +0 -0
- package/dist/cjs/clean-url-search-params.js +0 -0
- package/dist/cjs/clean-url-search-params.js.map +0 -0
- package/dist/cjs/collections/cache-dictionary.js +0 -0
- package/dist/cjs/collections/cache-dictionary.js.map +0 -0
- package/dist/cjs/collections/default-map.js +0 -0
- package/dist/cjs/collections/default-map.js.map +0 -0
- package/dist/cjs/collections/default-weak-map.js +0 -0
- package/dist/cjs/collections/default-weak-map.js.map +0 -0
- package/dist/cjs/collections/index.js +0 -0
- package/dist/cjs/collections/index.js.map +0 -0
- package/dist/cjs/draft.js +153 -0
- package/dist/cjs/draft.js.map +1 -0
- package/dist/cjs/event-bus.js +0 -0
- package/dist/cjs/event-bus.js.map +0 -0
- package/dist/cjs/from.js +1 -1
- package/dist/cjs/from.js.map +1 -1
- package/dist/cjs/index.js +3 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/key-value-pair.js +0 -0
- package/dist/cjs/key-value-pair.js.map +0 -0
- package/dist/cjs/lazy.js +0 -0
- package/dist/cjs/lazy.js.map +0 -0
- package/dist/cjs/math.js +2 -3
- package/dist/cjs/math.js.map +1 -1
- package/dist/cjs/order.js +0 -0
- package/dist/cjs/order.js.map +0 -0
- package/dist/cjs/parse.js +3 -4
- package/dist/cjs/parse.js.map +1 -1
- package/dist/cjs/patch.js +2 -3
- package/dist/cjs/patch.js.map +1 -1
- package/dist/cjs/stopwatch.js +0 -0
- package/dist/cjs/stopwatch.js.map +0 -0
- package/dist/cjs/string.js +8 -9
- package/dist/cjs/string.js.map +1 -1
- package/dist/cjs/timer.js +0 -0
- package/dist/cjs/timer.js.map +0 -0
- package/dist/cjs/timespan.js +0 -0
- package/dist/cjs/timespan.js.map +0 -0
- package/dist/cjs/type-code.js +0 -0
- package/dist/cjs/type-code.js.map +0 -0
- package/dist/cjs/type.js +0 -0
- package/dist/cjs/type.js.map +0 -0
- package/dist/cjs/types.js +0 -0
- package/dist/cjs/types.js.map +0 -0
- package/dist/cjs/utilities.js +106 -57
- package/dist/cjs/utilities.js.map +1 -1
- package/dist/esm/array.js +0 -0
- package/dist/esm/array.js.map +0 -0
- package/dist/esm/async-pool-executor.js +0 -0
- package/dist/esm/async-pool-executor.js.map +0 -0
- package/dist/esm/browser/form-utilities.js +7 -6
- package/dist/esm/browser/form-utilities.js.map +1 -1
- package/dist/esm/browser/geo-location.js +0 -0
- package/dist/esm/browser/geo-location.js.map +0 -0
- package/dist/esm/browser/index.js +27 -0
- package/dist/esm/browser/index.js.map +1 -1
- package/dist/esm/browser/native-bridge.js +0 -0
- package/dist/esm/browser/native-bridge.js.map +0 -0
- package/dist/esm/cancellable-promise.js +0 -0
- package/dist/esm/cancellable-promise.js.map +0 -0
- package/dist/esm/clean-url-search-params.js +0 -0
- package/dist/esm/clean-url-search-params.js.map +0 -0
- package/dist/esm/collections/cache-dictionary.js +0 -0
- package/dist/esm/collections/cache-dictionary.js.map +0 -0
- package/dist/esm/collections/default-map.js +0 -0
- package/dist/esm/collections/default-map.js.map +0 -0
- package/dist/esm/collections/default-weak-map.js +0 -0
- package/dist/esm/collections/default-weak-map.js.map +0 -0
- package/dist/esm/collections/index.js +0 -0
- package/dist/esm/collections/index.js.map +0 -0
- package/dist/esm/draft.js +150 -0
- package/dist/esm/draft.js.map +1 -0
- package/dist/esm/event-bus.js +0 -0
- package/dist/esm/event-bus.js.map +0 -0
- package/dist/esm/from.js +0 -0
- package/dist/esm/from.js.map +0 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/key-value-pair.js +0 -0
- package/dist/esm/key-value-pair.js.map +0 -0
- package/dist/esm/lazy.js +0 -0
- package/dist/esm/lazy.js.map +0 -0
- package/dist/esm/math.js +0 -0
- package/dist/esm/math.js.map +0 -0
- package/dist/esm/order.js +0 -0
- package/dist/esm/order.js.map +0 -0
- package/dist/esm/parse.js +0 -0
- package/dist/esm/parse.js.map +0 -0
- package/dist/esm/patch.js +0 -0
- package/dist/esm/patch.js.map +0 -0
- package/dist/esm/stopwatch.js +0 -0
- package/dist/esm/stopwatch.js.map +0 -0
- package/dist/esm/string.js +0 -0
- package/dist/esm/string.js.map +0 -0
- package/dist/esm/timer.js +0 -0
- package/dist/esm/timer.js.map +0 -0
- package/dist/esm/timespan.js +0 -0
- package/dist/esm/timespan.js.map +0 -0
- package/dist/esm/type-code.js +0 -0
- package/dist/esm/type-code.js.map +0 -0
- package/dist/esm/type.js +0 -0
- package/dist/esm/type.js.map +0 -0
- package/dist/esm/types.js +0 -0
- package/dist/esm/types.js.map +0 -0
- package/dist/esm/utilities.js +81 -32
- package/dist/esm/utilities.js.map +1 -1
- package/dist/types/array.d.ts +0 -0
- package/dist/types/array.d.ts.map +0 -0
- package/dist/types/async-pool-executor.d.ts +0 -0
- package/dist/types/async-pool-executor.d.ts.map +0 -0
- package/dist/types/browser/form-utilities.d.ts +0 -0
- package/dist/types/browser/form-utilities.d.ts.map +1 -1
- package/dist/types/browser/geo-location.d.ts +0 -0
- package/dist/types/browser/geo-location.d.ts.map +0 -0
- package/dist/types/browser/index.d.ts +3 -0
- package/dist/types/browser/index.d.ts.map +1 -1
- package/dist/types/browser/native-bridge.d.ts +0 -0
- package/dist/types/browser/native-bridge.d.ts.map +0 -0
- package/dist/types/cancellable-promise.d.ts +0 -0
- package/dist/types/cancellable-promise.d.ts.map +0 -0
- package/dist/types/clean-url-search-params.d.ts +0 -0
- package/dist/types/clean-url-search-params.d.ts.map +0 -0
- package/dist/types/collections/cache-dictionary.d.ts +0 -0
- package/dist/types/collections/cache-dictionary.d.ts.map +0 -0
- package/dist/types/collections/default-map.d.ts +0 -0
- package/dist/types/collections/default-map.d.ts.map +0 -0
- package/dist/types/collections/default-weak-map.d.ts +0 -0
- package/dist/types/collections/default-weak-map.d.ts.map +0 -0
- package/dist/types/collections/index.d.ts +0 -0
- package/dist/types/collections/index.d.ts.map +0 -0
- package/dist/types/draft.d.ts +17 -0
- package/dist/types/draft.d.ts.map +1 -0
- package/dist/types/event-bus.d.ts +0 -0
- package/dist/types/event-bus.d.ts.map +0 -0
- package/dist/types/from.d.ts +0 -0
- package/dist/types/from.d.ts.map +0 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/key-value-pair.d.ts +0 -0
- package/dist/types/key-value-pair.d.ts.map +0 -0
- package/dist/types/lazy.d.ts +0 -0
- package/dist/types/lazy.d.ts.map +0 -0
- package/dist/types/math.d.ts +0 -0
- package/dist/types/math.d.ts.map +0 -0
- package/dist/types/order.d.ts +0 -0
- package/dist/types/order.d.ts.map +0 -0
- package/dist/types/parse.d.ts +0 -0
- package/dist/types/parse.d.ts.map +0 -0
- package/dist/types/patch.d.ts +0 -0
- package/dist/types/patch.d.ts.map +0 -0
- package/dist/types/stopwatch.d.ts +0 -0
- package/dist/types/stopwatch.d.ts.map +0 -0
- package/dist/types/string.d.ts +0 -0
- package/dist/types/string.d.ts.map +0 -0
- package/dist/types/timer.d.ts +0 -0
- package/dist/types/timer.d.ts.map +0 -0
- package/dist/types/timespan.d.ts +0 -0
- package/dist/types/timespan.d.ts.map +0 -0
- package/dist/types/type-code.d.ts +0 -0
- package/dist/types/type-code.d.ts.map +0 -0
- package/dist/types/type.d.ts +0 -0
- package/dist/types/type.d.ts.map +0 -0
- package/dist/types/types.d.ts +0 -0
- package/dist/types/types.d.ts.map +0 -0
- package/dist/types/utilities.d.ts +3 -2
- package/dist/types/utilities.d.ts.map +1 -1
- package/dist/web/array.js +0 -0
- package/dist/web/array.js.map +0 -0
- package/dist/web/async-pool-executor.js +0 -0
- package/dist/web/async-pool-executor.js.map +0 -0
- package/dist/web/browser/form-utilities.js +7 -6
- package/dist/web/browser/form-utilities.js.map +1 -1
- package/dist/web/browser/geo-location.js +0 -0
- package/dist/web/browser/geo-location.js.map +0 -0
- package/dist/web/browser/index.js +27 -0
- package/dist/web/browser/index.js.map +1 -1
- package/dist/web/browser/native-bridge.js +0 -0
- package/dist/web/browser/native-bridge.js.map +0 -0
- package/dist/web/cancellable-promise.js +0 -0
- package/dist/web/cancellable-promise.js.map +0 -0
- package/dist/web/clean-url-search-params.js +0 -0
- package/dist/web/clean-url-search-params.js.map +0 -0
- package/dist/web/collections/cache-dictionary.js +0 -0
- package/dist/web/collections/cache-dictionary.js.map +0 -0
- package/dist/web/collections/default-map.js +0 -0
- package/dist/web/collections/default-map.js.map +0 -0
- package/dist/web/collections/default-weak-map.js +0 -0
- package/dist/web/collections/default-weak-map.js.map +0 -0
- package/dist/web/collections/index.js +0 -0
- package/dist/web/collections/index.js.map +0 -0
- package/dist/web/draft.js +150 -0
- package/dist/web/draft.js.map +1 -0
- package/dist/web/event-bus.js +0 -0
- package/dist/web/event-bus.js.map +0 -0
- package/dist/web/from.js +0 -0
- package/dist/web/from.js.map +0 -0
- package/dist/web/index.js +1 -0
- package/dist/web/index.js.map +1 -1
- package/dist/web/key-value-pair.js +0 -0
- package/dist/web/key-value-pair.js.map +0 -0
- package/dist/web/lazy.js +0 -0
- package/dist/web/lazy.js.map +0 -0
- package/dist/web/math.js +0 -0
- package/dist/web/math.js.map +0 -0
- package/dist/web/order.js +0 -0
- package/dist/web/order.js.map +0 -0
- package/dist/web/parse.js +0 -0
- package/dist/web/parse.js.map +0 -0
- package/dist/web/patch.js +0 -0
- package/dist/web/patch.js.map +0 -0
- package/dist/web/stopwatch.js +0 -0
- package/dist/web/stopwatch.js.map +0 -0
- package/dist/web/string.js +0 -0
- package/dist/web/string.js.map +0 -0
- package/dist/web/timer.js +0 -0
- package/dist/web/timer.js.map +0 -0
- package/dist/web/timespan.js +0 -0
- package/dist/web/timespan.js.map +0 -0
- package/dist/web/type-code.js +0 -0
- package/dist/web/type-code.js.map +0 -0
- package/dist/web/type.js +0 -0
- package/dist/web/type.js.map +0 -0
- package/dist/web/types.js +0 -0
- package/dist/web/types.js.map +0 -0
- package/dist/web/utilities.js +81 -32
- package/dist/web/utilities.js.map +1 -1
- package/package.json +60 -56
- package/src/browser/form-utilities.ts +7 -6
- package/src/browser/geo-location.ts +113 -113
- package/src/browser/index.ts +37 -0
- package/src/browser/native-bridge.ts +116 -116
- package/src/cancellable-promise.ts +76 -76
- package/src/collections/index.ts +2 -2
- package/src/draft.ts +268 -0
- package/src/event-bus.ts +83 -83
- package/src/index.ts +42 -37
- package/src/parse.ts +240 -240
- package/src/string.ts +128 -128
- package/src/type-code.ts +15 -15
- package/src/type.ts +371 -371
- package/src/types.ts +30 -30
- package/src/utilities.ts +480 -404
package/src/string.ts
CHANGED
|
@@ -1,129 +1,129 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* Ensures that a given string has a specific prefix.
|
|
4
|
-
*
|
|
5
|
-
* @param {string} str - The string to ensure the prefix on.
|
|
6
|
-
* @param {string} prefix - The prefix to ensure on the string.
|
|
7
|
-
* @return {string} - The resulting string with the ensured prefix.
|
|
8
|
-
*/
|
|
9
|
-
export function ensurePrefix(str: string, prefix: string): string {
|
|
10
|
-
if (!str.startsWith(prefix))
|
|
11
|
-
return prefix + str
|
|
12
|
-
return str
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Ensures that a string ends with a specified suffix.
|
|
18
|
-
*
|
|
19
|
-
* @param {string} str - The original string.
|
|
20
|
-
* @param {string} suffix - The suffix to ensure.
|
|
21
|
-
* @return {string} - The modified string with the suffix added if it was not already present.
|
|
22
|
-
*/
|
|
23
|
-
export function ensureSuffix(str: string, suffix: string): string {
|
|
24
|
-
if (!str.endsWith(suffix))
|
|
25
|
-
return str + suffix
|
|
26
|
-
return str
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Formats a string using a template and provided arguments.
|
|
31
|
-
*
|
|
32
|
-
* @param {string} template - The template string containing placeholders.
|
|
33
|
-
* @param {any[]} args - Optional arguments to replace the placeholders in the template.
|
|
34
|
-
* @return {string} The formatted string.
|
|
35
|
-
*/
|
|
36
|
-
export function format(template: string, ...args: any[]): string {
|
|
37
|
-
|
|
38
|
-
let regex: RegExp;
|
|
39
|
-
if (args.length === 1 && typeof args[0] === 'object') {
|
|
40
|
-
args = args[0];
|
|
41
|
-
regex = /{(.+?)}/g;
|
|
42
|
-
} else {
|
|
43
|
-
regex = /{(\d+?)}/g;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return template.replace(regex, (match, key) => {
|
|
47
|
-
return typeof args[key] !== 'undefined' ? args[key] : "";
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Splits a string into its constituent words, regardless of the original case
|
|
53
|
-
* style (camelCase, PascalCase, snake_case, kebab-case, CONSTANT_CASE,
|
|
54
|
-
* space-separated, etc.).
|
|
55
|
-
*
|
|
56
|
-
* @param {string} str - The string to split into words.
|
|
57
|
-
* @return {string[]} - The list of lowercase words extracted from the input.
|
|
58
|
-
*/
|
|
59
|
-
function toWords(str: string): string[] {
|
|
60
|
-
if (!str) return [];
|
|
61
|
-
|
|
62
|
-
return str
|
|
63
|
-
// Insert a space between a lowercase/digit and an uppercase letter (camelCase -> camel Case)
|
|
64
|
-
.replace(/([a-z0-9])([A-Z])/g, '$1 $2')
|
|
65
|
-
// Insert a space between consecutive uppercase letters followed by a lowercase letter (XMLParser -> XML Parser)
|
|
66
|
-
.replace(/([A-Z]+)([A-Z][a-z])/g, '$1 $2')
|
|
67
|
-
// Replace any non-alphanumeric character with a space
|
|
68
|
-
.replace(/[^a-zA-Z0-9]+/g, ' ')
|
|
69
|
-
.trim()
|
|
70
|
-
.toLowerCase()
|
|
71
|
-
.split(/\s+/)
|
|
72
|
-
.filter(Boolean);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Converts a string to snake_case.
|
|
77
|
-
*
|
|
78
|
-
* @param {string} str - The string to convert.
|
|
79
|
-
* @return {string} - The string converted to snake_case.
|
|
80
|
-
*/
|
|
81
|
-
export function toSnakeCase(str: string): string {
|
|
82
|
-
return toWords(str).join('_');
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Converts a string to kebab-case.
|
|
87
|
-
*
|
|
88
|
-
* @param {string} str - The string to convert.
|
|
89
|
-
* @return {string} - The string converted to kebab-case.
|
|
90
|
-
*/
|
|
91
|
-
export function toKebabCase(str: string): string {
|
|
92
|
-
return toWords(str).join('-');
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Converts a string to camelCase.
|
|
97
|
-
*
|
|
98
|
-
* @param {string} str - The string to convert.
|
|
99
|
-
* @return {string} - The string converted to camelCase.
|
|
100
|
-
*/
|
|
101
|
-
export function toCamelCase(str: string): string {
|
|
102
|
-
const words = toWords(str);
|
|
103
|
-
if (words.length === 0) return '';
|
|
104
|
-
return words
|
|
105
|
-
.map((word, i) => i === 0 ? word : word.charAt(0).toUpperCase() + word.slice(1))
|
|
106
|
-
.join('');
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* Converts a string to PascalCase.
|
|
111
|
-
*
|
|
112
|
-
* @param {string} str - The string to convert.
|
|
113
|
-
* @return {string} - The string converted to PascalCase.
|
|
114
|
-
*/
|
|
115
|
-
export function toPascalCase(str: string): string {
|
|
116
|
-
return toWords(str)
|
|
117
|
-
.map(word => word.charAt(0).toUpperCase() + word.slice(1))
|
|
118
|
-
.join('');
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* Converts a string to CONSTANT_CASE (a.k.a. SCREAMING_SNAKE_CASE).
|
|
123
|
-
*
|
|
124
|
-
* @param {string} str - The string to convert.
|
|
125
|
-
* @return {string} - The string converted to CONSTANT_CASE.
|
|
126
|
-
*/
|
|
127
|
-
export function toConstantCase(str: string): string {
|
|
128
|
-
return toWords(str).join('_').toUpperCase();
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* Ensures that a given string has a specific prefix.
|
|
4
|
+
*
|
|
5
|
+
* @param {string} str - The string to ensure the prefix on.
|
|
6
|
+
* @param {string} prefix - The prefix to ensure on the string.
|
|
7
|
+
* @return {string} - The resulting string with the ensured prefix.
|
|
8
|
+
*/
|
|
9
|
+
export function ensurePrefix(str: string, prefix: string): string {
|
|
10
|
+
if (!str.startsWith(prefix))
|
|
11
|
+
return prefix + str
|
|
12
|
+
return str
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Ensures that a string ends with a specified suffix.
|
|
18
|
+
*
|
|
19
|
+
* @param {string} str - The original string.
|
|
20
|
+
* @param {string} suffix - The suffix to ensure.
|
|
21
|
+
* @return {string} - The modified string with the suffix added if it was not already present.
|
|
22
|
+
*/
|
|
23
|
+
export function ensureSuffix(str: string, suffix: string): string {
|
|
24
|
+
if (!str.endsWith(suffix))
|
|
25
|
+
return str + suffix
|
|
26
|
+
return str
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Formats a string using a template and provided arguments.
|
|
31
|
+
*
|
|
32
|
+
* @param {string} template - The template string containing placeholders.
|
|
33
|
+
* @param {any[]} args - Optional arguments to replace the placeholders in the template.
|
|
34
|
+
* @return {string} The formatted string.
|
|
35
|
+
*/
|
|
36
|
+
export function format(template: string, ...args: any[]): string {
|
|
37
|
+
|
|
38
|
+
let regex: RegExp;
|
|
39
|
+
if (args.length === 1 && typeof args[0] === 'object') {
|
|
40
|
+
args = args[0];
|
|
41
|
+
regex = /{(.+?)}/g;
|
|
42
|
+
} else {
|
|
43
|
+
regex = /{(\d+?)}/g;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return template.replace(regex, (match, key) => {
|
|
47
|
+
return typeof args[key] !== 'undefined' ? args[key] : "";
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Splits a string into its constituent words, regardless of the original case
|
|
53
|
+
* style (camelCase, PascalCase, snake_case, kebab-case, CONSTANT_CASE,
|
|
54
|
+
* space-separated, etc.).
|
|
55
|
+
*
|
|
56
|
+
* @param {string} str - The string to split into words.
|
|
57
|
+
* @return {string[]} - The list of lowercase words extracted from the input.
|
|
58
|
+
*/
|
|
59
|
+
function toWords(str: string): string[] {
|
|
60
|
+
if (!str) return [];
|
|
61
|
+
|
|
62
|
+
return str
|
|
63
|
+
// Insert a space between a lowercase/digit and an uppercase letter (camelCase -> camel Case)
|
|
64
|
+
.replace(/([a-z0-9])([A-Z])/g, '$1 $2')
|
|
65
|
+
// Insert a space between consecutive uppercase letters followed by a lowercase letter (XMLParser -> XML Parser)
|
|
66
|
+
.replace(/([A-Z]+)([A-Z][a-z])/g, '$1 $2')
|
|
67
|
+
// Replace any non-alphanumeric character with a space
|
|
68
|
+
.replace(/[^a-zA-Z0-9]+/g, ' ')
|
|
69
|
+
.trim()
|
|
70
|
+
.toLowerCase()
|
|
71
|
+
.split(/\s+/)
|
|
72
|
+
.filter(Boolean);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Converts a string to snake_case.
|
|
77
|
+
*
|
|
78
|
+
* @param {string} str - The string to convert.
|
|
79
|
+
* @return {string} - The string converted to snake_case.
|
|
80
|
+
*/
|
|
81
|
+
export function toSnakeCase(str: string): string {
|
|
82
|
+
return toWords(str).join('_');
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Converts a string to kebab-case.
|
|
87
|
+
*
|
|
88
|
+
* @param {string} str - The string to convert.
|
|
89
|
+
* @return {string} - The string converted to kebab-case.
|
|
90
|
+
*/
|
|
91
|
+
export function toKebabCase(str: string): string {
|
|
92
|
+
return toWords(str).join('-');
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Converts a string to camelCase.
|
|
97
|
+
*
|
|
98
|
+
* @param {string} str - The string to convert.
|
|
99
|
+
* @return {string} - The string converted to camelCase.
|
|
100
|
+
*/
|
|
101
|
+
export function toCamelCase(str: string): string {
|
|
102
|
+
const words = toWords(str);
|
|
103
|
+
if (words.length === 0) return '';
|
|
104
|
+
return words
|
|
105
|
+
.map((word, i) => i === 0 ? word : word.charAt(0).toUpperCase() + word.slice(1))
|
|
106
|
+
.join('');
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Converts a string to PascalCase.
|
|
111
|
+
*
|
|
112
|
+
* @param {string} str - The string to convert.
|
|
113
|
+
* @return {string} - The string converted to PascalCase.
|
|
114
|
+
*/
|
|
115
|
+
export function toPascalCase(str: string): string {
|
|
116
|
+
return toWords(str)
|
|
117
|
+
.map(word => word.charAt(0).toUpperCase() + word.slice(1))
|
|
118
|
+
.join('');
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Converts a string to CONSTANT_CASE (a.k.a. SCREAMING_SNAKE_CASE).
|
|
123
|
+
*
|
|
124
|
+
* @param {string} str - The string to convert.
|
|
125
|
+
* @return {string} - The string converted to CONSTANT_CASE.
|
|
126
|
+
*/
|
|
127
|
+
export function toConstantCase(str: string): string {
|
|
128
|
+
return toWords(str).join('_').toUpperCase();
|
|
129
129
|
}
|
package/src/type-code.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
enum TypeCode {
|
|
2
|
-
String = 'string',
|
|
3
|
-
Number = 'number',
|
|
4
|
-
Boolean = 'boolean',
|
|
5
|
-
Symbol = 'symbol',
|
|
6
|
-
BigInt = 'bigint',
|
|
7
|
-
Null = 'null',
|
|
8
|
-
Undefined = 'undefined',
|
|
9
|
-
Object = 'object',
|
|
10
|
-
Function = 'function',
|
|
11
|
-
Array = 'array',
|
|
12
|
-
Unknown = 'unknown',
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
|
|
1
|
+
enum TypeCode {
|
|
2
|
+
String = 'string',
|
|
3
|
+
Number = 'number',
|
|
4
|
+
Boolean = 'boolean',
|
|
5
|
+
Symbol = 'symbol',
|
|
6
|
+
BigInt = 'bigint',
|
|
7
|
+
Null = 'null',
|
|
8
|
+
Undefined = 'undefined',
|
|
9
|
+
Object = 'object',
|
|
10
|
+
Function = 'function',
|
|
11
|
+
Array = 'array',
|
|
12
|
+
Unknown = 'unknown',
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
|
|
16
16
|
export default TypeCode;
|