ddan-js 2.7.9 → 2.7.10
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/bin/ddan-js.esm.js +1 -1
- package/bin/ddan-js.js +1 -1
- package/bin/lib/index.js +1 -0
- package/bin/lib/modules/hook/index.js +2 -0
- package/bin/lib/modules/hook/log.js +30 -0
- package/bin/lib/modules/string/index.js +28 -17
- package/bin/types/index.d.ts +22 -0
- package/bin/types/modules/hook/index.d.ts +2 -0
- package/bin/types/modules/hook/log.d.ts +5 -0
- package/bin/types/modules/string/index.d.ts +2 -1
- package/package.json +1 -1
|
@@ -14,24 +14,24 @@ function toString(value) {
|
|
|
14
14
|
}
|
|
15
15
|
if (Array.isArray(value)) {
|
|
16
16
|
// Recursively convert values (susceptible to call stack limits).
|
|
17
|
-
return `${value.map((other) => other == null ? other : toString(other))}`;
|
|
17
|
+
return `${value.map((other) => (other == null ? other : toString(other)))}`;
|
|
18
18
|
}
|
|
19
19
|
if (is_1.default.isSymbol(value)) {
|
|
20
20
|
return value.toString();
|
|
21
21
|
}
|
|
22
22
|
const result = `${value}`;
|
|
23
|
-
return
|
|
23
|
+
return result == '0' && 1 / value == -INFINITY ? '-0' : result;
|
|
24
24
|
}
|
|
25
25
|
const upperFirst = (0, createCaseFirst_1.default)('toUpperCase');
|
|
26
26
|
const lowerFirst = (0, createCaseFirst_1.default)('toLowerCase');
|
|
27
|
-
const snakeCase = (string) => (
|
|
28
|
-
const kebabCase = (string) => (
|
|
29
|
-
const upperCase = (string) => (
|
|
30
|
-
const camelCase = (string) => (
|
|
27
|
+
const snakeCase = (string) => (0, words_1.default)(toString(string).replace(/['\u2019]/g, '')).reduce((result, word, index) => result + (index ? '_' : '') + word.toLowerCase(), '');
|
|
28
|
+
const kebabCase = (string) => (0, words_1.default)(toString(string).replace(/['\u2019]/g, '')).reduce((result, word, index) => result + (index ? '-' : '') + word.toLowerCase(), '');
|
|
29
|
+
const upperCase = (string) => (0, words_1.default)(toString(string).replace(/['\u2019]/g, '')).reduce((result, word, index) => result + (index ? ' ' : '') + word.toUpperCase(), '');
|
|
30
|
+
const camelCase = (string) => (0, words_1.default)(toString(string).replace(/['\u2019]/g, '')).reduce((result, word, index) => {
|
|
31
31
|
word = word.toLowerCase();
|
|
32
32
|
return result + (index ? upperFirst(word) : word);
|
|
33
|
-
}, '')
|
|
34
|
-
const lowerCase = (string) => (
|
|
33
|
+
}, '');
|
|
34
|
+
const lowerCase = (string) => (0, words_1.default)(toString(string).replace(/['\u2019]/g, '')).reduce((result, word, index) => result + (index ? ' ' : '') + word.toLowerCase(), '');
|
|
35
35
|
/**
|
|
36
36
|
* startCase('--foo-bar--')
|
|
37
37
|
* // => 'Foo Bar'
|
|
@@ -42,7 +42,7 @@ const lowerCase = (string) => ((0, words_1.default)(toString(string).replace(/['
|
|
|
42
42
|
* startCase('__FOO_BAR__')
|
|
43
43
|
* // => 'FOO BAR'
|
|
44
44
|
*/
|
|
45
|
-
const startCase = (string) => (
|
|
45
|
+
const startCase = (string) => (0, words_1.default)(`${string}`.replace(/['\u2019]/g, '')).reduce((result, word, index) => result + (index ? ' ' : '') + upperFirst(word), '');
|
|
46
46
|
const splitOnFirst = (string, separator) => {
|
|
47
47
|
if (!(typeof string === 'string' && typeof separator === 'string')) {
|
|
48
48
|
throw new TypeError('Expected the arguments to be of type `string`');
|
|
@@ -54,19 +54,18 @@ const splitOnFirst = (string, separator) => {
|
|
|
54
54
|
if (separatorIndex === -1) {
|
|
55
55
|
return [];
|
|
56
56
|
}
|
|
57
|
-
return [
|
|
58
|
-
string.slice(0, separatorIndex),
|
|
59
|
-
string.slice(separatorIndex + separator.length)
|
|
60
|
-
];
|
|
57
|
+
return [string.slice(0, separatorIndex), string.slice(separatorIndex + separator.length)];
|
|
61
58
|
};
|
|
62
59
|
const parseValue = (value, { number = false, boolean = false } = {}) => {
|
|
63
60
|
let val = value;
|
|
64
61
|
if (!value || typeof value !== 'string')
|
|
65
62
|
return val;
|
|
66
|
-
if (number && !Number.isNaN(Number(value)) &&
|
|
63
|
+
if (number && !Number.isNaN(Number(value)) && typeof value === 'string' && value.trim() !== '') {
|
|
67
64
|
val = Number(value);
|
|
68
65
|
}
|
|
69
|
-
else if (boolean &&
|
|
66
|
+
else if (boolean &&
|
|
67
|
+
value !== null &&
|
|
68
|
+
(value.toLowerCase() === 'true' || value.toLowerCase() === 'false')) {
|
|
70
69
|
val = value.toLowerCase() === 'true';
|
|
71
70
|
}
|
|
72
71
|
return val;
|
|
@@ -80,11 +79,22 @@ const replace = (source, rules) => {
|
|
|
80
79
|
const _arr = Array.isArray(rules) ? rules : [rules];
|
|
81
80
|
(_arr || []).forEach((e) => {
|
|
82
81
|
if (e.key && e.value) {
|
|
83
|
-
result = result.replace(new RegExp(e.key, e.flag ||
|
|
82
|
+
result = result.replace(new RegExp(e.key, e.flag || ''), e.value);
|
|
84
83
|
}
|
|
85
84
|
});
|
|
86
85
|
return result;
|
|
87
86
|
};
|
|
87
|
+
const jsonFormat = (jsonString) => {
|
|
88
|
+
try {
|
|
89
|
+
if (!jsonString)
|
|
90
|
+
return '';
|
|
91
|
+
const json = JSON.parse(jsonString);
|
|
92
|
+
return JSON.stringify(json, null, 2);
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
return jsonString;
|
|
96
|
+
}
|
|
97
|
+
};
|
|
88
98
|
exports.default = {
|
|
89
99
|
toString,
|
|
90
100
|
startCase,
|
|
@@ -97,5 +107,6 @@ exports.default = {
|
|
|
97
107
|
lowerFirst,
|
|
98
108
|
splitOnFirst,
|
|
99
109
|
parseValue,
|
|
100
|
-
replace
|
|
110
|
+
replace,
|
|
111
|
+
jsonFormat
|
|
101
112
|
};
|
package/bin/types/index.d.ts
CHANGED
|
@@ -143,6 +143,7 @@ declare const dUtil: {
|
|
|
143
143
|
boolean?: boolean | undefined;
|
|
144
144
|
}) => any;
|
|
145
145
|
replace: (source: string, rules: import("./typings").Ddan.IRegexRule | import("./typings").Ddan.IRegexRule[]) => string;
|
|
146
|
+
jsonFormat: (jsonString: string) => string;
|
|
146
147
|
};
|
|
147
148
|
time: {
|
|
148
149
|
now: () => import("./modules/time/dtime").default;
|
|
@@ -267,6 +268,22 @@ declare const dHook: {
|
|
|
267
268
|
readonly Instance: T;
|
|
268
269
|
readonly I: T;
|
|
269
270
|
};
|
|
271
|
+
toString: (value: any) => any;
|
|
272
|
+
startCase: (string: any) => any;
|
|
273
|
+
snakeCase: (string: any) => any;
|
|
274
|
+
kebabCase: (string: any) => any;
|
|
275
|
+
camelCase: (string: any) => any;
|
|
276
|
+
upperCase: (string: any) => any;
|
|
277
|
+
upperFirst: (string: any) => any;
|
|
278
|
+
lowerCase: (string: any) => any;
|
|
279
|
+
lowerFirst: (string: any) => any;
|
|
280
|
+
splitOnFirst: (string: any, separator: any) => string[];
|
|
281
|
+
parseValue: (value?: any, { number, boolean }?: {
|
|
282
|
+
number?: boolean | undefined;
|
|
283
|
+
boolean?: boolean | undefined;
|
|
284
|
+
}) => any;
|
|
285
|
+
replace: (source: string, rules: import("./typings").Ddan.IRegexRule | import("./typings").Ddan.IRegexRule[]) => string;
|
|
286
|
+
jsonFormat: (jsonString: string) => string;
|
|
270
287
|
sleep: (ms?: number) => Promise<unknown>;
|
|
271
288
|
run: <T_1 = any>(task?: import("./typings").Ddan.PFunction<T_1> | undefined, wait?: number) => Promise<[any, undefined] | [null, T_1]>;
|
|
272
289
|
exec: (func: import("./typings").Ddan.Function, taskId?: string) => import("./typings").Ddan.PSafeResult<any>;
|
|
@@ -278,6 +295,8 @@ declare const dHook: {
|
|
|
278
295
|
pipe: (func: import("./typings").Ddan.Function, callback?: ((result: import("./typings").Ddan.SafeResult<any>) => void) | undefined) => import("./modules/hook/modules/pipeline").default;
|
|
279
296
|
pipeline: (max?: number) => import("./modules/hook/modules/pipeline").default;
|
|
280
297
|
safeTask: (func: import("./typings").Ddan.Function, callback?: ((result: import("./typings").Ddan.SafeResult<any>) => void) | undefined) => import("./modules/hook/modules/safeTask").default;
|
|
298
|
+
logString: (data: any) => Promise<string>;
|
|
299
|
+
logParse: (logStr: string) => Promise<string>;
|
|
281
300
|
to: <T_2 = any, U extends object = any>(promise: Promise<T_2>, errorExt?: object | undefined) => Promise<[null, T_2] | [U, undefined]>;
|
|
282
301
|
go: <T_3 = any>(task?: import("./typings").Ddan.PFunction<T_3> | undefined) => Promise<[any, undefined] | [null, T_3]>;
|
|
283
302
|
delay: (ms?: number) => Promise<unknown>;
|
|
@@ -638,6 +657,8 @@ declare const _default: {
|
|
|
638
657
|
pipe: (func: import("./typings").Ddan.Function, callback?: ((result: import("./typings").Ddan.SafeResult<any>) => void) | undefined) => import("./modules/hook/modules/pipeline").default;
|
|
639
658
|
pipeline: (max?: number) => import("./modules/hook/modules/pipeline").default;
|
|
640
659
|
safeTask: (func: import("./typings").Ddan.Function, callback?: ((result: import("./typings").Ddan.SafeResult<any>) => void) | undefined) => import("./modules/hook/modules/safeTask").default;
|
|
660
|
+
logString: (data: any) => Promise<string>;
|
|
661
|
+
logParse: (logStr: string) => Promise<string>;
|
|
641
662
|
to: <T_1 = any, U extends object = any>(promise: Promise<T_1>, errorExt?: object | undefined) => Promise<[null, T_1] | [U, undefined]>;
|
|
642
663
|
go: <T_2 = any>(task?: import("./typings").Ddan.PFunction<T_2> | undefined) => Promise<[any, undefined] | [null, T_2]>;
|
|
643
664
|
delay: (ms?: number) => Promise<unknown>;
|
|
@@ -744,6 +765,7 @@ declare const _default: {
|
|
|
744
765
|
boolean?: boolean | undefined;
|
|
745
766
|
}) => any;
|
|
746
767
|
replace: (source: string, rules: import("./typings").Ddan.IRegexRule | import("./typings").Ddan.IRegexRule[]) => string;
|
|
768
|
+
jsonFormat: (jsonString: string) => string;
|
|
747
769
|
};
|
|
748
770
|
obj: {
|
|
749
771
|
copy: (source: any, options?: {
|
|
@@ -25,6 +25,8 @@ declare const _default: {
|
|
|
25
25
|
pipe: (func: Ddan.Function, callback?: ((result: Ddan.SafeResult<any>) => void) | undefined) => DPipeline;
|
|
26
26
|
pipeline: (max?: number) => DPipeline;
|
|
27
27
|
safeTask: (func: Ddan.Function, callback?: ((result: Ddan.SafeResult<any>) => void) | undefined) => DSafeTask;
|
|
28
|
+
logString: (data: any) => Promise<string>;
|
|
29
|
+
logParse: (logStr: string) => Promise<string>;
|
|
28
30
|
to: <T = any, U extends object = any>(promise: Promise<T>, errorExt?: object | undefined) => Promise<[null, T] | [U, undefined]>;
|
|
29
31
|
go: <T_1 = any>(task?: Ddan.PFunction<T_1> | undefined) => Promise<[any, undefined] | [null, T_1]>;
|
|
30
32
|
delay: (ms?: number) => Promise<unknown>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Ddan } from
|
|
1
|
+
import { Ddan } from '../../typings';
|
|
2
2
|
declare function toString(value: any): any;
|
|
3
3
|
declare const _default: {
|
|
4
4
|
toString: typeof toString;
|
|
@@ -16,5 +16,6 @@ declare const _default: {
|
|
|
16
16
|
boolean?: boolean | undefined;
|
|
17
17
|
}) => any;
|
|
18
18
|
replace: (source: string, rules: Ddan.IRegexRule | Ddan.IRegexRule[]) => string;
|
|
19
|
+
jsonFormat: (jsonString: string) => string;
|
|
19
20
|
};
|
|
20
21
|
export default _default;
|