@cabloy/utils 1.0.5 → 1.0.7
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/check.d.ts +1 -0
- package/dist/check.js +5 -0
- package/dist/utils.d.ts +3 -0
- package/dist/utils.js +31 -15
- package/package.json +1 -1
package/dist/check.d.ts
CHANGED
|
@@ -15,3 +15,4 @@ export declare const isSymbol: (val: any) => val is symbol;
|
|
|
15
15
|
export declare function isPromise(obj: any): obj is Promise<any>;
|
|
16
16
|
export declare function isNilOrEmptyString(str?: string | undefined | null): str is null | undefined | '';
|
|
17
17
|
export declare function checkMeta(meta?: {}, data?: {}): boolean;
|
|
18
|
+
export declare function safeBoolean(value?: undefined | null | boolean | string): boolean;
|
package/dist/check.js
CHANGED
package/dist/utils.d.ts
CHANGED
|
@@ -6,3 +6,6 @@ export declare function setProperty<T>(obj: object, name: string, value: T): voi
|
|
|
6
6
|
export declare function getProperty<T>(obj: object, name: string, sep?: string): T | undefined;
|
|
7
7
|
export declare function getPropertyObject<T>(obj: object, name: string, sep?: string): T | undefined;
|
|
8
8
|
export declare function createFunction(expression: string, scopeKeys?: string[]): Function;
|
|
9
|
+
export declare function evaluateSimple(expression: string): any;
|
|
10
|
+
export declare function getRandomInt(size: number, start?: number): number;
|
|
11
|
+
export declare function combineQueries(url?: string, queries?: Record<string, any>): string | undefined;
|
package/dist/utils.js
CHANGED
|
@@ -83,18 +83,34 @@ export function createFunction(expression, scopeKeys) {
|
|
|
83
83
|
}
|
|
84
84
|
return fn;
|
|
85
85
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
//
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
//
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
86
|
+
export function evaluateSimple(expression) {
|
|
87
|
+
const fn = createFunction(expression);
|
|
88
|
+
return fn();
|
|
89
|
+
}
|
|
90
|
+
export function getRandomInt(size, start = 0) {
|
|
91
|
+
return Math.floor(Math.random() * size) + start;
|
|
92
|
+
}
|
|
93
|
+
export function combineQueries(url, queries) {
|
|
94
|
+
//
|
|
95
|
+
if (!queries)
|
|
96
|
+
return url;
|
|
97
|
+
//
|
|
98
|
+
const parts = [];
|
|
99
|
+
for (const key of Object.keys(queries)) {
|
|
100
|
+
parts.push(`${encodeURIComponent(key)}=${encodeURIComponent(queries[key])}`);
|
|
101
|
+
}
|
|
102
|
+
if (parts.length === 0)
|
|
103
|
+
return url;
|
|
104
|
+
//
|
|
105
|
+
const str = parts.join('&');
|
|
106
|
+
//
|
|
107
|
+
if (!url)
|
|
108
|
+
return `?${str}`;
|
|
109
|
+
//
|
|
110
|
+
const pos = url.indexOf('?');
|
|
111
|
+
if (pos === -1)
|
|
112
|
+
return `${url}?${str}`;
|
|
113
|
+
if (pos === url.length - 1)
|
|
114
|
+
return `${url}${str}`;
|
|
115
|
+
return `${url}&${str}`;
|
|
116
|
+
}
|