@develia/commons 0.4.19 → 0.4.21
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/browser/form-utilities.js +1 -1
- package/dist/cjs/browser/form-utilities.js.map +1 -1
- package/dist/cjs/collections/default-map.js +2 -2
- package/dist/cjs/collections/default-map.js.map +1 -1
- package/dist/cjs/collections/default-weak-map.js +2 -2
- package/dist/cjs/collections/default-weak-map.js.map +1 -1
- package/dist/cjs/collections/from.js +4 -4
- package/dist/cjs/collections/from.js.map +1 -1
- package/dist/cjs/string.js +21 -0
- package/dist/cjs/string.js.map +1 -1
- package/dist/cjs/types.js.map +1 -1
- package/dist/cjs/utilities.js +14 -5
- package/dist/cjs/utilities.js.map +1 -1
- package/dist/esm/browser/form-utilities.js +1 -1
- package/dist/esm/browser/form-utilities.js.map +1 -1
- package/dist/esm/collections/default-map.js +2 -2
- package/dist/esm/collections/default-map.js.map +1 -1
- package/dist/esm/collections/default-weak-map.js +2 -2
- package/dist/esm/collections/default-weak-map.js.map +1 -1
- package/dist/esm/collections/from.js +4 -4
- package/dist/esm/collections/from.js.map +1 -1
- package/dist/esm/string.js +19 -0
- package/dist/esm/string.js.map +1 -1
- package/dist/esm/types.js.map +1 -1
- package/dist/esm/utilities.js +14 -5
- package/dist/esm/utilities.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/collections/default-map.d.ts +3 -3
- package/dist/types/collections/default-map.d.ts.map +1 -1
- package/dist/types/collections/default-weak-map.d.ts +3 -3
- package/dist/types/collections/default-weak-map.d.ts.map +1 -1
- package/dist/types/collections/from.d.ts +5 -5
- package/dist/types/collections/from.d.ts.map +1 -1
- package/dist/types/string.d.ts +11 -0
- package/dist/types/string.d.ts.map +1 -1
- package/dist/types/types.d.ts +0 -1
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/utilities.d.ts.map +1 -1
- package/dist/web/browser/form-utilities.js +1 -2
- package/dist/web/browser/form-utilities.js.map +1 -1
- package/dist/web/collections/default-map.js +2 -2
- package/dist/web/collections/default-map.js.map +1 -1
- package/dist/web/collections/default-weak-map.js +2 -2
- package/dist/web/collections/default-weak-map.js.map +1 -1
- package/dist/web/collections/from.js +4 -4
- package/dist/web/collections/from.js.map +1 -1
- package/dist/web/string.js +19 -0
- package/dist/web/string.js.map +1 -1
- package/dist/web/types.js.map +1 -1
- package/dist/web/utilities.js +14 -5
- package/dist/web/utilities.js.map +1 -1
- package/package.json +1 -1
- package/src/browser/form-utilities.ts +3 -3
- package/src/collections/default-map.ts +3 -3
- package/src/collections/default-weak-map.ts +3 -3
- package/src/collections/from.ts +5 -5
- package/src/string.ts +22 -1
- package/src/types.ts +1 -3
- package/src/utilities.ts +14 -5
package/src/string.ts
CHANGED
|
@@ -26,6 +26,27 @@ export function ensureSuffix(str: string, suffix: string): string {
|
|
|
26
26
|
return str
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
+
/**
|
|
30
|
+
* Normalizes Unicode whitespaces into single ASCII spaces and removes leading
|
|
31
|
+
* and trailing whitespace.
|
|
32
|
+
*/
|
|
33
|
+
export function normalizeWhitespaces(str: string): string {
|
|
34
|
+
return str.normalize('NFKC')
|
|
35
|
+
.replace(/[\s\u200B\uFEFF]+/gu, ' ')
|
|
36
|
+
.trim()
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Removes Unicode diacritics while preserving the original letter casing.
|
|
41
|
+
*
|
|
42
|
+
* @example removeDiacritics('áÁñÑ') // 'aAnN'
|
|
43
|
+
*/
|
|
44
|
+
export function removeDiacritics(str: string): string {
|
|
45
|
+
return str
|
|
46
|
+
.normalize('NFD')
|
|
47
|
+
.replace(/\p{M}+/gu, '')
|
|
48
|
+
}
|
|
49
|
+
|
|
29
50
|
/**
|
|
30
51
|
* Formats a string using a template and provided arguments.
|
|
31
52
|
*
|
|
@@ -129,4 +150,4 @@ export function toPascalCase(str: string): string {
|
|
|
129
150
|
*/
|
|
130
151
|
export function toConstantCase(str: string): string {
|
|
131
152
|
return toWords(str).join('_').toUpperCase();
|
|
132
|
-
}
|
|
153
|
+
}
|
package/src/types.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
export type EqualityComparer<T> = (arg1: T, arg2: T) => boolean;
|
|
4
4
|
|
|
5
|
-
export type Consumer<T> = (arg: T) => void
|
|
5
|
+
export type Consumer<T> = (arg: T) => void;
|
|
6
6
|
|
|
7
7
|
export type Predicate<T> = (arg: T) => boolean;
|
|
8
8
|
|
|
@@ -10,8 +10,6 @@ export type Supplier<T> = () => T;
|
|
|
10
10
|
|
|
11
11
|
export type Nullable<T> = T | null;
|
|
12
12
|
|
|
13
|
-
export type Optional<T> = T | undefined;
|
|
14
|
-
|
|
15
13
|
export type Nullish = null | undefined;
|
|
16
14
|
|
|
17
15
|
export type Resolvable<T> = T | Promise<T> | Supplier<T>;
|
package/src/utilities.ts
CHANGED
|
@@ -6,11 +6,13 @@ import type {Resolvable, Constructor} from "./types.js";
|
|
|
6
6
|
import Type from "./type.js";
|
|
7
7
|
|
|
8
8
|
export function lazy<T extends object>(factory: () => T): T {
|
|
9
|
-
let
|
|
9
|
+
let created = false;
|
|
10
|
+
let instance: T;
|
|
10
11
|
|
|
11
12
|
const getInstance = (): T => {
|
|
12
|
-
if (!
|
|
13
|
+
if (!created) {
|
|
13
14
|
instance = factory();
|
|
15
|
+
created = true;
|
|
14
16
|
}
|
|
15
17
|
return instance;
|
|
16
18
|
};
|
|
@@ -19,8 +21,11 @@ export function lazy<T extends object>(factory: () => T): T {
|
|
|
19
21
|
get(_, prop, receiver) {
|
|
20
22
|
return Reflect.get(getInstance(), prop, receiver);
|
|
21
23
|
},
|
|
22
|
-
set(_, prop, value
|
|
23
|
-
return Reflect.set(getInstance(), prop, value,
|
|
24
|
+
set(_, prop, value) {
|
|
25
|
+
return Reflect.set(getInstance(), prop, value, getInstance());
|
|
26
|
+
},
|
|
27
|
+
defineProperty(_, prop, descriptor) {
|
|
28
|
+
return Reflect.defineProperty(getInstance(), prop, descriptor);
|
|
24
29
|
},
|
|
25
30
|
has(_, prop) {
|
|
26
31
|
return Reflect.has(getInstance(), prop);
|
|
@@ -32,7 +37,11 @@ export function lazy<T extends object>(factory: () => T): T {
|
|
|
32
37
|
return Reflect.ownKeys(getInstance());
|
|
33
38
|
},
|
|
34
39
|
getOwnPropertyDescriptor(_, prop) {
|
|
35
|
-
|
|
40
|
+
const descriptor = Reflect.getOwnPropertyDescriptor(getInstance(), prop);
|
|
41
|
+
if (descriptor == null || descriptor.configurable) {
|
|
42
|
+
return descriptor;
|
|
43
|
+
}
|
|
44
|
+
return {...descriptor, configurable: true};
|
|
36
45
|
},
|
|
37
46
|
getPrototypeOf() {
|
|
38
47
|
return Reflect.getPrototypeOf(getInstance());
|