Skip to content

Commit

Permalink
🎨 Format
Browse files Browse the repository at this point in the history
  • Loading branch information
barbarbar338 committed Aug 6, 2023
1 parent debe7f2 commit 9680a60
Show file tree
Hide file tree
Showing 6 changed files with 132 additions and 150 deletions.
22 changes: 0 additions & 22 deletions .github/workflows/buil-test.yml

This file was deleted.

5 changes: 3 additions & 2 deletions .gitignore
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*
78 changes: 39 additions & 39 deletions README.md
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.
33 changes: 18 additions & 15 deletions src/index.ts
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>,
);
}
110 changes: 55 additions & 55 deletions tests/example.test.ts
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();
});
});
34 changes: 17 additions & 17 deletions tsconfig.json
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"]
}

0 comments on commit 9680a60

Please sign in to comment.