remove-anything 0.1.0 → 0.1.1
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,18 +7,16 @@ var isWhat = require('is-what');
|
|
|
7
7
|
/**
|
|
8
8
|
* Recursively remove props from an object, if the prop's value matches any of those in `valuesToRemove`
|
|
9
9
|
*/
|
|
10
|
-
function removeProps(payload, valuesToRemove) {
|
|
11
|
-
if (valuesToRemove === void 0) { valuesToRemove = []; }
|
|
10
|
+
function removeProps(payload, valuesToRemove = []) {
|
|
12
11
|
if (!isWhat.isPlainObject(payload) || !isWhat.isFullArray(valuesToRemove))
|
|
13
12
|
return payload;
|
|
14
|
-
|
|
15
|
-
return Object.entries(payload).reduce(
|
|
16
|
-
var key = _a[0], value = _a[1];
|
|
13
|
+
const removeEmptyObjects = !!valuesToRemove.find((val) => isWhat.isEmptyObject(val));
|
|
14
|
+
return Object.entries(payload).reduce((carry, [key, value]) => {
|
|
17
15
|
if (removeEmptyObjects && isWhat.isEmptyObject(value))
|
|
18
16
|
return carry;
|
|
19
17
|
if (valuesToRemove.includes(value))
|
|
20
18
|
return carry;
|
|
21
|
-
|
|
19
|
+
const newVal = removeProps(value, valuesToRemove);
|
|
22
20
|
if (removeEmptyObjects && isWhat.isEmptyObject(newVal))
|
|
23
21
|
return carry;
|
|
24
22
|
carry[key] = newVal;
|
|
@@ -3,18 +3,16 @@ import { isPlainObject, isFullArray, isEmptyObject } from 'is-what';
|
|
|
3
3
|
/**
|
|
4
4
|
* Recursively remove props from an object, if the prop's value matches any of those in `valuesToRemove`
|
|
5
5
|
*/
|
|
6
|
-
function removeProps(payload, valuesToRemove) {
|
|
7
|
-
if (valuesToRemove === void 0) { valuesToRemove = []; }
|
|
6
|
+
function removeProps(payload, valuesToRemove = []) {
|
|
8
7
|
if (!isPlainObject(payload) || !isFullArray(valuesToRemove))
|
|
9
8
|
return payload;
|
|
10
|
-
|
|
11
|
-
return Object.entries(payload).reduce(
|
|
12
|
-
var key = _a[0], value = _a[1];
|
|
9
|
+
const removeEmptyObjects = !!valuesToRemove.find((val) => isEmptyObject(val));
|
|
10
|
+
return Object.entries(payload).reduce((carry, [key, value]) => {
|
|
13
11
|
if (removeEmptyObjects && isEmptyObject(value))
|
|
14
12
|
return carry;
|
|
15
13
|
if (valuesToRemove.includes(value))
|
|
16
14
|
return carry;
|
|
17
|
-
|
|
15
|
+
const newVal = removeProps(value, valuesToRemove);
|
|
18
16
|
if (removeEmptyObjects && isEmptyObject(newVal))
|
|
19
17
|
return carry;
|
|
20
18
|
carry[key] = newVal;
|
package/package.json
CHANGED
|
@@ -1,44 +1,48 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "remove-anything",
|
|
3
3
|
"sideEffects": false,
|
|
4
|
-
"
|
|
4
|
+
"type": "module",
|
|
5
|
+
"version": "0.1.1",
|
|
5
6
|
"description": "Remove any prop (eg. `undefined`) from an object",
|
|
6
|
-
"
|
|
7
|
-
"
|
|
7
|
+
"module": "./dist/index.es.js",
|
|
8
|
+
"main": "./dist/index.cjs",
|
|
8
9
|
"types": "./dist/types/index.d.ts",
|
|
9
10
|
"exports": {
|
|
10
11
|
".": {
|
|
11
|
-
"
|
|
12
|
-
"
|
|
12
|
+
"import": "./dist/index.es.js",
|
|
13
|
+
"require": "./dist/index.cjs",
|
|
13
14
|
"types": "./dist/types/index.d.ts"
|
|
14
15
|
}
|
|
15
16
|
},
|
|
16
17
|
"files": [
|
|
17
18
|
"dist"
|
|
18
19
|
],
|
|
20
|
+
"engines": {
|
|
21
|
+
"node": ">=12.13",
|
|
22
|
+
"npm": ">=7"
|
|
23
|
+
},
|
|
19
24
|
"scripts": {
|
|
20
|
-
"test": "
|
|
21
|
-
"lint": "eslint
|
|
22
|
-
"build": "rollup -c build.js",
|
|
23
|
-
"release": "npm run lint &&
|
|
25
|
+
"test": "vitest run",
|
|
26
|
+
"lint": "tsc --noEmit && eslint ./src --ext .ts",
|
|
27
|
+
"build": "rollup -c ./scripts/build.js",
|
|
28
|
+
"release": "npm run lint && del dist && npm run build && np"
|
|
24
29
|
},
|
|
25
30
|
"dependencies": {
|
|
26
|
-
"is-what": "^
|
|
31
|
+
"is-what": "^4.1.1"
|
|
27
32
|
},
|
|
28
33
|
"devDependencies": {
|
|
29
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
30
|
-
"@typescript-eslint/parser": "^5.
|
|
31
|
-
"
|
|
32
|
-
"eslint": "^8.
|
|
34
|
+
"@typescript-eslint/eslint-plugin": "^5.10.1",
|
|
35
|
+
"@typescript-eslint/parser": "^5.10.1",
|
|
36
|
+
"del-cli": "^4.0.1",
|
|
37
|
+
"eslint": "^8.7.0",
|
|
33
38
|
"eslint-config-prettier": "^8.3.0",
|
|
34
39
|
"eslint-plugin-tree-shaking": "^1.10.0",
|
|
35
40
|
"np": "^7.6.0",
|
|
36
41
|
"prettier": "^2.5.1",
|
|
37
|
-
"rollup": "^2.
|
|
42
|
+
"rollup": "^2.66.0",
|
|
38
43
|
"rollup-plugin-typescript2": "^0.31.1",
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"typescript": "^4.5.4"
|
|
44
|
+
"typescript": "^4.5.5",
|
|
45
|
+
"vitest": "^0.2.1"
|
|
42
46
|
},
|
|
43
47
|
"keywords": [
|
|
44
48
|
"remove",
|
|
@@ -57,17 +61,35 @@
|
|
|
57
61
|
"type": "git",
|
|
58
62
|
"url": "git+https://github.com/mesqueeb/remove-anything.git"
|
|
59
63
|
},
|
|
60
|
-
"ava": {
|
|
61
|
-
"extensions": [
|
|
62
|
-
"ts"
|
|
63
|
-
],
|
|
64
|
-
"require": [
|
|
65
|
-
"tsconfig-paths/register",
|
|
66
|
-
"ts-node/register"
|
|
67
|
-
]
|
|
68
|
-
},
|
|
69
64
|
"np": {
|
|
70
65
|
"yarn": false,
|
|
71
66
|
"branch": "production"
|
|
67
|
+
},
|
|
68
|
+
"eslintConfig": {
|
|
69
|
+
"ignorePatterns": [
|
|
70
|
+
"node_modules",
|
|
71
|
+
"dist",
|
|
72
|
+
"scripts",
|
|
73
|
+
"test"
|
|
74
|
+
],
|
|
75
|
+
"root": true,
|
|
76
|
+
"parser": "@typescript-eslint/parser",
|
|
77
|
+
"plugins": [
|
|
78
|
+
"@typescript-eslint",
|
|
79
|
+
"tree-shaking"
|
|
80
|
+
],
|
|
81
|
+
"extends": [
|
|
82
|
+
"eslint:recommended",
|
|
83
|
+
"plugin:@typescript-eslint/eslint-recommended",
|
|
84
|
+
"plugin:@typescript-eslint/recommended",
|
|
85
|
+
"prettier"
|
|
86
|
+
],
|
|
87
|
+
"rules": {
|
|
88
|
+
"@typescript-eslint/no-empty-function": "off",
|
|
89
|
+
"@typescript-eslint/no-explicit-any": "off",
|
|
90
|
+
"@typescript-eslint/ban-ts-ignore": "off",
|
|
91
|
+
"tree-shaking/no-side-effects-in-initialization": "error",
|
|
92
|
+
"@typescript-eslint/ban-ts-comment": "off"
|
|
93
|
+
}
|
|
72
94
|
}
|
|
73
95
|
}
|