-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
debe7f2
commit 9680a60
Showing
6 changed files
with
132 additions
and
150 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
node_modules | ||
dist | ||
yarn-error.log | ||
yarn.lock | ||
*log* | ||
*err* | ||
*lock* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,39 @@ | ||
# 🔥 Remove properties from object | ||
|
||
easy-to-use, zero-dependency property remover. | ||
|
||
**Typedefinitions are built-in** | ||
|
||
[![build](https://img.shields.io/github/workflow/status/barisbored/remove-properties/Build%20and%20Test?logo=github&style=for-the-badge)](https://github.com/barisbored/remove-properties) | ||
[![supportServer](https://img.shields.io/discord/711995199945179187?color=7289DA&label=Support&logo=discord&style=for-the-badge)](https://discord.gg/BjEJFwh) | ||
[![totalDownloads](https://img.shields.io/npm/dt/remove-properties?color=CC3534&logo=npm&style=for-the-badge)](http://npmjs.com/remove-properties) | ||
[![weeklyDownloads](https://img.shields.io/npm/dw/remove-properties?color=CC3534&logo=npm&style=for-the-badge)](http://npmjs.com/remove-properties) | ||
[![version](https://img.shields.io/npm/v/remove-properties?color=red&label=Version&logo=npm&style=for-the-badge)](http://npmjs.com/remove-properties) | ||
[![stars](https://img.shields.io/github/stars/barisbored/remove-properties?color=yellow&logo=github&style=for-the-badge)](https://github.com/barisbored/remove-properties) | ||
[![license](https://img.shields.io/github/license/barisbored/remove-properties?logo=github&style=for-the-badge)](https://github.com/barisbored/remove-properties) | ||
|
||
# 🐮 Installation | ||
|
||
- Using NPM: `npm install remove-properties --save` | ||
- Using Yarn: `yarn add remove-properties` | ||
|
||
# 🧶 Usage | ||
|
||
```js | ||
const { removeProperties } = require("remove-properties"); | ||
|
||
const myObj = { a: 1, b: 2, c: 3, d: 4, e: 5, f: 6, g: 7 }; | ||
|
||
removeProperties(myObj, ["a", "c", "f"]); // => { b: 2, d: 4, e: 5, g: 7 } | ||
``` | ||
|
||
# 🎈 Options | ||
|
||
| Name | Type | Required | Default | | ||
| ------ | ------------- | -------- | ------- | | ||
| obj | Object | ✔️ | - | | ||
| remove | Array{string} | ✔️ | - | | ||
|
||
# 🧦 Contributing | ||
|
||
Feel free to use GitHub's features. | ||
# 🔥 Remove properties from object | ||
|
||
easy-to-use, zero-dependency property remover. | ||
|
||
**Typedefinitions are built-in** | ||
|
||
[![build](https://img.shields.io/github/workflow/status/barisbored/remove-properties/Build%20and%20Test?logo=github&style=for-the-badge)](https://github.com/barisbored/remove-properties) | ||
[![supportServer](https://img.shields.io/discord/711995199945179187?color=7289DA&label=Support&logo=discord&style=for-the-badge)](https://discord.gg/BjEJFwh) | ||
[![totalDownloads](https://img.shields.io/npm/dt/remove-properties?color=CC3534&logo=npm&style=for-the-badge)](http://npmjs.com/remove-properties) | ||
[![weeklyDownloads](https://img.shields.io/npm/dw/remove-properties?color=CC3534&logo=npm&style=for-the-badge)](http://npmjs.com/remove-properties) | ||
[![version](https://img.shields.io/npm/v/remove-properties?color=red&label=Version&logo=npm&style=for-the-badge)](http://npmjs.com/remove-properties) | ||
[![stars](https://img.shields.io/github/stars/barisbored/remove-properties?color=yellow&logo=github&style=for-the-badge)](https://github.com/barisbored/remove-properties) | ||
[![license](https://img.shields.io/github/license/barisbored/remove-properties?logo=github&style=for-the-badge)](https://github.com/barisbored/remove-properties) | ||
|
||
# 🐮 Installation | ||
|
||
- Using NPM: `npm install remove-properties --save` | ||
- Using Yarn: `yarn add remove-properties` | ||
|
||
# 🧶 Usage | ||
|
||
```js | ||
const { removeProperties } = require("remove-properties"); | ||
|
||
const myObj = { a: 1, b: 2, c: 3, d: 4, e: 5, f: 6, g: 7 }; | ||
|
||
removeProperties(myObj, ["a", "c", "f"]); // => { b: 2, d: 4, e: 5, g: 7 } | ||
``` | ||
|
||
# 🎈 Options | ||
|
||
| Name | Type | Required | Default | | ||
| ------ | ------------- | -------- | ------- | | ||
| obj | Object | ✔️ | - | | ||
| remove | Array{string} | ✔️ | - | | ||
|
||
# 🧦 Contributing | ||
|
||
Feel free to use GitHub's features. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,18 @@ | ||
export function removeProperties< | ||
T extends object, | ||
K extends string | number | symbol, | ||
>(obj: T, remove: K[]): Omit<T, K> { | ||
return ( | ||
(Object.keys(obj) as K[]).filter((key) => !remove.includes(key)) as ( | ||
| string | ||
| number | ||
| symbol | ||
)[] | ||
).reduce((newObj, key) => { | ||
(newObj as any)[key] = (obj as any)[key]; | ||
return newObj; | ||
}, {} as Omit<T, K>); | ||
} | ||
export function removeProperties< | ||
T extends object, | ||
K extends string | number | symbol, | ||
>(obj: T, remove: K[]): Omit<T, K> { | ||
return ( | ||
(Object.keys(obj) as K[]).filter((key) => !remove.includes(key)) as ( | ||
| string | ||
| number | ||
| symbol | ||
)[] | ||
).reduce( | ||
(newObj, key) => { | ||
(newObj as any)[key] = (obj as any)[key]; | ||
return newObj; | ||
}, | ||
{} as Omit<T, K>, | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,55 @@ | ||
import { expect } from "chai"; | ||
import { removeProperties } from "../src"; | ||
|
||
const obj = { a: 1, b: 2, c: 3, d: 4, e: 5, f: 6, g: 7 }; | ||
|
||
describe("Remove Properties Tests", () => { | ||
it("Should remove", (done) => { | ||
const removed = removeProperties(obj, ["b", "e", "c", "g"]); | ||
expect(removed).to.haveOwnProperty("a", 1); | ||
expect(removed).not.to.haveOwnProperty("b"); | ||
expect(removed).not.to.haveOwnProperty("c"); | ||
expect(removed).to.haveOwnProperty("d", 4); | ||
expect(removed).not.to.haveOwnProperty("e"); | ||
expect(removed).to.haveOwnProperty("f", 6); | ||
expect(removed).not.to.haveOwnProperty("g"); | ||
expect(removed).to.be.deep.equal({ | ||
a: 1, | ||
d: 4, | ||
f: 6, | ||
}); | ||
done(); | ||
}); | ||
it("Should not remove", (done) => { | ||
const removed = removeProperties(obj, ["z"]); | ||
expect(removed).to.haveOwnProperty("a", 1); | ||
expect(removed).to.haveOwnProperty("b", 2); | ||
expect(removed).to.haveOwnProperty("c", 3); | ||
expect(removed).to.haveOwnProperty("d", 4); | ||
expect(removed).to.haveOwnProperty("e", 5); | ||
expect(removed).to.haveOwnProperty("f", 6); | ||
expect(removed).to.haveOwnProperty("g", 7); | ||
expect(removed).to.be.deep.equal(obj); | ||
done(); | ||
}); | ||
it("Should remove everything", (done) => { | ||
const removed = removeProperties(obj, [ | ||
"a", | ||
"b", | ||
"c", | ||
"d", | ||
"e", | ||
"f", | ||
"g", | ||
]); | ||
expect(removed).not.to.haveOwnProperty("a", 1); | ||
expect(removed).not.to.haveOwnProperty("b", 2); | ||
expect(removed).not.to.haveOwnProperty("c", 3); | ||
expect(removed).not.to.haveOwnProperty("d", 4); | ||
expect(removed).not.to.haveOwnProperty("e", 5); | ||
expect(removed).not.to.haveOwnProperty("f", 6); | ||
expect(removed).not.to.haveOwnProperty("g", 7); | ||
expect(removed).to.be.deep.equal({}); | ||
done(); | ||
}); | ||
}); | ||
import { expect } from "chai"; | ||
import { removeProperties } from "../src"; | ||
|
||
const obj = { a: 1, b: 2, c: 3, d: 4, e: 5, f: 6, g: 7 }; | ||
|
||
describe("Remove Properties Tests", () => { | ||
it("Should remove", (done) => { | ||
const removed = removeProperties(obj, ["b", "e", "c", "g"]); | ||
expect(removed).to.haveOwnProperty("a", 1); | ||
expect(removed).not.to.haveOwnProperty("b"); | ||
expect(removed).not.to.haveOwnProperty("c"); | ||
expect(removed).to.haveOwnProperty("d", 4); | ||
expect(removed).not.to.haveOwnProperty("e"); | ||
expect(removed).to.haveOwnProperty("f", 6); | ||
expect(removed).not.to.haveOwnProperty("g"); | ||
expect(removed).to.be.deep.equal({ | ||
a: 1, | ||
d: 4, | ||
f: 6, | ||
}); | ||
done(); | ||
}); | ||
it("Should not remove", (done) => { | ||
const removed = removeProperties(obj, ["z"]); | ||
expect(removed).to.haveOwnProperty("a", 1); | ||
expect(removed).to.haveOwnProperty("b", 2); | ||
expect(removed).to.haveOwnProperty("c", 3); | ||
expect(removed).to.haveOwnProperty("d", 4); | ||
expect(removed).to.haveOwnProperty("e", 5); | ||
expect(removed).to.haveOwnProperty("f", 6); | ||
expect(removed).to.haveOwnProperty("g", 7); | ||
expect(removed).to.be.deep.equal(obj); | ||
done(); | ||
}); | ||
it("Should remove everything", (done) => { | ||
const removed = removeProperties(obj, [ | ||
"a", | ||
"b", | ||
"c", | ||
"d", | ||
"e", | ||
"f", | ||
"g", | ||
]); | ||
expect(removed).not.to.haveOwnProperty("a", 1); | ||
expect(removed).not.to.haveOwnProperty("b", 2); | ||
expect(removed).not.to.haveOwnProperty("c", 3); | ||
expect(removed).not.to.haveOwnProperty("d", 4); | ||
expect(removed).not.to.haveOwnProperty("e", 5); | ||
expect(removed).not.to.haveOwnProperty("f", 6); | ||
expect(removed).not.to.haveOwnProperty("g", 7); | ||
expect(removed).to.be.deep.equal({}); | ||
done(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"declaration": true, | ||
"removeComments": false, | ||
"allowSyntheticDefaultImports": true, | ||
"target": "ES2016", | ||
"outDir": "./dist", | ||
"baseUrl": "./", | ||
"incremental": true, | ||
"moduleResolution": "node", | ||
"esModuleInterop": true, | ||
"strict": true, | ||
"forceConsistentCasingInFileNames": true | ||
}, | ||
"exclude": ["node_modules", "dist", "tests"] | ||
} | ||
{ | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"declaration": true, | ||
"removeComments": false, | ||
"allowSyntheticDefaultImports": true, | ||
"target": "ES2016", | ||
"outDir": "./dist", | ||
"baseUrl": "./", | ||
"incremental": true, | ||
"moduleResolution": "node", | ||
"esModuleInterop": true, | ||
"strict": true, | ||
"forceConsistentCasingInFileNames": true | ||
}, | ||
"exclude": ["node_modules", "dist", "tests"] | ||
} |