Skip to content

Commit d3bdb21

Browse files
Merge pull request #3 from joaopaulomoraes/refactor/improve-features
Improve features
2 parents 600eec8 + 54d55bd commit d3bdb21

File tree

4 files changed

+11
-15
lines changed

4 files changed

+11
-15
lines changed

jest.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ export default {
55
testEnvironment: 'node',
66
modulePaths: ['<rootDir>/src/'],
77
collectCoverageFrom: ['src/**/*.ts'],
8-
testPathIgnorePatterns: ['/dist/', '/node_modules/']
8+
testPathIgnorePatterns: ['/build/', '/node_modules/']
99
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "json-object-keys",
3-
"version": "0.1.2-dev",
3+
"version": "0.1.2",
44
"description": "Manage complex object keys in depth",
55
"author": {
66
"name": "João Paulo Moraes",

src/remove/index.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
type Key = string
2-
3-
type Keys = Array<Key>
4-
51
type JSObject = {
6-
[key: string | symbol]: unknown
2+
[key: string | number | symbol]: unknown
73
}
84

95
/**
@@ -12,20 +8,20 @@ type JSObject = {
128
* @param keys - A single key or an array of keys
139
* @returns A new object without the given keys
1410
*/
15-
export function remove<T extends JSObject>(object: T, keys: Key | Keys): T {
16-
if (typeof keys === 'string') {
17-
return withoutKey(object, keys)
18-
}
11+
export function remove<O extends JSObject, K extends keyof O>(object: O, keys: K | K[]): Omit<O, K> {
12+
if (typeof keys === 'string') return withoutKey(object, keys)
13+
14+
if (typeof keys === 'object') return withoutKeys(object, keys)
1915

20-
return withoutKeys(object, keys)
16+
return object
2117
}
2218

23-
function withoutKey(object: JSObject, key: Key) {
19+
function withoutKey<O extends JSObject, K extends string>(object: O, key: K) {
2420
const regex = new RegExp(`"${key}":[^,}]+,?`, 'g')
2521
return withRegex(object, regex)
2622
}
2723

28-
function withoutKeys(object: JSObject, keys: Keys) {
24+
function withoutKeys<O extends JSObject, K extends keyof O>(object: O, keys: K[]) {
2925
const regex = new RegExp(`"(${keys.join('|')})":[^,}]+,?`, 'g')
3026
return withRegex(object, regex)
3127
}

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@
1515
"isolatedModules": true
1616
},
1717
"include": ["src/**/*.ts"],
18-
"exclude": ["node_modules", "build"]
18+
"exclude": ["node_modules", "build", "test.ts"]
1919
}

0 commit comments

Comments
 (0)