@cabloy/utils 1.0.6 → 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 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
@@ -59,3 +59,8 @@ export function checkMeta(meta, data) {
59
59
  // default
60
60
  return true;
61
61
  }
62
+ export function safeBoolean(value) {
63
+ if (isNil(value) || value === 'false' || value === '0')
64
+ return false;
65
+ return Boolean(value);
66
+ }
package/dist/utils.d.ts CHANGED
@@ -7,3 +7,5 @@ export declare function getProperty<T>(obj: object, name: string, sep?: string):
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
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
@@ -87,3 +87,30 @@ export function evaluateSimple(expression) {
87
87
  const fn = createFunction(expression);
88
88
  return fn();
89
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
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cabloy/utils",
3
3
  "type": "module",
4
- "version": "1.0.6",
4
+ "version": "1.0.7",
5
5
  "description": "cabloy utils",
6
6
  "publishConfig": {
7
7
  "access": "public"