remove-anything 1.0.5 → 2.0.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.
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: Record<string, any>, valueToRemove: any, ...valuesToRemove: any[]): Record<string, unknown>;
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: Record<string, any>, valuesToRemove: any[]) => Record<string, unknown>;
9
-
10
- export { removeProp, removeProps };
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 { 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
- }, {});
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
- const removeProps = (payload, valuesToRemove) => removeProp(payload, valuesToRemove[0], ...valuesToRemove);
26
-
27
- export { removeProp, removeProps };
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,100 +1,47 @@
1
1
  {
2
2
  "name": "remove-anything",
3
- "version": "1.0.5",
3
+ "version": "2.0.1",
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
- ".": {
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
- }
20
- }
8
+ ".": "./dist/index.js"
21
9
  },
22
- "files": [
23
- "dist"
24
- ],
25
10
  "engines": {
26
- "node": ">=12.13"
11
+ "node": ">=18"
27
12
  },
28
13
  "scripts": {
29
14
  "test": "vitest run",
30
- "lint": "tsc --noEmit && eslint ./src --ext .ts",
31
- "build": "rollup -c ./rollup.config.js",
32
- "release": "npm run lint && del dist && npm run build && np"
15
+ "lint": "tsc --noEmit && eslint ./src",
16
+ "build": "del-cli dist && tsc",
17
+ "release": "npm run lint && npm run build && np"
33
18
  },
34
19
  "dependencies": {
35
20
  "is-what": "^4.1.8"
36
21
  },
37
22
  "devDependencies": {
38
- "@typescript-eslint/eslint-plugin": "^5.59.2",
39
- "@typescript-eslint/parser": "^5.59.2",
40
- "del-cli": "^5.0.0",
41
- "eslint": "^8.40.0",
42
- "eslint-config-prettier": "^8.8.0",
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"
23
+ "del-cli": "^5.1.0",
24
+ "np": "^10.0.5",
25
+ "vitest": "^1.6.0",
26
+ "@cycraft/eslint": "^0.3.0",
27
+ "@cycraft/tsconfig": "^0.1.2"
51
28
  },
29
+ "files": [
30
+ "dist"
31
+ ],
52
32
  "keywords": [
53
33
  "remove",
54
34
  "remove-prop",
55
35
  "remove-anything",
56
36
  "remove-undefined"
57
37
  ],
58
- "author": "Luca Ban - Mesqueeb",
38
+ "author": "Luca Ban - Mesqueeb (https://cycraft.co)",
59
39
  "funding": "https://github.com/sponsors/mesqueeb",
60
40
  "license": "MIT",
61
- "bugs": {
62
- "url": "https://github.com/mesqueeb/remove-anything/issues"
63
- },
64
- "homepage": "https://github.com/mesqueeb/remove-anything#readme",
65
41
  "repository": {
66
42
  "type": "git",
67
- "url": "git+https://github.com/mesqueeb/remove-anything.git"
43
+ "url": "https://github.com/mesqueeb/remove-anything.git"
68
44
  },
69
- "np": {
70
- "yarn": false,
71
- "branch": "production"
72
- },
73
- "eslintConfig": {
74
- "ignorePatterns": [
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
- }
45
+ "homepage": "https://github.com/mesqueeb/remove-anything#readme",
46
+ "bugs": "https://github.com/mesqueeb/remove-anything/issues"
100
47
  }
@@ -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;
@@ -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 };