remove-anything 1.0.4 → 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.
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Recursively remove props from an object, if the prop's value matches `valueToRemove`
3
+ */
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
+ };
9
+ /**
10
+ * @deprecated use `removeProp` instead and pass multiple parameters
11
+ */
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
+ };
@@ -1,33 +1,30 @@
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 };
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
+ }, {});
26
+ }
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,94 +1,56 @@
1
1
  {
2
2
  "name": "remove-anything",
3
- "sideEffects": false,
4
- "type": "module",
5
- "version": "1.0.4",
3
+ "version": "2.0.0",
6
4
  "description": "Remove any prop (eg. `undefined`) from an object",
7
- "module": "./dist/index.es.js",
8
- "main": "./dist/index.cjs",
9
- "types": "./dist/types/index.d.ts",
5
+ "type": "module",
6
+ "sideEffects": false,
10
7
  "exports": {
11
8
  ".": {
12
- "types": "./dist/types/index.d.ts",
13
- "import": "./dist/index.es.js",
14
- "require": "./dist/index.cjs"
9
+ "require": {
10
+ "types": "./dist/cjs/index.d.cts",
11
+ "default": "./dist/cjs/index.cjs"
12
+ },
13
+ "import": {
14
+ "types": "./dist/index.d.ts",
15
+ "default": "./dist/index.js"
16
+ }
15
17
  }
16
18
  },
17
- "files": [
18
- "dist"
19
- ],
20
19
  "engines": {
21
- "node": ">=12.13"
20
+ "node": ">=18"
22
21
  },
23
22
  "scripts": {
24
23
  "test": "vitest run",
25
- "lint": "tsc --noEmit && eslint ./src --ext .ts",
26
- "build": "rollup --bundleConfigAsCjs -c ./scripts/build.js",
27
- "release": "npm run lint && del dist && npm run build && np"
24
+ "lint": "tsc --noEmit && eslint ./src",
25
+ "build": "del-cli dist && tsc",
26
+ "release": "npm run lint && npm run build && np"
28
27
  },
29
28
  "dependencies": {
30
29
  "is-what": "^4.1.8"
31
30
  },
32
31
  "devDependencies": {
33
- "@typescript-eslint/eslint-plugin": "^5.59.2",
34
- "@typescript-eslint/parser": "^5.59.2",
35
- "del-cli": "^5.0.0",
36
- "eslint": "^8.40.0",
37
- "eslint-config-prettier": "^8.8.0",
38
- "eslint-plugin-tree-shaking": "^1.10.0",
39
- "np": "^7.7.0",
40
- "prettier": "^2.8.8",
41
- "rollup": "^3.21.5",
42
- "rollup-plugin-typescript2": "^0.34.1",
43
- "typescript": "^4.9.5",
44
- "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"
45
37
  },
38
+ "files": [
39
+ "dist"
40
+ ],
46
41
  "keywords": [
47
42
  "remove",
48
43
  "remove-prop",
49
44
  "remove-anything",
50
45
  "remove-undefined"
51
46
  ],
52
- "author": "Luca Ban - Mesqueeb",
47
+ "author": "Luca Ban - Mesqueeb (https://cycraft.co)",
53
48
  "funding": "https://github.com/sponsors/mesqueeb",
54
49
  "license": "MIT",
55
- "bugs": {
56
- "url": "https://github.com/mesqueeb/remove-anything/issues"
57
- },
58
- "homepage": "https://github.com/mesqueeb/remove-anything#readme",
59
50
  "repository": {
60
51
  "type": "git",
61
- "url": "git+https://github.com/mesqueeb/remove-anything.git"
52
+ "url": "https://github.com/mesqueeb/remove-anything.git"
62
53
  },
63
- "np": {
64
- "yarn": false,
65
- "branch": "production"
66
- },
67
- "eslintConfig": {
68
- "ignorePatterns": [
69
- "node_modules",
70
- "dist",
71
- "scripts",
72
- "test"
73
- ],
74
- "root": true,
75
- "parser": "@typescript-eslint/parser",
76
- "plugins": [
77
- "@typescript-eslint",
78
- "tree-shaking"
79
- ],
80
- "extends": [
81
- "eslint:recommended",
82
- "plugin:@typescript-eslint/eslint-recommended",
83
- "plugin:@typescript-eslint/recommended",
84
- "prettier"
85
- ],
86
- "rules": {
87
- "@typescript-eslint/no-empty-function": "off",
88
- "@typescript-eslint/no-explicit-any": "off",
89
- "@typescript-eslint/ban-ts-ignore": "off",
90
- "tree-shaking/no-side-effects-in-initialization": "error",
91
- "@typescript-eslint/ban-ts-comment": "off"
92
- }
93
- }
54
+ "homepage": "https://github.com/mesqueeb/remove-anything#readme",
55
+ "bugs": "https://github.com/mesqueeb/remove-anything/issues"
94
56
  }
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;
@@ -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>;