ag-common 0.0.663 → 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,6 +47,13 @@ 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>;
|
|
50
57
|
/** remove key values from an object where the value is null or undefined or other specific passed in values */
|
|
51
58
|
export declare const removeUndefValuesFromObject: <TA>(orig: Record<string, TA>) => Record<string, TA extends null | undefined ? never : TA>;
|
|
52
59
|
/** remove key values from an object where the value is null or undefined or other specific passed in values */
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isObject = exports.castStringlyObject = exports.removeUndefValuesFromObjectAdditional = 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,6 +130,23 @@ 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;
|
|
133
150
|
/** remove key values from an object where the value is null or undefined or other specific passed in values */
|
|
134
151
|
const removeUndefValuesFromObject = (orig) => {
|
|
135
152
|
const ret = {};
|
package/package.json
CHANGED