remove-anything 1.0.5 → 2.0.0
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/index.d.ts +14 -4
- package/dist/index.js +29 -26
- package/package.json +17 -61
- package/dist/cjs/index.cjs +0 -30
- package/dist/cjs/index.d.cts +0 -10
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Recursively remove props from an object, if the prop's value matches `valueToRemove`
|
|
3
3
|
*/
|
|
4
|
-
declare function removeProp(payload:
|
|
4
|
+
export declare function removeProp(payload: {
|
|
5
|
+
[key in string | number | symbol]: unknown;
|
|
6
|
+
}, valueToRemove: unknown, ...valuesToRemove: unknown[]): {
|
|
7
|
+
[key in string | number | symbol]: unknown;
|
|
8
|
+
};
|
|
5
9
|
/**
|
|
6
10
|
* @deprecated use `removeProp` instead and pass multiple parameters
|
|
7
11
|
*/
|
|
8
|
-
declare const removeProps: (payload:
|
|
9
|
-
|
|
10
|
-
|
|
12
|
+
export declare const removeProps: (payload: {
|
|
13
|
+
[x: string]: unknown;
|
|
14
|
+
[x: number]: unknown;
|
|
15
|
+
[x: symbol]: unknown;
|
|
16
|
+
}, valuesToRemove: unknown[]) => {
|
|
17
|
+
[x: string]: unknown;
|
|
18
|
+
[x: number]: unknown;
|
|
19
|
+
[x: symbol]: unknown;
|
|
20
|
+
};
|
package/dist/index.js
CHANGED
|
@@ -1,27 +1,30 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
1
|
+
import { isEmptyArray, isEmptyObject, isPlainObject } from 'is-what';
|
|
2
|
+
/**
|
|
3
|
+
* Recursively remove props from an object, if the prop's value matches `valueToRemove`
|
|
4
|
+
*/
|
|
5
|
+
export function removeProp(payload, valueToRemove, ...valuesToRemove) {
|
|
6
|
+
if (!isPlainObject(payload))
|
|
7
|
+
return payload;
|
|
8
|
+
const remove = [valueToRemove, ...valuesToRemove];
|
|
9
|
+
const removeEmptyObjects = !!remove.find((val) => isEmptyObject(val));
|
|
10
|
+
const removeEmptyArrays = !!remove.find((val) => isEmptyArray(val));
|
|
11
|
+
return Object.entries(payload).reduce((carry, [key, value]) => {
|
|
12
|
+
if (removeEmptyObjects && isEmptyObject(value))
|
|
13
|
+
return carry;
|
|
14
|
+
if (removeEmptyArrays && 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 && isEmptyObject(newVal))
|
|
20
|
+
return carry;
|
|
21
|
+
if (removeEmptyArrays && isEmptyArray(newVal))
|
|
22
|
+
return carry;
|
|
23
|
+
carry[key] = newVal;
|
|
24
|
+
return carry;
|
|
25
|
+
}, {});
|
|
24
26
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
27
|
+
/**
|
|
28
|
+
* @deprecated use `removeProp` instead and pass multiple parameters
|
|
29
|
+
*/
|
|
30
|
+
export const removeProps = (payload, valuesToRemove) => removeProp(payload, valuesToRemove[0], ...valuesToRemove);
|
package/package.json
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "remove-anything",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Remove any prop (eg. `undefined`) from an object",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
7
|
-
"types": "./dist/index.d.ts",
|
|
8
|
-
"module": "./dist/index.js",
|
|
9
|
-
"main": "./dist/index.js",
|
|
10
7
|
"exports": {
|
|
11
8
|
".": {
|
|
12
9
|
"require": {
|
|
@@ -19,82 +16,41 @@
|
|
|
19
16
|
}
|
|
20
17
|
}
|
|
21
18
|
},
|
|
22
|
-
"files": [
|
|
23
|
-
"dist"
|
|
24
|
-
],
|
|
25
19
|
"engines": {
|
|
26
|
-
"node": ">=
|
|
20
|
+
"node": ">=18"
|
|
27
21
|
},
|
|
28
22
|
"scripts": {
|
|
29
23
|
"test": "vitest run",
|
|
30
|
-
"lint": "tsc --noEmit && eslint ./src
|
|
31
|
-
"build": "
|
|
32
|
-
"release": "npm run lint &&
|
|
24
|
+
"lint": "tsc --noEmit && eslint ./src",
|
|
25
|
+
"build": "del-cli dist && tsc",
|
|
26
|
+
"release": "npm run lint && npm run build && np"
|
|
33
27
|
},
|
|
34
28
|
"dependencies": {
|
|
35
29
|
"is-what": "^4.1.8"
|
|
36
30
|
},
|
|
37
31
|
"devDependencies": {
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"eslint": "^
|
|
42
|
-
"
|
|
43
|
-
"eslint-plugin-tree-shaking": "^1.10.0",
|
|
44
|
-
"np": "^7.7.0",
|
|
45
|
-
"prettier": "^2.8.8",
|
|
46
|
-
"rollup": "^3.23.0",
|
|
47
|
-
"rollup-plugin-dts": "^5.3.0",
|
|
48
|
-
"rollup-plugin-esbuild": "^5.0.0",
|
|
49
|
-
"typescript": "^4.9.5",
|
|
50
|
-
"vitest": "^0.31.0"
|
|
32
|
+
"del-cli": "^5.1.0",
|
|
33
|
+
"np": "^10.0.5",
|
|
34
|
+
"vitest": "^1.6.0",
|
|
35
|
+
"@cycraft/eslint": "^0.3.0",
|
|
36
|
+
"@cycraft/tsconfig": "^0.1.2"
|
|
51
37
|
},
|
|
38
|
+
"files": [
|
|
39
|
+
"dist"
|
|
40
|
+
],
|
|
52
41
|
"keywords": [
|
|
53
42
|
"remove",
|
|
54
43
|
"remove-prop",
|
|
55
44
|
"remove-anything",
|
|
56
45
|
"remove-undefined"
|
|
57
46
|
],
|
|
58
|
-
"author": "Luca Ban - Mesqueeb",
|
|
47
|
+
"author": "Luca Ban - Mesqueeb (https://cycraft.co)",
|
|
59
48
|
"funding": "https://github.com/sponsors/mesqueeb",
|
|
60
49
|
"license": "MIT",
|
|
61
|
-
"bugs": {
|
|
62
|
-
"url": "https://github.com/mesqueeb/remove-anything/issues"
|
|
63
|
-
},
|
|
64
|
-
"homepage": "https://github.com/mesqueeb/remove-anything#readme",
|
|
65
50
|
"repository": {
|
|
66
51
|
"type": "git",
|
|
67
|
-
"url": "
|
|
68
|
-
},
|
|
69
|
-
"np": {
|
|
70
|
-
"yarn": false,
|
|
71
|
-
"branch": "production"
|
|
52
|
+
"url": "https://github.com/mesqueeb/remove-anything.git"
|
|
72
53
|
},
|
|
73
|
-
"
|
|
74
|
-
|
|
75
|
-
"node_modules",
|
|
76
|
-
"dist",
|
|
77
|
-
"scripts",
|
|
78
|
-
"test"
|
|
79
|
-
],
|
|
80
|
-
"root": true,
|
|
81
|
-
"parser": "@typescript-eslint/parser",
|
|
82
|
-
"plugins": [
|
|
83
|
-
"@typescript-eslint",
|
|
84
|
-
"tree-shaking"
|
|
85
|
-
],
|
|
86
|
-
"extends": [
|
|
87
|
-
"eslint:recommended",
|
|
88
|
-
"plugin:@typescript-eslint/eslint-recommended",
|
|
89
|
-
"plugin:@typescript-eslint/recommended",
|
|
90
|
-
"prettier"
|
|
91
|
-
],
|
|
92
|
-
"rules": {
|
|
93
|
-
"@typescript-eslint/no-empty-function": "off",
|
|
94
|
-
"@typescript-eslint/no-explicit-any": "off",
|
|
95
|
-
"@typescript-eslint/ban-ts-ignore": "off",
|
|
96
|
-
"tree-shaking/no-side-effects-in-initialization": "error",
|
|
97
|
-
"@typescript-eslint/ban-ts-comment": "off"
|
|
98
|
-
}
|
|
99
|
-
}
|
|
54
|
+
"homepage": "https://github.com/mesqueeb/remove-anything#readme",
|
|
55
|
+
"bugs": "https://github.com/mesqueeb/remove-anything/issues"
|
|
100
56
|
}
|
package/dist/cjs/index.cjs
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
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;
|
package/dist/cjs/index.d.cts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
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 };
|