ag-common 0.0.662 → 0.0.664
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.
|
@@ -7,7 +7,7 @@ export declare function clamp({ value, min, max, }: {
|
|
|
7
7
|
max: number;
|
|
8
8
|
}): number;
|
|
9
9
|
export declare function sumArray(array: number[]): number;
|
|
10
|
-
export declare
|
|
10
|
+
export declare const isNumber: (num: string) => boolean;
|
|
11
11
|
export declare function toFixedDown(num: number, scale: number): number;
|
|
12
12
|
/**
|
|
13
13
|
* get percentage of value within supplied range
|
|
@@ -38,11 +38,7 @@ function sumArray(array) {
|
|
|
38
38
|
return array.reduce((a, b) => a + b, 0);
|
|
39
39
|
}
|
|
40
40
|
exports.sumArray = sumArray;
|
|
41
|
-
|
|
42
|
-
const re = new RegExp(`(\\d+\\.?\\d*)(\\d)`);
|
|
43
|
-
const m = val.toString().match(re);
|
|
44
|
-
return !!m;
|
|
45
|
-
}
|
|
41
|
+
const isNumber = (num) => /^-{0,1}\d*\.{0,1}\d+$/.test(num);
|
|
46
42
|
exports.isNumber = isNumber;
|
|
47
43
|
function toFixedDown(num, scale) {
|
|
48
44
|
if (!`${num}`.includes('e')) {
|
|
@@ -47,8 +47,17 @@ joinKeys: string): string;
|
|
|
47
47
|
* @returns
|
|
48
48
|
*/
|
|
49
49
|
export declare const castObject: <TIn, TOut>(orig: Record<string, TIn>, castF: (t: TIn) => TOut) => Record<string, TOut>;
|
|
50
|
+
/**
|
|
51
|
+
* run func over values in object to filter
|
|
52
|
+
* @param orig
|
|
53
|
+
* @param castF
|
|
54
|
+
* @returns
|
|
55
|
+
*/
|
|
56
|
+
export declare const filterObject: <TA extends Record<string | number, TB>, TB>(orig: TA, filterF: (t: TB) => boolean) => Partial<TA>;
|
|
57
|
+
/** remove key values from an object where the value is null or undefined or other specific passed in values */
|
|
58
|
+
export declare const removeUndefValuesFromObject: <TA>(orig: Record<string, TA>) => Record<string, TA extends null | undefined ? never : TA>;
|
|
50
59
|
/** remove key values from an object where the value is null or undefined or other specific passed in values */
|
|
51
|
-
export declare const
|
|
60
|
+
export declare const removeUndefValuesFromObjectAdditional: <T>(orig: Record<string, T>, ...additionalRemoves: T[]) => Record<string, T>;
|
|
52
61
|
/**
|
|
53
62
|
* cast Record<string,string[]|string> to Record<string,string>. can be used for querystring params
|
|
54
63
|
* @param orig
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isObject = exports.castStringlyObject = exports.removeUndefValuesFromObject = exports.castObject = exports.objectToString = exports.paramsToObject = exports.objectAlphaSort = exports.objectToArray = exports.getObjectKeysAsNumber = exports.objectKeysToLowerCase = exports.isJson = exports.tryJsonParse = void 0;
|
|
3
|
+
exports.isObject = exports.castStringlyObject = exports.removeUndefValuesFromObjectAdditional = exports.removeUndefValuesFromObject = exports.filterObject = exports.castObject = exports.objectToString = exports.paramsToObject = exports.objectAlphaSort = exports.objectToArray = exports.getObjectKeysAsNumber = exports.objectKeysToLowerCase = exports.isJson = exports.tryJsonParse = void 0;
|
|
4
4
|
const tryJsonParse = (str, defaultValue) => {
|
|
5
5
|
if (!str) {
|
|
6
6
|
return null;
|
|
@@ -130,8 +130,37 @@ const castObject = (orig, castF) => {
|
|
|
130
130
|
return ret;
|
|
131
131
|
};
|
|
132
132
|
exports.castObject = castObject;
|
|
133
|
+
/**
|
|
134
|
+
* run func over values in object to filter
|
|
135
|
+
* @param orig
|
|
136
|
+
* @param castF
|
|
137
|
+
* @returns
|
|
138
|
+
*/
|
|
139
|
+
const filterObject = (orig, filterF) => {
|
|
140
|
+
const ret = {};
|
|
141
|
+
Object.entries(orig).forEach(([k, v]) => {
|
|
142
|
+
if (filterF(v)) {
|
|
143
|
+
//@ts-ignore
|
|
144
|
+
ret[k] = v;
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
return ret;
|
|
148
|
+
};
|
|
149
|
+
exports.filterObject = filterObject;
|
|
150
|
+
/** remove key values from an object where the value is null or undefined or other specific passed in values */
|
|
151
|
+
const removeUndefValuesFromObject = (orig) => {
|
|
152
|
+
const ret = {};
|
|
153
|
+
Object.entries(orig).forEach(([k, v]) => {
|
|
154
|
+
if (v !== null && v !== undefined) {
|
|
155
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
156
|
+
ret[k] = v;
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
return ret;
|
|
160
|
+
};
|
|
161
|
+
exports.removeUndefValuesFromObject = removeUndefValuesFromObject;
|
|
133
162
|
/** remove key values from an object where the value is null or undefined or other specific passed in values */
|
|
134
|
-
const
|
|
163
|
+
const removeUndefValuesFromObjectAdditional = (orig,
|
|
135
164
|
/** other than null or undefined */
|
|
136
165
|
...additionalRemoves) => {
|
|
137
166
|
const ret = {};
|
|
@@ -142,7 +171,7 @@ const removeUndefValuesFromObject = (orig,
|
|
|
142
171
|
});
|
|
143
172
|
return ret;
|
|
144
173
|
};
|
|
145
|
-
exports.
|
|
174
|
+
exports.removeUndefValuesFromObjectAdditional = removeUndefValuesFromObjectAdditional;
|
|
146
175
|
/**
|
|
147
176
|
* cast Record<string,string[]|string> to Record<string,string>. can be used for querystring params
|
|
148
177
|
* @param orig
|
package/package.json
CHANGED