@purr-react-core/utils.helpers 0.0.14
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/LICENSE +21 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.cts +200 -0
- package/dist/index.d.ts +200 -0
- package/dist/index.js +1 -0
- package/package.json +37 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Dinh Thien Phuc
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
'use strict';var g=async n=>{try{return {error:null,result:await n}}catch(o){return {error:o,result:null}}},s=n=>{try{return n==="undefined"?null:JSON.parse(n??"")}catch{return null}},f=()=>{},c=n=>n.charAt(0).toUpperCase()+n.slice(1).toLowerCase(),p=(n,o=/-/)=>n.split(o).map(c).join(""),w=(n,o)=>(e,t)=>{let a=n.every(r=>o(r,e,t)??true),u=Object.keys(e).every(r=>n.includes(r)?true:e[r]===t[r]);return a&&u},d=n=>n;var m=()=>{window.location.reload();},k=(n,o="localStorage")=>s(window[o].getItem(n)),S=(n,o,e="localStorage")=>{window[e].setItem(n,JSON.stringify(o));},h=(n,o="localStorage")=>{window[o].removeItem(n);},T=(n="localStorage")=>{window[n].clear();};var i=n=>{if(Array.isArray(n))return true;if(n&&typeof n=="object"&&"length"in n&&typeof n.length=="number")try{for(let o=0;o<n.length;o++)if(!(o in n))return !1;return !0}catch{return false}return false},b=n=>i(n)&&n.length>0,l=n=>typeof n=="object"&&n!==null&&!i(n)&&!(n instanceof Date)&&!(n instanceof RegExp)&&!(n instanceof Error)&&!(n instanceof Function),v=(n,o)=>!l(n)||o.length===0?false:o.some(e=>Object.prototype.hasOwnProperty.call(n,e)),O=n=>typeof n=="string"||n instanceof String,P=n=>typeof n=="number"&&!isNaN(n)||n instanceof Number&&!isNaN(n.valueOf()),R=n=>typeof n=="boolean"||n instanceof Boolean,A=n=>typeof n=="function"&&!/^class\s/.test(Function.prototype.toString.call(n)),E=n=>n instanceof Date&&!isNaN(n.getTime()),j=n=>n===void 0,D=n=>n===null,F=n=>n==null,B=n=>typeof n=="object"&&n!==null&&typeof n.then=="function"&&typeof n.catch=="function";exports.arePropsShallowEqual=w;exports.capitalize=c;exports.cast=d;exports.clearStorage=T;exports.doNothing=f;exports.getFromStorage=k;exports.hasProperties=v;exports.isArray=i;exports.isBoolean=R;exports.isDate=E;exports.isFunction=A;exports.isNil=F;exports.isNonEmptyArray=b;exports.isNull=D;exports.isNumber=P;exports.isObject=l;exports.isPromise=B;exports.isString=O;exports.isUndefined=j;exports.parseJSON=s;exports.reload=m;exports.removeFromStorage=h;exports.setToStorage=S;exports.toCamelCase=p;exports.tryDo=g;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import { TAsyncBoundary } from '@purr-react-core/utils.definitions';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Attempts to resolve the given promise and returns an object containing either the result or an error.
|
|
5
|
+
*
|
|
6
|
+
* @template T - The type of the resolved value of the promise.
|
|
7
|
+
* @param {Promise<T>} promise - The promise to be resolved.
|
|
8
|
+
* @returns {Promise<TAsyncBoundary<T>>} A promise that resolves to an object containing either the result or an error.
|
|
9
|
+
*/
|
|
10
|
+
declare const tryDo: <T>(promise: Promise<T>) => Promise<TAsyncBoundary<T>>;
|
|
11
|
+
/**
|
|
12
|
+
* Parses a JSON string and returns the corresponding object.
|
|
13
|
+
*
|
|
14
|
+
* @template T - The type of the object to be returned.
|
|
15
|
+
* @param {string | null} jsonString - The JSON string to parse. If the string is "undefined" or null, the function returns null.
|
|
16
|
+
* @returns {T | null} - The parsed object, or null if the input is "undefined", null, or if parsing fails.
|
|
17
|
+
*/
|
|
18
|
+
declare const parseJSON: <T>(jsonString: string | null) => T | null;
|
|
19
|
+
/**
|
|
20
|
+
* A no-operation (noop) function that does nothing.
|
|
21
|
+
*
|
|
22
|
+
* This function can be used as a placeholder or default callback
|
|
23
|
+
* where a function is required but no action is needed.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```typescript
|
|
27
|
+
* doNothing(); // This will perform no action
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
declare const doNothing: () => void;
|
|
31
|
+
/**
|
|
32
|
+
* Capitalizes the first character of the given string and converts the rest to lowercase.
|
|
33
|
+
*
|
|
34
|
+
* @param str - The string to be capitalized.
|
|
35
|
+
* @returns The capitalized string.
|
|
36
|
+
*/
|
|
37
|
+
declare const capitalize: (str: string) => string;
|
|
38
|
+
/**
|
|
39
|
+
* Converts a string to camel case format.
|
|
40
|
+
*
|
|
41
|
+
* @param str - The string to be converted.
|
|
42
|
+
* @param divider - A regular expression used to split the string into words. Defaults to a hyphen (`-`).
|
|
43
|
+
* @returns The camel case formatted string.
|
|
44
|
+
*/
|
|
45
|
+
declare const toCamelCase: (str: string, divider?: RegExp) => string;
|
|
46
|
+
/**
|
|
47
|
+
* Compares the shallow equality of specific properties and other properties between two objects.
|
|
48
|
+
*
|
|
49
|
+
* @param keys - An array of strings representing the keys of the properties to compare.
|
|
50
|
+
* @param callback - A function that takes a key, previous properties, and next properties, and returns a boolean or undefined.
|
|
51
|
+
* If the callback returns `undefined`, the comparison for that key defaults to `true`.
|
|
52
|
+
* @returns A function that takes two objects (`prevProps` and `nextProps`) and returns `true` if the specified properties and other properties are shallowly equal, otherwise `false`.
|
|
53
|
+
*/
|
|
54
|
+
declare const arePropsShallowEqual: (keys: string[], callback: (key: string, prevProps: Record<string, unknown>, nextProps: Record<string, unknown>) => boolean | undefined) => (prevProps: Record<string, unknown>, nextProps: Record<string, unknown>) => boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Casts a value to a specified type.
|
|
57
|
+
* Use it wisely, as it can lead to type errors if not used correctly.
|
|
58
|
+
*
|
|
59
|
+
* @template T - The type to cast the value to.
|
|
60
|
+
* @param {unknown} value - The value to cast.
|
|
61
|
+
* @returns {T} The cast value.
|
|
62
|
+
*/
|
|
63
|
+
declare const cast: <T>(value: unknown) => T;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Reloads the current page.
|
|
67
|
+
*
|
|
68
|
+
* This function triggers a full page reload by calling `window.location.reload()`.
|
|
69
|
+
*/
|
|
70
|
+
declare const reload: () => void;
|
|
71
|
+
/**
|
|
72
|
+
* Retrieves a value from the specified web storage (localStorage or sessionStorage).
|
|
73
|
+
*
|
|
74
|
+
* @template T - The expected type of the retrieved value.
|
|
75
|
+
* @param {string} key - The key of the item to retrieve from storage.
|
|
76
|
+
* @param {string} [storage="localStorage"] - The type of web storage to use ("localStorage" or "sessionStorage").
|
|
77
|
+
* @returns {T | null} - The parsed value from storage, or null if the key does not exist.
|
|
78
|
+
*/
|
|
79
|
+
declare const getFromStorage: <T>(key: string, storage?: "localStorage" | "sessionStorage") => T | null;
|
|
80
|
+
/**
|
|
81
|
+
* Sets a value to the specified web storage (localStorage or sessionStorage).
|
|
82
|
+
*
|
|
83
|
+
* @template T - The type of the value to set.
|
|
84
|
+
* @param {string} key - The key of the item to set in storage.
|
|
85
|
+
* @param {T} value - The value to set in storage.
|
|
86
|
+
* @param {string} [storage="localStorage"] - The type of web storage to use ("localStorage" or "sessionStorage").
|
|
87
|
+
* @returns {void}
|
|
88
|
+
*/
|
|
89
|
+
declare const setToStorage: <T>(key: string, value: T, storage?: "localStorage" | "sessionStorage") => void;
|
|
90
|
+
/**
|
|
91
|
+
* Removes an item from the specified web storage (localStorage or sessionStorage).
|
|
92
|
+
*
|
|
93
|
+
* @param {string} key - The key of the item to remove from storage.
|
|
94
|
+
* @param {string} [storage="localStorage"] - The type of web storage to use ("localStorage" or "sessionStorage").
|
|
95
|
+
* @returns {void}
|
|
96
|
+
*/
|
|
97
|
+
declare const removeFromStorage: (key: string, storage?: "localStorage" | "sessionStorage") => void;
|
|
98
|
+
/**
|
|
99
|
+
* Clears all items from the specified web storage (localStorage or sessionStorage).
|
|
100
|
+
*
|
|
101
|
+
* @param {string} [storage="localStorage"] - The type of web storage to use ("localStorage" or "sessionStorage").
|
|
102
|
+
* @returns {void}
|
|
103
|
+
*/
|
|
104
|
+
declare const clearStorage: (storage?: "localStorage" | "sessionStorage") => void;
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Checks if the input is an array.
|
|
108
|
+
*
|
|
109
|
+
* @param {unknown} input - The input to check.
|
|
110
|
+
* @returns {boolean} True if the input is an array, false otherwise.
|
|
111
|
+
*/
|
|
112
|
+
declare const isArray: (input: unknown) => input is unknown[];
|
|
113
|
+
/**
|
|
114
|
+
* Checks if the input is a non-empty array.
|
|
115
|
+
*
|
|
116
|
+
* @param {unknown} input - The input to check.
|
|
117
|
+
* @returns {boolean} True if the input is a non-empty array, false otherwise.
|
|
118
|
+
*/
|
|
119
|
+
declare const isNonEmptyArray: (input: unknown) => input is unknown[];
|
|
120
|
+
/**
|
|
121
|
+
* Checks if the input is an object.
|
|
122
|
+
*
|
|
123
|
+
* @param {unknown} input - The input to check.
|
|
124
|
+
* @returns {boolean} True if the input is an object, false otherwise.
|
|
125
|
+
*/
|
|
126
|
+
declare const isObject: (input: unknown) => input is Record<string, unknown>;
|
|
127
|
+
/**
|
|
128
|
+
* Checks if the input object has the specified properties.
|
|
129
|
+
*
|
|
130
|
+
* @param {unknown} obj - The object to check.
|
|
131
|
+
* @param {string[]} properties - The properties to check.
|
|
132
|
+
* @returns {boolean} True if the input object has the specified properties, false otherwise.
|
|
133
|
+
*/
|
|
134
|
+
declare const hasProperties: (obj: unknown, properties: string[]) => obj is Record<string, unknown>;
|
|
135
|
+
/**
|
|
136
|
+
* Checks if the input is a string.
|
|
137
|
+
*
|
|
138
|
+
* @param {unknown} input - The input to check.
|
|
139
|
+
* @returns {boolean} True if the input is a string, false otherwise.
|
|
140
|
+
*/
|
|
141
|
+
declare const isString: (input: unknown) => input is string;
|
|
142
|
+
/**
|
|
143
|
+
* Checks if the input is a number.
|
|
144
|
+
*
|
|
145
|
+
* @param {unknown} input - The input to check.
|
|
146
|
+
* @returns {boolean} True if the input is a number, false otherwise.
|
|
147
|
+
*/
|
|
148
|
+
declare const isNumber: (input: unknown) => input is number;
|
|
149
|
+
/**
|
|
150
|
+
* Checks if the input is a boolean.
|
|
151
|
+
*
|
|
152
|
+
* @param {unknown} input - The input to check.
|
|
153
|
+
* @returns {boolean} True if the input is a boolean, false otherwise.
|
|
154
|
+
*/
|
|
155
|
+
declare const isBoolean: (input: unknown) => input is boolean;
|
|
156
|
+
/**
|
|
157
|
+
* Checks if the input is a function.
|
|
158
|
+
*
|
|
159
|
+
* @param {unknown} input - The input to check.
|
|
160
|
+
* @returns {boolean} True if the input is a function, false otherwise.
|
|
161
|
+
*/
|
|
162
|
+
declare const isFunction: (input: unknown) => input is (...args: unknown[]) => unknown;
|
|
163
|
+
/**
|
|
164
|
+
* Checks if the input is a date.
|
|
165
|
+
*
|
|
166
|
+
* @param {unknown} input - The input to check.
|
|
167
|
+
* @returns {boolean} True if the input is a date, false otherwise.
|
|
168
|
+
*/
|
|
169
|
+
declare const isDate: (input: unknown) => input is Date;
|
|
170
|
+
/**
|
|
171
|
+
* Checks if the input is undefined.
|
|
172
|
+
*
|
|
173
|
+
* @param {unknown} input - The input to check.
|
|
174
|
+
* @returns {boolean} True if the input is undefined, false otherwise.
|
|
175
|
+
*/
|
|
176
|
+
declare const isUndefined: (input: unknown) => input is undefined;
|
|
177
|
+
/**
|
|
178
|
+
* Checks if the input is null.
|
|
179
|
+
*
|
|
180
|
+
* @param {unknown} input - The input to check.
|
|
181
|
+
* @returns {boolean} True if the input is null, false otherwise.
|
|
182
|
+
*/
|
|
183
|
+
declare const isNull: (input: unknown) => input is null;
|
|
184
|
+
/**
|
|
185
|
+
* Checks if the input is null or undefined.
|
|
186
|
+
*
|
|
187
|
+
* @param {unknown} input - The input to check.
|
|
188
|
+
* @returns {boolean} True if the input is null or undefined, false otherwise.
|
|
189
|
+
*/
|
|
190
|
+
declare const isNil: (input: unknown) => input is null | undefined;
|
|
191
|
+
/**
|
|
192
|
+
* Checks if the input is a promise.
|
|
193
|
+
*
|
|
194
|
+
* @param {unknown} input - The input to check.
|
|
195
|
+
* @returns {boolean} True if the input is a promise, false otherwise.
|
|
196
|
+
* @template T - The type of the promise.
|
|
197
|
+
*/
|
|
198
|
+
declare const isPromise: <T = unknown>(input: unknown) => input is Promise<T>;
|
|
199
|
+
|
|
200
|
+
export { arePropsShallowEqual, capitalize, cast, clearStorage, doNothing, getFromStorage, hasProperties, isArray, isBoolean, isDate, isFunction, isNil, isNonEmptyArray, isNull, isNumber, isObject, isPromise, isString, isUndefined, parseJSON, reload, removeFromStorage, setToStorage, toCamelCase, tryDo };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import { TAsyncBoundary } from '@purr-react-core/utils.definitions';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Attempts to resolve the given promise and returns an object containing either the result or an error.
|
|
5
|
+
*
|
|
6
|
+
* @template T - The type of the resolved value of the promise.
|
|
7
|
+
* @param {Promise<T>} promise - The promise to be resolved.
|
|
8
|
+
* @returns {Promise<TAsyncBoundary<T>>} A promise that resolves to an object containing either the result or an error.
|
|
9
|
+
*/
|
|
10
|
+
declare const tryDo: <T>(promise: Promise<T>) => Promise<TAsyncBoundary<T>>;
|
|
11
|
+
/**
|
|
12
|
+
* Parses a JSON string and returns the corresponding object.
|
|
13
|
+
*
|
|
14
|
+
* @template T - The type of the object to be returned.
|
|
15
|
+
* @param {string | null} jsonString - The JSON string to parse. If the string is "undefined" or null, the function returns null.
|
|
16
|
+
* @returns {T | null} - The parsed object, or null if the input is "undefined", null, or if parsing fails.
|
|
17
|
+
*/
|
|
18
|
+
declare const parseJSON: <T>(jsonString: string | null) => T | null;
|
|
19
|
+
/**
|
|
20
|
+
* A no-operation (noop) function that does nothing.
|
|
21
|
+
*
|
|
22
|
+
* This function can be used as a placeholder or default callback
|
|
23
|
+
* where a function is required but no action is needed.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```typescript
|
|
27
|
+
* doNothing(); // This will perform no action
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
declare const doNothing: () => void;
|
|
31
|
+
/**
|
|
32
|
+
* Capitalizes the first character of the given string and converts the rest to lowercase.
|
|
33
|
+
*
|
|
34
|
+
* @param str - The string to be capitalized.
|
|
35
|
+
* @returns The capitalized string.
|
|
36
|
+
*/
|
|
37
|
+
declare const capitalize: (str: string) => string;
|
|
38
|
+
/**
|
|
39
|
+
* Converts a string to camel case format.
|
|
40
|
+
*
|
|
41
|
+
* @param str - The string to be converted.
|
|
42
|
+
* @param divider - A regular expression used to split the string into words. Defaults to a hyphen (`-`).
|
|
43
|
+
* @returns The camel case formatted string.
|
|
44
|
+
*/
|
|
45
|
+
declare const toCamelCase: (str: string, divider?: RegExp) => string;
|
|
46
|
+
/**
|
|
47
|
+
* Compares the shallow equality of specific properties and other properties between two objects.
|
|
48
|
+
*
|
|
49
|
+
* @param keys - An array of strings representing the keys of the properties to compare.
|
|
50
|
+
* @param callback - A function that takes a key, previous properties, and next properties, and returns a boolean or undefined.
|
|
51
|
+
* If the callback returns `undefined`, the comparison for that key defaults to `true`.
|
|
52
|
+
* @returns A function that takes two objects (`prevProps` and `nextProps`) and returns `true` if the specified properties and other properties are shallowly equal, otherwise `false`.
|
|
53
|
+
*/
|
|
54
|
+
declare const arePropsShallowEqual: (keys: string[], callback: (key: string, prevProps: Record<string, unknown>, nextProps: Record<string, unknown>) => boolean | undefined) => (prevProps: Record<string, unknown>, nextProps: Record<string, unknown>) => boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Casts a value to a specified type.
|
|
57
|
+
* Use it wisely, as it can lead to type errors if not used correctly.
|
|
58
|
+
*
|
|
59
|
+
* @template T - The type to cast the value to.
|
|
60
|
+
* @param {unknown} value - The value to cast.
|
|
61
|
+
* @returns {T} The cast value.
|
|
62
|
+
*/
|
|
63
|
+
declare const cast: <T>(value: unknown) => T;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Reloads the current page.
|
|
67
|
+
*
|
|
68
|
+
* This function triggers a full page reload by calling `window.location.reload()`.
|
|
69
|
+
*/
|
|
70
|
+
declare const reload: () => void;
|
|
71
|
+
/**
|
|
72
|
+
* Retrieves a value from the specified web storage (localStorage or sessionStorage).
|
|
73
|
+
*
|
|
74
|
+
* @template T - The expected type of the retrieved value.
|
|
75
|
+
* @param {string} key - The key of the item to retrieve from storage.
|
|
76
|
+
* @param {string} [storage="localStorage"] - The type of web storage to use ("localStorage" or "sessionStorage").
|
|
77
|
+
* @returns {T | null} - The parsed value from storage, or null if the key does not exist.
|
|
78
|
+
*/
|
|
79
|
+
declare const getFromStorage: <T>(key: string, storage?: "localStorage" | "sessionStorage") => T | null;
|
|
80
|
+
/**
|
|
81
|
+
* Sets a value to the specified web storage (localStorage or sessionStorage).
|
|
82
|
+
*
|
|
83
|
+
* @template T - The type of the value to set.
|
|
84
|
+
* @param {string} key - The key of the item to set in storage.
|
|
85
|
+
* @param {T} value - The value to set in storage.
|
|
86
|
+
* @param {string} [storage="localStorage"] - The type of web storage to use ("localStorage" or "sessionStorage").
|
|
87
|
+
* @returns {void}
|
|
88
|
+
*/
|
|
89
|
+
declare const setToStorage: <T>(key: string, value: T, storage?: "localStorage" | "sessionStorage") => void;
|
|
90
|
+
/**
|
|
91
|
+
* Removes an item from the specified web storage (localStorage or sessionStorage).
|
|
92
|
+
*
|
|
93
|
+
* @param {string} key - The key of the item to remove from storage.
|
|
94
|
+
* @param {string} [storage="localStorage"] - The type of web storage to use ("localStorage" or "sessionStorage").
|
|
95
|
+
* @returns {void}
|
|
96
|
+
*/
|
|
97
|
+
declare const removeFromStorage: (key: string, storage?: "localStorage" | "sessionStorage") => void;
|
|
98
|
+
/**
|
|
99
|
+
* Clears all items from the specified web storage (localStorage or sessionStorage).
|
|
100
|
+
*
|
|
101
|
+
* @param {string} [storage="localStorage"] - The type of web storage to use ("localStorage" or "sessionStorage").
|
|
102
|
+
* @returns {void}
|
|
103
|
+
*/
|
|
104
|
+
declare const clearStorage: (storage?: "localStorage" | "sessionStorage") => void;
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Checks if the input is an array.
|
|
108
|
+
*
|
|
109
|
+
* @param {unknown} input - The input to check.
|
|
110
|
+
* @returns {boolean} True if the input is an array, false otherwise.
|
|
111
|
+
*/
|
|
112
|
+
declare const isArray: (input: unknown) => input is unknown[];
|
|
113
|
+
/**
|
|
114
|
+
* Checks if the input is a non-empty array.
|
|
115
|
+
*
|
|
116
|
+
* @param {unknown} input - The input to check.
|
|
117
|
+
* @returns {boolean} True if the input is a non-empty array, false otherwise.
|
|
118
|
+
*/
|
|
119
|
+
declare const isNonEmptyArray: (input: unknown) => input is unknown[];
|
|
120
|
+
/**
|
|
121
|
+
* Checks if the input is an object.
|
|
122
|
+
*
|
|
123
|
+
* @param {unknown} input - The input to check.
|
|
124
|
+
* @returns {boolean} True if the input is an object, false otherwise.
|
|
125
|
+
*/
|
|
126
|
+
declare const isObject: (input: unknown) => input is Record<string, unknown>;
|
|
127
|
+
/**
|
|
128
|
+
* Checks if the input object has the specified properties.
|
|
129
|
+
*
|
|
130
|
+
* @param {unknown} obj - The object to check.
|
|
131
|
+
* @param {string[]} properties - The properties to check.
|
|
132
|
+
* @returns {boolean} True if the input object has the specified properties, false otherwise.
|
|
133
|
+
*/
|
|
134
|
+
declare const hasProperties: (obj: unknown, properties: string[]) => obj is Record<string, unknown>;
|
|
135
|
+
/**
|
|
136
|
+
* Checks if the input is a string.
|
|
137
|
+
*
|
|
138
|
+
* @param {unknown} input - The input to check.
|
|
139
|
+
* @returns {boolean} True if the input is a string, false otherwise.
|
|
140
|
+
*/
|
|
141
|
+
declare const isString: (input: unknown) => input is string;
|
|
142
|
+
/**
|
|
143
|
+
* Checks if the input is a number.
|
|
144
|
+
*
|
|
145
|
+
* @param {unknown} input - The input to check.
|
|
146
|
+
* @returns {boolean} True if the input is a number, false otherwise.
|
|
147
|
+
*/
|
|
148
|
+
declare const isNumber: (input: unknown) => input is number;
|
|
149
|
+
/**
|
|
150
|
+
* Checks if the input is a boolean.
|
|
151
|
+
*
|
|
152
|
+
* @param {unknown} input - The input to check.
|
|
153
|
+
* @returns {boolean} True if the input is a boolean, false otherwise.
|
|
154
|
+
*/
|
|
155
|
+
declare const isBoolean: (input: unknown) => input is boolean;
|
|
156
|
+
/**
|
|
157
|
+
* Checks if the input is a function.
|
|
158
|
+
*
|
|
159
|
+
* @param {unknown} input - The input to check.
|
|
160
|
+
* @returns {boolean} True if the input is a function, false otherwise.
|
|
161
|
+
*/
|
|
162
|
+
declare const isFunction: (input: unknown) => input is (...args: unknown[]) => unknown;
|
|
163
|
+
/**
|
|
164
|
+
* Checks if the input is a date.
|
|
165
|
+
*
|
|
166
|
+
* @param {unknown} input - The input to check.
|
|
167
|
+
* @returns {boolean} True if the input is a date, false otherwise.
|
|
168
|
+
*/
|
|
169
|
+
declare const isDate: (input: unknown) => input is Date;
|
|
170
|
+
/**
|
|
171
|
+
* Checks if the input is undefined.
|
|
172
|
+
*
|
|
173
|
+
* @param {unknown} input - The input to check.
|
|
174
|
+
* @returns {boolean} True if the input is undefined, false otherwise.
|
|
175
|
+
*/
|
|
176
|
+
declare const isUndefined: (input: unknown) => input is undefined;
|
|
177
|
+
/**
|
|
178
|
+
* Checks if the input is null.
|
|
179
|
+
*
|
|
180
|
+
* @param {unknown} input - The input to check.
|
|
181
|
+
* @returns {boolean} True if the input is null, false otherwise.
|
|
182
|
+
*/
|
|
183
|
+
declare const isNull: (input: unknown) => input is null;
|
|
184
|
+
/**
|
|
185
|
+
* Checks if the input is null or undefined.
|
|
186
|
+
*
|
|
187
|
+
* @param {unknown} input - The input to check.
|
|
188
|
+
* @returns {boolean} True if the input is null or undefined, false otherwise.
|
|
189
|
+
*/
|
|
190
|
+
declare const isNil: (input: unknown) => input is null | undefined;
|
|
191
|
+
/**
|
|
192
|
+
* Checks if the input is a promise.
|
|
193
|
+
*
|
|
194
|
+
* @param {unknown} input - The input to check.
|
|
195
|
+
* @returns {boolean} True if the input is a promise, false otherwise.
|
|
196
|
+
* @template T - The type of the promise.
|
|
197
|
+
*/
|
|
198
|
+
declare const isPromise: <T = unknown>(input: unknown) => input is Promise<T>;
|
|
199
|
+
|
|
200
|
+
export { arePropsShallowEqual, capitalize, cast, clearStorage, doNothing, getFromStorage, hasProperties, isArray, isBoolean, isDate, isFunction, isNil, isNonEmptyArray, isNull, isNumber, isObject, isPromise, isString, isUndefined, parseJSON, reload, removeFromStorage, setToStorage, toCamelCase, tryDo };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var g=async n=>{try{return {error:null,result:await n}}catch(o){return {error:o,result:null}}},s=n=>{try{return n==="undefined"?null:JSON.parse(n??"")}catch{return null}},f=()=>{},c=n=>n.charAt(0).toUpperCase()+n.slice(1).toLowerCase(),p=(n,o=/-/)=>n.split(o).map(c).join(""),w=(n,o)=>(e,t)=>{let a=n.every(r=>o(r,e,t)??true),u=Object.keys(e).every(r=>n.includes(r)?true:e[r]===t[r]);return a&&u},d=n=>n;var m=()=>{window.location.reload();},k=(n,o="localStorage")=>s(window[o].getItem(n)),S=(n,o,e="localStorage")=>{window[e].setItem(n,JSON.stringify(o));},h=(n,o="localStorage")=>{window[o].removeItem(n);},T=(n="localStorage")=>{window[n].clear();};var i=n=>{if(Array.isArray(n))return true;if(n&&typeof n=="object"&&"length"in n&&typeof n.length=="number")try{for(let o=0;o<n.length;o++)if(!(o in n))return !1;return !0}catch{return false}return false},b=n=>i(n)&&n.length>0,l=n=>typeof n=="object"&&n!==null&&!i(n)&&!(n instanceof Date)&&!(n instanceof RegExp)&&!(n instanceof Error)&&!(n instanceof Function),v=(n,o)=>!l(n)||o.length===0?false:o.some(e=>Object.prototype.hasOwnProperty.call(n,e)),O=n=>typeof n=="string"||n instanceof String,P=n=>typeof n=="number"&&!isNaN(n)||n instanceof Number&&!isNaN(n.valueOf()),R=n=>typeof n=="boolean"||n instanceof Boolean,A=n=>typeof n=="function"&&!/^class\s/.test(Function.prototype.toString.call(n)),E=n=>n instanceof Date&&!isNaN(n.getTime()),j=n=>n===void 0,D=n=>n===null,F=n=>n==null,B=n=>typeof n=="object"&&n!==null&&typeof n.then=="function"&&typeof n.catch=="function";export{w as arePropsShallowEqual,c as capitalize,d as cast,T as clearStorage,f as doNothing,k as getFromStorage,v as hasProperties,i as isArray,R as isBoolean,E as isDate,A as isFunction,F as isNil,b as isNonEmptyArray,D as isNull,P as isNumber,l as isObject,B as isPromise,O as isString,j as isUndefined,s as parseJSON,m as reload,h as removeFromStorage,S as setToStorage,p as toCamelCase,g as tryDo};
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@purr-react-core/utils.helpers",
|
|
3
|
+
"version": "0.0.14",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "dist/index.cjs",
|
|
6
|
+
"module": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"default": "./dist/index.js"
|
|
13
|
+
},
|
|
14
|
+
"require": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"default": "./dist/index.cjs"
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"dist"
|
|
22
|
+
],
|
|
23
|
+
"author": "@DinhThienPhuc",
|
|
24
|
+
"license": "ISC",
|
|
25
|
+
"description": "",
|
|
26
|
+
"sideEffects": false,
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@purr-react-core/utils.definitions": "0.0.14"
|
|
29
|
+
},
|
|
30
|
+
"scripts": {
|
|
31
|
+
"dev": "vite build --watch",
|
|
32
|
+
"build": "tsc && vite build",
|
|
33
|
+
"build:vite": "tsc && vite build",
|
|
34
|
+
"build:tsup": "tsup",
|
|
35
|
+
"lint": "eslint . --ext ts,tsx --max-warnings 0"
|
|
36
|
+
}
|
|
37
|
+
}
|