From 9680a609b70ce061ac8f482857902bc76e3df84f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20DEM=C4=B0RC=C4=B0?= Date: Sun, 6 Aug 2023 06:04:41 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20Format?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/buil-test.yml | 22 ------- .gitignore | 5 +- README.md | 78 +++++++++++----------- src/index.ts | 33 +++++----- tests/example.test.ts | 110 ++++++++++++++++---------------- tsconfig.json | 34 +++++----- 6 files changed, 132 insertions(+), 150 deletions(-) delete mode 100644 .github/workflows/buil-test.yml diff --git a/.github/workflows/buil-test.yml b/.github/workflows/buil-test.yml deleted file mode 100644 index f19f4f0..0000000 --- a/.github/workflows/buil-test.yml +++ /dev/null @@ -1,22 +0,0 @@ -name: Build and Test - -on: [push, pull_request] - -jobs: - build: - runs-on: ubuntu-latest - strategy: - matrix: - node-version: [14.x] - steps: - - uses: actions/checkout@v1 - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v1 - with: - node-version: ${{ matrix.node-version }} - - name: Install dependencies - run: yarn - - name: Build - run: yarn build - - name: Tests - run: yarn test diff --git a/.gitignore b/.gitignore index ed5b54b..498be9e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ node_modules dist -yarn-error.log -yarn.lock +*log* +*err* +*lock* diff --git a/README.md b/README.md index 09da74e..651d83d 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/src/index.ts b/src/index.ts index d495b56..0f16a49 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,15 +1,18 @@ -export function removeProperties< - T extends object, - K extends string | number | symbol, ->(obj: T, remove: K[]): Omit { - 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); -} +export function removeProperties< + T extends object, + K extends string | number | symbol, +>(obj: T, remove: K[]): Omit { + 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, + ); +} diff --git a/tests/example.test.ts b/tests/example.test.ts index c0ac0a3..535210d 100644 --- a/tests/example.test.ts +++ b/tests/example.test.ts @@ -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(); + }); +}); diff --git a/tsconfig.json b/tsconfig.json index 76b93da..795cafe 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -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"] +}