remove-anything 0.0.2 → 1.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/README.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Remove Anything ✂️
2
2
 
3
+ <a href="https://www.npmjs.com/package/remove-anything"><img src="https://img.shields.io/npm/v/remove-anything.svg" alt="Total Downloads"></a>
4
+ <a href="https://www.npmjs.com/package/remove-anything"><img src="https://img.shields.io/npm/dw/remove-anything.svg" alt="Latest Stable Version"></a>
5
+
6
+ ```
7
+ npm i remove-anything
8
+ ```
9
+
3
10
  Removes props (eg. undefined) from an object
4
11
 
5
12
  An optimised way to remove any prop (eg. `undefined`) from an object. A small and simple integration.
@@ -7,15 +7,19 @@ 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
- return Object.entries(payload).reduce(function (carry, _a) {
15
- 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]) => {
15
+ if (removeEmptyObjects && isWhat.isEmptyObject(value))
16
+ return carry;
16
17
  if (valuesToRemove.includes(value))
17
18
  return carry;
18
- carry[key] = removeProps(value, valuesToRemove);
19
+ const newVal = removeProps(value, valuesToRemove);
20
+ if (removeEmptyObjects && isWhat.isEmptyObject(newVal))
21
+ return carry;
22
+ carry[key] = newVal;
19
23
  return carry;
20
24
  }, {});
21
25
  }
@@ -0,0 +1,29 @@
1
+ import { isPlainObject, isFullArray, isEmptyObject } from 'is-what';
2
+
3
+ /**
4
+ * Recursively remove props from an object, if the prop's value matches any of those in `valuesToRemove`
5
+ */
6
+ function removeProps(payload, valuesToRemove = []) {
7
+ if (!isPlainObject(payload) || !isFullArray(valuesToRemove))
8
+ return payload;
9
+ const removeEmptyObjects = !!valuesToRemove.find((val) => isEmptyObject(val));
10
+ return Object.entries(payload).reduce((carry, [key, value]) => {
11
+ if (removeEmptyObjects && isEmptyObject(value))
12
+ return carry;
13
+ if (valuesToRemove.includes(value))
14
+ return carry;
15
+ const newVal = removeProps(value, valuesToRemove);
16
+ if (removeEmptyObjects && isEmptyObject(newVal))
17
+ return carry;
18
+ carry[key] = newVal;
19
+ return carry;
20
+ }, {});
21
+ }
22
+ /**
23
+ * Recursively remove props from an object, if the prop's value matches `valueToRemove`
24
+ */
25
+ function removeProp(payload, valueToRemove) {
26
+ return removeProps(payload, [valueToRemove]);
27
+ }
28
+
29
+ export { removeProp, removeProps };
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Recursively remove props from an object, if the prop's value matches any of those in `valuesToRemove`
3
+ */
4
+ export declare function removeProps(payload: Record<string, any>, valuesToRemove?: any[]): Record<string, unknown>;
5
+ export declare function removeProp<Payload extends Record<string, any>>(payload: Payload, valueToRemove: any): Payload;
package/package.json CHANGED
@@ -1,32 +1,48 @@
1
1
  {
2
2
  "name": "remove-anything",
3
3
  "sideEffects": false,
4
- "version": "0.0.2",
4
+ "type": "module",
5
+ "version": "1.0.0",
5
6
  "description": "Remove any prop (eg. `undefined`) from an object",
6
- "main": "dist/index.cjs.js",
7
- "module": "dist/index.esm.js",
8
- "typings": "types/index.d.ts",
7
+ "module": "./dist/index.es.js",
8
+ "main": "./dist/index.cjs",
9
+ "types": "./dist/types/index.d.ts",
10
+ "exports": {
11
+ ".": {
12
+ "import": "./dist/index.es.js",
13
+ "require": "./dist/index.cjs",
14
+ "types": "./dist/types/index.d.ts"
15
+ }
16
+ },
17
+ "files": [
18
+ "dist"
19
+ ],
20
+ "engines": {
21
+ "node": ">=12.13",
22
+ "npm": ">=7"
23
+ },
9
24
  "scripts": {
10
- "test": "ava",
11
- "lint": "eslint . --ext .js,.jsx,.ts,.tsx",
12
- "rollup": "rollup -c build.js",
13
- "build": "npm run lint && npm run test && npm run rollup"
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"
14
29
  },
15
30
  "dependencies": {
16
- "is-what": "^3.12.0"
31
+ "is-what": "^4.1.1"
17
32
  },
18
33
  "devDependencies": {
19
- "@typescript-eslint/eslint-plugin": "^4.14.2",
20
- "@typescript-eslint/parser": "^4.14.2",
21
- "ava": "^3.15.0",
22
- "eslint": "^7.19.0",
23
- "eslint-config-prettier": "^7.2.0",
24
- "eslint-plugin-tree-shaking": "^1.8.0",
25
- "rollup": "^2.38.5",
26
- "rollup-plugin-typescript2": "^0.29.0",
27
- "ts-node": "^9.1.1",
28
- "tsconfig-paths": "^3.9.0",
29
- "typescript": "^4.1.3"
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",
38
+ "eslint-config-prettier": "^8.3.0",
39
+ "eslint-plugin-tree-shaking": "^1.10.0",
40
+ "np": "^7.6.0",
41
+ "prettier": "^2.5.1",
42
+ "rollup": "^2.66.0",
43
+ "rollup-plugin-typescript2": "^0.31.1",
44
+ "typescript": "^4.5.5",
45
+ "vitest": "^0.2.1"
30
46
  },
31
47
  "keywords": [
32
48
  "remove",
@@ -35,6 +51,7 @@
35
51
  "remove-undefined"
36
52
  ],
37
53
  "author": "Luca Ban - Mesqueeb",
54
+ "funding": "https://github.com/sponsors/mesqueeb",
38
55
  "license": "MIT",
39
56
  "bugs": {
40
57
  "url": "https://github.com/mesqueeb/remove-anything/issues"
@@ -44,13 +61,35 @@
44
61
  "type": "git",
45
62
  "url": "git+https://github.com/mesqueeb/remove-anything.git"
46
63
  },
47
- "ava": {
48
- "extensions": [
49
- "ts"
64
+ "np": {
65
+ "yarn": false,
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"
50
86
  ],
51
- "require": [
52
- "tsconfig-paths/register",
53
- "ts-node/register"
54
- ]
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
+ }
55
94
  }
56
95
  }
