@develia/commons 0.4.9 → 0.4.12
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 +5 -4
- package/dist/cjs/array.js.map +1 -1
- package/dist/cjs/browser/form-utilities.js +29 -23
- package/dist/cjs/browser/form-utilities.js.map +1 -1
- package/dist/cjs/browser/geo-location.js +61 -37
- package/dist/cjs/browser/geo-location.js.map +1 -1
- package/dist/cjs/browser/index.js +46 -1
- package/dist/cjs/browser/index.js.map +1 -1
- package/dist/cjs/event-bus.js +70 -0
- package/dist/cjs/event-bus.js.map +1 -0
- package/dist/cjs/from.js +1 -1
- package/dist/cjs/from.js.map +1 -1
- package/dist/cjs/index.js +4 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/math.js +3 -2
- package/dist/cjs/math.js.map +1 -1
- package/dist/cjs/parse.js +4 -3
- package/dist/cjs/parse.js.map +1 -1
- package/dist/cjs/patch.js +3 -2
- package/dist/cjs/patch.js.map +1 -1
- package/dist/cjs/string.js +43 -3
- package/dist/cjs/string.js.map +1 -1
- package/dist/cjs/utilities.js +25 -24
- package/dist/cjs/utilities.js.map +1 -1
- package/dist/esm/browser/form-utilities.js +23 -18
- package/dist/esm/browser/form-utilities.js.map +1 -1
- package/dist/esm/browser/geo-location.js +60 -36
- package/dist/esm/browser/geo-location.js.map +1 -1
- package/dist/esm/browser/index.js +44 -0
- package/dist/esm/browser/index.js.map +1 -1
- package/dist/esm/event-bus.js +65 -0
- package/dist/esm/event-bus.js.map +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/string.js +34 -0
- package/dist/esm/string.js.map +1 -1
- package/dist/types/browser/form-utilities.d.ts +2 -2
- package/dist/types/browser/form-utilities.d.ts.map +1 -1
- package/dist/types/browser/geo-location.d.ts.map +1 -1
- package/dist/types/browser/index.d.ts +7 -0
- package/dist/types/browser/index.d.ts.map +1 -1
- package/dist/types/event-bus.d.ts +21 -0
- package/dist/types/event-bus.d.ts.map +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/string.d.ts +5 -0
- package/dist/types/string.d.ts.map +1 -1
- package/dist/web/browser/form-utilities.js +23 -18
- package/dist/web/browser/form-utilities.js.map +1 -1
- package/dist/web/browser/geo-location.js +60 -36
- package/dist/web/browser/geo-location.js.map +1 -1
- package/dist/web/browser/index.js +44 -0
- package/dist/web/browser/index.js.map +1 -1
- package/dist/web/event-bus.js +65 -0
- package/dist/web/event-bus.js.map +1 -0
- package/dist/web/index.js +1 -0
- package/dist/web/index.js.map +1 -1
- package/dist/web/string.js +34 -0
- package/dist/web/string.js.map +1 -1
- package/package.json +56 -56
- package/src/array.ts +0 -0
- package/src/async-pool-executor.ts +0 -0
- package/src/browser/form-utilities.ts +179 -173
- package/src/browser/geo-location.ts +113 -79
- package/src/browser/index.ts +78 -4
- package/src/browser/native-bridge.ts +116 -116
- package/src/cancellable-promise.ts +76 -76
- package/src/clean-url-search-params.ts +0 -0
- package/src/collections/cache-dictionary.ts +0 -0
- package/src/collections/default-map.ts +0 -0
- package/src/collections/default-weak-map.ts +0 -0
- package/src/collections/index.ts +2 -2
- package/src/event-bus.ts +84 -0
- package/src/from.ts +0 -0
- package/src/index.ts +37 -36
- package/src/key-value-pair.ts +0 -0
- package/src/lazy.ts +0 -0
- package/src/math.ts +0 -0
- package/src/order.ts +0 -0
- package/src/parse.ts +240 -240
- package/src/patch.ts +0 -0
- package/src/stopwatch.ts +0 -0
- package/src/string.ts +82 -2
- package/src/timer.ts +0 -0
- package/src/timespan.ts +0 -0
- package/src/type-code.ts +15 -15
- package/src/type.ts +371 -371
- package/src/types.ts +30 -30
- package/src/utilities.ts +404 -404
package/src/stopwatch.ts
CHANGED
|
File without changes
|
package/src/string.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* @param {string} prefix - The prefix to ensure on the string.
|
|
7
7
|
* @return {string} - The resulting string with the ensured prefix.
|
|
8
8
|
*/
|
|
9
|
-
export function ensurePrefix(str: string, prefix: string) {
|
|
9
|
+
export function ensurePrefix(str: string, prefix: string): string {
|
|
10
10
|
if (!str.startsWith(prefix))
|
|
11
11
|
return prefix + str
|
|
12
12
|
return str
|
|
@@ -20,7 +20,7 @@ export function ensurePrefix(str: string, prefix: string) {
|
|
|
20
20
|
* @param {string} suffix - The suffix to ensure.
|
|
21
21
|
* @return {string} - The modified string with the suffix added if it was not already present.
|
|
22
22
|
*/
|
|
23
|
-
export function ensureSuffix(str: string, suffix: string) {
|
|
23
|
+
export function ensureSuffix(str: string, suffix: string): string {
|
|
24
24
|
if (!str.endsWith(suffix))
|
|
25
25
|
return str + suffix
|
|
26
26
|
return str
|
|
@@ -46,4 +46,84 @@ export function format(template: string, ...args: any[]): string {
|
|
|
46
46
|
return template.replace(regex, (match, key) => {
|
|
47
47
|
return typeof args[key] !== 'undefined' ? args[key] : "";
|
|
48
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();
|
|
49
129
|
}
|
package/src/timer.ts
CHANGED
|
File without changes
|
package/src/timespan.ts
CHANGED
|
File without changes
|
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;
|