remove-anything 1.0.4 → 1.0.5
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/cjs/index.cjs +30 -0
- package/dist/cjs/index.d.cts +10 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +27 -0
- package/package.json +18 -12
- package/dist/index.cjs +0 -36
- package/dist/index.es.js +0 -33
- package/dist/types/index.d.ts +0 -8
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const isWhat = require('is-what');
|
|
4
|
+
|
|
5
|
+
function removeProp(payload, valueToRemove, ...valuesToRemove) {
|
|
6
|
+
if (!isWhat.isPlainObject(payload))
|
|
7
|
+
return payload;
|
|
8
|
+
const remove = [valueToRemove, ...valuesToRemove];
|
|
9
|
+
const removeEmptyObjects = !!remove.find((val) => isWhat.isEmptyObject(val));
|
|
10
|
+
const removeEmptyArrays = !!remove.find((val) => isWhat.isEmptyArray(val));
|
|
11
|
+
return Object.entries(payload).reduce((carry, [key, value]) => {
|
|
12
|
+
if (removeEmptyObjects && isWhat.isEmptyObject(value))
|
|
13
|
+
return carry;
|
|
14
|
+
if (removeEmptyArrays && isWhat.isEmptyArray(value))
|
|
15
|
+
return carry;
|
|
16
|
+
if (remove.includes(value))
|
|
17
|
+
return carry;
|
|
18
|
+
const newVal = removeProp(value, remove[0], ...remove.slice(1));
|
|
19
|
+
if (removeEmptyObjects && isWhat.isEmptyObject(newVal))
|
|
20
|
+
return carry;
|
|
21
|
+
if (removeEmptyArrays && isWhat.isEmptyArray(newVal))
|
|
22
|
+
return carry;
|
|
23
|
+
carry[key] = newVal;
|
|
24
|
+
return carry;
|
|
25
|
+
}, {});
|
|
26
|
+
}
|
|
27
|
+
const removeProps = (payload, valuesToRemove) => removeProp(payload, valuesToRemove[0], ...valuesToRemove);
|
|
28
|
+
|
|
29
|
+
exports.removeProp = removeProp;
|
|
30
|
+
exports.removeProps = removeProps;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Recursively remove props from an object, if the prop's value matches `valueToRemove`
|
|
3
|
+
*/
|
|
4
|
+
declare function removeProp(payload: Record<string, any>, valueToRemove: any, ...valuesToRemove: any[]): Record<string, unknown>;
|
|
5
|
+
/**
|
|
6
|
+
* @deprecated use `removeProp` instead and pass multiple parameters
|
|
7
|
+
*/
|
|
8
|
+
declare const removeProps: (payload: Record<string, any>, valuesToRemove: any[]) => Record<string, unknown>;
|
|
9
|
+
|
|
10
|
+
export { removeProp, removeProps };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Recursively remove props from an object, if the prop's value matches `valueToRemove`
|
|
3
|
+
*/
|
|
4
|
+
declare function removeProp(payload: Record<string, any>, valueToRemove: any, ...valuesToRemove: any[]): Record<string, unknown>;
|
|
5
|
+
/**
|
|
6
|
+
* @deprecated use `removeProp` instead and pass multiple parameters
|
|
7
|
+
*/
|
|
8
|
+
declare const removeProps: (payload: Record<string, any>, valuesToRemove: any[]) => Record<string, unknown>;
|
|
9
|
+
|
|
10
|
+
export { removeProp, removeProps };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { isPlainObject, isEmptyObject, isEmptyArray } from 'is-what';
|
|
2
|
+
|
|
3
|
+
function removeProp(payload, valueToRemove, ...valuesToRemove) {
|
|
4
|
+
if (!isPlainObject(payload))
|
|
5
|
+
return payload;
|
|
6
|
+
const remove = [valueToRemove, ...valuesToRemove];
|
|
7
|
+
const removeEmptyObjects = !!remove.find((val) => isEmptyObject(val));
|
|
8
|
+
const removeEmptyArrays = !!remove.find((val) => isEmptyArray(val));
|
|
9
|
+
return Object.entries(payload).reduce((carry, [key, value]) => {
|
|
10
|
+
if (removeEmptyObjects && isEmptyObject(value))
|
|
11
|
+
return carry;
|
|
12
|
+
if (removeEmptyArrays && isEmptyArray(value))
|
|
13
|
+
return carry;
|
|
14
|
+
if (remove.includes(value))
|
|
15
|
+
return carry;
|
|
16
|
+
const newVal = removeProp(value, remove[0], ...remove.slice(1));
|
|
17
|
+
if (removeEmptyObjects && isEmptyObject(newVal))
|
|
18
|
+
return carry;
|
|
19
|
+
if (removeEmptyArrays && isEmptyArray(newVal))
|
|
20
|
+
return carry;
|
|
21
|
+
carry[key] = newVal;
|
|
22
|
+
return carry;
|
|
23
|
+
}, {});
|
|
24
|
+
}
|
|
25
|
+
const removeProps = (payload, valuesToRemove) => removeProp(payload, valuesToRemove[0], ...valuesToRemove);
|
|
26
|
+
|
|
27
|
+
export { removeProp, removeProps };
|
package/package.json
CHANGED
|
@@ -1,17 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "remove-anything",
|
|
3
|
-
"
|
|
4
|
-
"type": "module",
|
|
5
|
-
"version": "1.0.4",
|
|
3
|
+
"version": "1.0.5",
|
|
6
4
|
"description": "Remove any prop (eg. `undefined`) from an object",
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
"types": "./dist/
|
|
5
|
+
"type": "module",
|
|
6
|
+
"sideEffects": false,
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"module": "./dist/index.js",
|
|
9
|
+
"main": "./dist/index.js",
|
|
10
10
|
"exports": {
|
|
11
11
|
".": {
|
|
12
|
-
"
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
"require": {
|
|
13
|
+
"types": "./dist/cjs/index.d.cts",
|
|
14
|
+
"default": "./dist/cjs/index.cjs"
|
|
15
|
+
},
|
|
16
|
+
"import": {
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"default": "./dist/index.js"
|
|
19
|
+
}
|
|
15
20
|
}
|
|
16
21
|
},
|
|
17
22
|
"files": [
|
|
@@ -23,7 +28,7 @@
|
|
|
23
28
|
"scripts": {
|
|
24
29
|
"test": "vitest run",
|
|
25
30
|
"lint": "tsc --noEmit && eslint ./src --ext .ts",
|
|
26
|
-
"build": "rollup
|
|
31
|
+
"build": "rollup -c ./rollup.config.js",
|
|
27
32
|
"release": "npm run lint && del dist && npm run build && np"
|
|
28
33
|
},
|
|
29
34
|
"dependencies": {
|
|
@@ -38,8 +43,9 @@
|
|
|
38
43
|
"eslint-plugin-tree-shaking": "^1.10.0",
|
|
39
44
|
"np": "^7.7.0",
|
|
40
45
|
"prettier": "^2.8.8",
|
|
41
|
-
"rollup": "^3.
|
|
42
|
-
"rollup-plugin-
|
|
46
|
+
"rollup": "^3.23.0",
|
|
47
|
+
"rollup-plugin-dts": "^5.3.0",
|
|
48
|
+
"rollup-plugin-esbuild": "^5.0.0",
|
|
43
49
|
"typescript": "^4.9.5",
|
|
44
50
|
"vitest": "^0.31.0"
|
|
45
51
|
},
|
package/dist/index.cjs
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var isWhat = require('is-what');
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Recursively remove props from an object, if the prop's value matches `valueToRemove`
|
|
7
|
-
*/
|
|
8
|
-
function removeProp(payload, valueToRemove, ...valuesToRemove) {
|
|
9
|
-
if (!isWhat.isPlainObject(payload))
|
|
10
|
-
return payload;
|
|
11
|
-
const remove = [valueToRemove, ...valuesToRemove];
|
|
12
|
-
const removeEmptyObjects = !!remove.find((val) => isWhat.isEmptyObject(val));
|
|
13
|
-
const removeEmptyArrays = !!remove.find((val) => isWhat.isEmptyArray(val));
|
|
14
|
-
return Object.entries(payload).reduce((carry, [key, value]) => {
|
|
15
|
-
if (removeEmptyObjects && isWhat.isEmptyObject(value))
|
|
16
|
-
return carry;
|
|
17
|
-
if (removeEmptyArrays && isWhat.isEmptyArray(value))
|
|
18
|
-
return carry;
|
|
19
|
-
if (remove.includes(value))
|
|
20
|
-
return carry;
|
|
21
|
-
const newVal = removeProp(value, remove[0], ...remove.slice(1));
|
|
22
|
-
if (removeEmptyObjects && isWhat.isEmptyObject(newVal))
|
|
23
|
-
return carry;
|
|
24
|
-
if (removeEmptyArrays && isWhat.isEmptyArray(newVal))
|
|
25
|
-
return carry;
|
|
26
|
-
carry[key] = newVal;
|
|
27
|
-
return carry;
|
|
28
|
-
}, {});
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* @deprecated use `removeProp` instead and pass multiple parameters
|
|
32
|
-
*/
|
|
33
|
-
const removeProps = (payload, valuesToRemove) => removeProp(payload, valuesToRemove[0], ...valuesToRemove);
|
|
34
|
-
|
|
35
|
-
exports.removeProp = removeProp;
|
|
36
|
-
exports.removeProps = removeProps;
|
package/dist/index.es.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { isPlainObject, isEmptyObject, isEmptyArray } from 'is-what';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Recursively remove props from an object, if the prop's value matches `valueToRemove`
|
|
5
|
-
*/
|
|
6
|
-
function removeProp(payload, valueToRemove, ...valuesToRemove) {
|
|
7
|
-
if (!isPlainObject(payload))
|
|
8
|
-
return payload;
|
|
9
|
-
const remove = [valueToRemove, ...valuesToRemove];
|
|
10
|
-
const removeEmptyObjects = !!remove.find((val) => isEmptyObject(val));
|
|
11
|
-
const removeEmptyArrays = !!remove.find((val) => isEmptyArray(val));
|
|
12
|
-
return Object.entries(payload).reduce((carry, [key, value]) => {
|
|
13
|
-
if (removeEmptyObjects && isEmptyObject(value))
|
|
14
|
-
return carry;
|
|
15
|
-
if (removeEmptyArrays && isEmptyArray(value))
|
|
16
|
-
return carry;
|
|
17
|
-
if (remove.includes(value))
|
|
18
|
-
return carry;
|
|
19
|
-
const newVal = removeProp(value, remove[0], ...remove.slice(1));
|
|
20
|
-
if (removeEmptyObjects && isEmptyObject(newVal))
|
|
21
|
-
return carry;
|
|
22
|
-
if (removeEmptyArrays && isEmptyArray(newVal))
|
|
23
|
-
return carry;
|
|
24
|
-
carry[key] = newVal;
|
|
25
|
-
return carry;
|
|
26
|
-
}, {});
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* @deprecated use `removeProp` instead and pass multiple parameters
|
|
30
|
-
*/
|
|
31
|
-
const removeProps = (payload, valuesToRemove) => removeProp(payload, valuesToRemove[0], ...valuesToRemove);
|
|
32
|
-
|
|
33
|
-
export { removeProp, removeProps };
|
package/dist/types/index.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Recursively remove props from an object, if the prop's value matches `valueToRemove`
|
|
3
|
-
*/
|
|
4
|
-
export declare function removeProp(payload: Record<string, any>, valueToRemove: any, ...valuesToRemove: any[]): Record<string, unknown>;
|
|
5
|
-
/**
|
|
6
|
-
* @deprecated use `removeProp` instead and pass multiple parameters
|
|
7
|
-
*/
|
|
8
|
-
export declare const removeProps: (payload: Record<string, any>, valuesToRemove: any[]) => Record<string, unknown>;
|