package/.eslintignore DELETED
@@ -1,9 +0,0 @@
1
- # don't ever lint node_modules
2
- node_modules
3
- # don't lint build output (make sure it's set to your correct build folder name)
4
- dist
5
- # don't lint nyc coverage output
6
- coverage
7
-
8
- test
9
- .eslintrc.js
package/.eslintrc.js DELETED
@@ -1,18 +0,0 @@
1
- // npm i -D @typescript-eslint/eslint-plugin @typescript-eslint/parser eslint eslint-config-prettier eslint-plugin-tree-shaking
2
- module.exports = {
3
- root: true,
4
- parser: '@typescript-eslint/parser',
5
- plugins: ['@typescript-eslint', 'tree-shaking'],
6
- extends: [
7
- 'eslint:recommended',
8
- 'plugin:@typescript-eslint/eslint-recommended',
9
- 'plugin:@typescript-eslint/recommended',
10
- 'prettier/@typescript-eslint',
11
- ],
12
- rules: {
13
- '@typescript-eslint/no-explicit-any': 'off',
14
- '@typescript-eslint/ban-ts-ignore': 'off',
15
- '@typescript-eslint/explicit-module-boundary-types': 'off',
16
- 'tree-shaking/no-side-effects-in-initialization': 'error',
17
- },
18
- }
package/.prettierrc DELETED
@@ -1,9 +0,0 @@
1
- {
2
- "printWidth": 100,
3
- "tabWidth": 2,
4
- "singleQuote": true,
5
- "trailingComma": "es5",
6
- "semi": false,
7
- "bracketSpacing": true,
8
- "quoteProps": "consistent"
9
- }
package/build.js DELETED
@@ -1,57 +0,0 @@
1
- /* eslint-disable */
2
-
3
- // npm install rollup-plugin-typescript2 typescript --save-dev
4
- import typescript from 'rollup-plugin-typescript2'
5
-
6
- // ------------------------------------------------------------------------------------------
7
- // formats
8
- // ------------------------------------------------------------------------------------------
9
- // amd – Asynchronous Module Definition, used with module loaders like RequireJS
10
- // cjs – CommonJS, suitable for Node and Browserify/Webpack
11
- // esm – Keep the bundle as an ES module file
12
- // iife – A self-executing function, suitable for inclusion as a <script> tag. (If you want to create a bundle for your application, you probably want to use this, because it leads to smaller file sizes.)
13
- // umd – Universal Module Definition, works as amd, cjs and iife all in one
14
- // system – Native format of the SystemJS loader
15
-
16
- // ------------------------------------------------------------------------------------------
17
- // setup
18
- // ------------------------------------------------------------------------------------------
19
- const pkg = require('./package.json')
20
- const name = pkg.name
21
- const className = name.replace(/(^\w|-\w)/g, c => c.replace('-', '').toUpperCase())
22
- const external = Object.keys(pkg.dependencies || [])
23
- const plugins = [
24
- typescript({ useTsconfigDeclarationDir: true, tsconfigOverride: { exclude: ['test/**/*'] } }),
25
- ]
26
-
27
- // ------------------------------------------------------------------------------------------
28
- // Builds
29
- // ------------------------------------------------------------------------------------------
30
- function defaults (config) {
31
- // defaults
32
- const defaults = {
33
- plugins,
34
- external,
35
- }
36
- // defaults.output
37
- config.output = config.output.map(output => {
38
- return Object.assign(
39
- {
40
- sourcemap: false,
41
- name: className,
42
- },
43
- output
44
- )
45
- })
46
- return Object.assign(defaults, config)
47
- }
48
-
49
- export default [
50
- defaults({
51
- input: 'src/index.ts',
52
- output: [
53
- { file: 'dist/index.cjs.js', format: 'cjs' },
54
- { file: 'dist/index.esm.js', format: 'esm' },
55
- ],
56
- }),
57
- ]
package/dist/index.esm.js DELETED
@@ -1,25 +0,0 @@
1
- import { isPlainObject, isFullArray } from 'is-what';
2
-
3
- /**
4
- * Recursively remove props from an object, if the prop's value matches any of those in `valuesToRemove`
5
- */
6
- function removeProps(payload, valuesToRemove) {
7
- if (valuesToRemove === void 0) { valuesToRemove = []; }
8
- if (!isPlainObject(payload) || !isFullArray(valuesToRemove))
9
- return payload;
10
- return Object.entries(payload).reduce(function (carry, _a) {
11
- var key = _a[0], value = _a[1];
12
- if (valuesToRemove.includes(value))
13
- return carry;
14
- carry[key] = removeProps(value, valuesToRemove);
15
- return carry;
16
- }, {});
17
- }
18
- /**
19
- * Recursively remove props from an object, if the prop's value matches `valueToRemove`
20
- */
21
- function removeProp(payload, valueToRemove) {
22
- return removeProps(payload, [valueToRemove]);
23
- }
24
-
25
- export { removeProp, removeProps };
package/src/index.ts DELETED
@@ -1,38 +0,0 @@
1
- import { isFullArray, isPlainObject } from 'is-what'
2
-
3
- type PlainObject = Record<string, any>
4
-
5
- // function overload for external use & type accuracy
6
- export function removeProps<Payload extends PlainObject> (
7
- payload: Payload,
8
- valuesToRemove: any[]
9
- ): Payload
10
- /**
11
- * Recursively remove props from an object, if the prop's value matches any of those in `valuesToRemove`
12
- */
13
- export function removeProps (
14
- payload: PlainObject,
15
- valuesToRemove: any[] = []
16
- ): PlainObject {
17
- if (!isPlainObject(payload) || !isFullArray(valuesToRemove)) return payload
18
- return Object.entries(payload).reduce((carry, [key, value]) => {
19
- if (valuesToRemove.includes(value)) return carry
20
- carry[key] = removeProps(value, valuesToRemove)
21
- return carry
22
- }, {} as PlainObject)
23
- }
24
-
25
- // function overload for external use & type accuracy
26
- export function removeProp<Payload extends PlainObject> (
27
- payload: Payload,
28
- valueToRemove: any
29
- ): Payload
30
- /**
31
- * Recursively remove props from an object, if the prop's value matches `valueToRemove`
32
- */
33
- export function removeProp (
34
- payload: PlainObject,
35
- valueToRemove: any
36
- ): PlainObject {
37
- return removeProps(payload, [valueToRemove])
38
- }
package/test/index.ts DELETED
@@ -1,13 +0,0 @@
1
- import test from 'ava'
2
- import { removeProp } from '../src/index'
3
-
4
- test('removeProp', t => {
5
- t.deepEqual(
6
- { a: 1 } as any,
7
- removeProp({ a: 1, b: undefined }, undefined)
8
- )
9
- t.deepEqual(
10
- { b: undefined } as any,
11
- removeProp({ a: 1, b: undefined }, 1)
12
- )
13
- })
package/tsconfig.json DELETED
@@ -1,14 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "baseUrl": ".",
4
- "outDir": "./dist",
5
- "declaration": true,
6
- "declarationDir": "./types/",
7
- "target": "es5",
8
- "lib": ["es5", "es2015", "es2016", "es2017", "dom"]
9
- },
10
- "include": [
11
- "src/**/*",
12
- "test/**/*"
13
- ]
14
- }
package/types/index.d.ts DELETED
@@ -1,4 +0,0 @@
1
- declare type PlainObject = Record<string, any>;
2
- export declare function removeProps<Payload extends PlainObject>(payload: Payload, valuesToRemove: any[]): Payload;
3
- export declare function removeProp<Payload extends PlainObject>(payload: Payload, valueToRemove: any): Payload;
4
- export {};