remove-anything 0.0.2 → 0.1.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 +7 -0
- package/dist/index.cjs.js +7 -1
- package/dist/index.esm.js +8 -2
- package/dist/types/index.d.ts +5 -0
- package/package.json +35 -18
- package/.eslintignore +0 -9
- package/.eslintrc.js +0 -18
- package/.prettierrc +0 -9
- package/build.js +0 -57
- package/src/index.ts +0 -38
- package/test/index.ts +0 -13
- package/tsconfig.json +0 -14
- package/types/index.d.ts +0 -4
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.
|
package/dist/index.cjs.js
CHANGED
|
@@ -11,11 +11,17 @@ function removeProps(payload, valuesToRemove) {
|
|
|
11
11
|
if (valuesToRemove === void 0) { valuesToRemove = []; }
|
|
12
12
|
if (!isWhat.isPlainObject(payload) || !isWhat.isFullArray(valuesToRemove))
|
|
13
13
|
return payload;
|
|
14
|
+
var removeEmptyObjects = !!valuesToRemove.find(function (val) { return isWhat.isEmptyObject(val); });
|
|
14
15
|
return Object.entries(payload).reduce(function (carry, _a) {
|
|
15
16
|
var key = _a[0], value = _a[1];
|
|
17
|
+
if (removeEmptyObjects && isWhat.isEmptyObject(value))
|
|
18
|
+
return carry;
|
|
16
19
|
if (valuesToRemove.includes(value))
|
|
17
20
|
return carry;
|
|
18
|
-
|
|
21
|
+
var newVal = removeProps(value, valuesToRemove);
|
|
22
|
+
if (removeEmptyObjects && isWhat.isEmptyObject(newVal))
|
|
23
|
+
return carry;
|
|
24
|
+
carry[key] = newVal;
|
|
19
25
|
return carry;
|
|
20
26
|
}, {});
|
|
21
27
|
}
|
package/dist/index.esm.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isPlainObject, isFullArray } from 'is-what';
|
|
1
|
+
import { isPlainObject, isFullArray, isEmptyObject } from 'is-what';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Recursively remove props from an object, if the prop's value matches any of those in `valuesToRemove`
|
|
@@ -7,11 +7,17 @@ function removeProps(payload, valuesToRemove) {
|
|
|
7
7
|
if (valuesToRemove === void 0) { valuesToRemove = []; }
|
|
8
8
|
if (!isPlainObject(payload) || !isFullArray(valuesToRemove))
|
|
9
9
|
return payload;
|
|
10
|
+
var removeEmptyObjects = !!valuesToRemove.find(function (val) { return isEmptyObject(val); });
|
|
10
11
|
return Object.entries(payload).reduce(function (carry, _a) {
|
|
11
12
|
var key = _a[0], value = _a[1];
|
|
13
|
+
if (removeEmptyObjects && isEmptyObject(value))
|
|
14
|
+
return carry;
|
|
12
15
|
if (valuesToRemove.includes(value))
|
|
13
16
|
return carry;
|
|
14
|
-
|
|
17
|
+
var newVal = removeProps(value, valuesToRemove);
|
|
18
|
+
if (removeEmptyObjects && isEmptyObject(newVal))
|
|
19
|
+
return carry;
|
|
20
|
+
carry[key] = newVal;
|
|
15
21
|
return carry;
|
|
16
22
|
}, {});
|
|
17
23
|
}
|
|
@@ -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,44 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "remove-anything",
|
|
3
3
|
"sideEffects": false,
|
|
4
|
-
"version": "0.0
|
|
4
|
+
"version": "0.1.0",
|
|
5
5
|
"description": "Remove any prop (eg. `undefined`) from an object",
|
|
6
|
-
"main": "dist/index.cjs.js",
|
|
7
|
-
"module": "dist/index.esm.js",
|
|
8
|
-
"
|
|
6
|
+
"main": "./dist/index.cjs.js",
|
|
7
|
+
"module": "./dist/index.esm.js",
|
|
8
|
+
"types": "./dist/types/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"require": "./dist/index.cjs.js",
|
|
12
|
+
"import": "./dist/index.esm.js",
|
|
13
|
+
"types": "./dist/types/index.d.ts"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist"
|
|
18
|
+
],
|
|
9
19
|
"scripts": {
|
|
10
20
|
"test": "ava",
|
|
11
21
|
"lint": "eslint . --ext .js,.jsx,.ts,.tsx",
|
|
12
|
-
"
|
|
13
|
-
"
|
|
22
|
+
"build": "rollup -c build.js",
|
|
23
|
+
"release": "npm run lint && npm run test && npm run build && np"
|
|
14
24
|
},
|
|
15
25
|
"dependencies": {
|
|
16
|
-
"is-what": "^3.
|
|
26
|
+
"is-what": "^3.14.1"
|
|
17
27
|
},
|
|
18
28
|
"devDependencies": {
|
|
19
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
20
|
-
"@typescript-eslint/parser": "^
|
|
21
|
-
"ava": "^
|
|
22
|
-
"eslint": "^
|
|
23
|
-
"eslint-config-prettier": "^
|
|
24
|
-
"eslint-plugin-tree-shaking": "^1.
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"
|
|
29
|
+
"@typescript-eslint/eslint-plugin": "^5.9.1",
|
|
30
|
+
"@typescript-eslint/parser": "^5.9.1",
|
|
31
|
+
"ava": "^4.0.1",
|
|
32
|
+
"eslint": "^8.6.0",
|
|
33
|
+
"eslint-config-prettier": "^8.3.0",
|
|
34
|
+
"eslint-plugin-tree-shaking": "^1.10.0",
|
|
35
|
+
"np": "^7.6.0",
|
|
36
|
+
"prettier": "^2.5.1",
|
|
37
|
+
"rollup": "^2.63.0",
|
|
38
|
+
"rollup-plugin-typescript2": "^0.31.1",
|
|
39
|
+
"ts-node": "^10.4.0",
|
|
40
|
+
"tsconfig-paths": "^3.12.0",
|
|
41
|
+
"typescript": "^4.5.4"
|
|
30
42
|
},
|
|
31
43
|
"keywords": [
|
|
32
44
|
"remove",
|
|
@@ -35,6 +47,7 @@
|
|
|
35
47
|
"remove-undefined"
|
|
36
48
|
],
|
|
37
49
|
"author": "Luca Ban - Mesqueeb",
|
|
50
|
+
"funding": "https://github.com/sponsors/mesqueeb",
|
|
38
51
|
"license": "MIT",
|
|
39
52
|
"bugs": {
|
|
40
53
|
"url": "https://github.com/mesqueeb/remove-anything/issues"
|
|
@@ -52,5 +65,9 @@
|
|
|
52
65
|
"tsconfig-paths/register",
|
|
53
66
|
"ts-node/register"
|
|
54
67
|
]
|
|
68
|
+
},
|
|
69
|
+
"np": {
|
|
70
|
+
"yarn": false,
|
|
71
|
+
"branch": "production"
|
|
55
72
|
}
|
|
56
73
|
}
|
package/.eslintignore
DELETED
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
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/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 {};
|