-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(utils): omit, pick 인터페이스 수정 및 로직 간소화
- Loading branch information
Showing
13 changed files
with
160 additions
and
89 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@modern-kit/utils': patch | ||
--- | ||
|
||
fix(utils): omit, pick 인터페이스 수정 및 로직 간소화 - @ssi02014 |
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
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
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
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
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
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
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
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { bench, describe } from 'vitest'; | ||
import { omit } from '.'; | ||
import { omit as omitLodash } from 'lodash-es'; | ||
|
||
describe('omit', () => { | ||
bench('modern-kit/omit', () => { | ||
omit({ a: 1, b: 2, c: 3, d: 4, e: 5 }, ['a', 'c', 'e']); | ||
}); | ||
|
||
bench('lodash/omit', () => { | ||
omitLodash({ a: 1, b: 2, c: 3, d: 4, e: 5 }, ['a', 'c', 'e']); | ||
}); | ||
}); |
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,28 +1,14 @@ | ||
import { describe, it, expect } from 'vitest'; | ||
import { describe, it, expect, expectTypeOf } from 'vitest'; | ||
import { omit } from '.'; | ||
|
||
describe('omit function', () => { | ||
it('should return a new object omitting a single key from an object', () => { | ||
const inputObj = { a: 1, b: 2, c: 3 } as const; | ||
const omittedObj = omit(inputObj, ['b']); | ||
|
||
expect(omittedObj).toEqual({ a: 1, c: 3 }); | ||
}); | ||
|
||
it('should return a new object omitting multiple keys from an object', () => { | ||
const symbol = Symbol('d'); | ||
const inputObj = { a: 1, b: 2, c: 3, d: 4, [symbol]: 5 } as const; | ||
const omittedObj = omit(inputObj, ['b', 'd', symbol]); | ||
|
||
expect(omittedObj).toEqual({ a: 1, c: 3 }); | ||
}); | ||
const inputObj = { a: 1, b: 2, c: 3 }; | ||
const omittedObj = omit(inputObj, ['b', 'c']); | ||
|
||
it('should return a new object that is deeply copied', () => { | ||
const symbol = Symbol('d'); | ||
const inputObj = { a: 1, b: { x: 2, y: 3 }, c: 4, [symbol]: 5 } as const; | ||
const omittedObj = omit(inputObj, ['a', 'c']); | ||
expect(omittedObj).toEqual({ a: 1 }); | ||
|
||
expect(omittedObj.b).not.toBe(inputObj.b); | ||
expect(omittedObj.b).toEqual(inputObj.b); | ||
// type | ||
expectTypeOf(omittedObj).toEqualTypeOf<{ a: number }>(); | ||
}); | ||
}); |
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
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { bench, describe } from 'vitest'; | ||
import { pick } from '.'; | ||
import { pick as pickLodash } from 'lodash-es'; | ||
|
||
describe('pick', () => { | ||
bench('@modern-kit/pick', () => { | ||
pick({ a: 1, b: 2, c: 3, d: 4, e: 5 }, ['a', 'c', 'e']); | ||
}); | ||
|
||
bench('lodash/pick', () => { | ||
pickLodash({ a: 1, b: 2, c: 3, d: 4, e: 5 }, ['a', 'c', 'e']); | ||
}); | ||
}); |
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,29 +1,14 @@ | ||
import { describe, it, expect } from 'vitest'; | ||
import { describe, it, expect, expectTypeOf } from 'vitest'; | ||
import { pick } from '.'; | ||
|
||
describe('pick', () => { | ||
it('should return a new object with a single key extracted from an object', () => { | ||
const symbol = Symbol('d'); | ||
const inputObj = { a: 1, b: 2, c: 3, [symbol]: 4 } as const; | ||
const pickedObj = pick(inputObj, 'b'); | ||
|
||
expect(pickedObj).toEqual({ b: 2 }); | ||
}); | ||
|
||
it('should return a new object with multiple keys extracted from an object', () => { | ||
const symbol = Symbol('d'); | ||
const inputObj = { a: 1, b: 2, c: 3, [symbol]: 4 } as const; | ||
const pickedObj = pick(inputObj, ['a', 'c']); | ||
|
||
expect(pickedObj).toEqual({ a: 1, c: 3 }); | ||
}); | ||
const inputObj = { a: 1, b: 2, c: 3 }; | ||
const pickedObj = pick(inputObj, ['b', 'c']); | ||
|
||
it('should return a new object that is deeply copied', () => { | ||
const symbol = Symbol('d'); | ||
const inputObj = { a: 1, b: { x: 2, y: 3 }, c: 4, [symbol]: 4 } as const; | ||
const pickedObj = pick(inputObj, ['b']); | ||
expect(pickedObj).toEqual({ b: 2, c: 3 }); | ||
|
||
expect(pickedObj.b).not.toBe(inputObj.b); | ||
expect(pickedObj.b).toEqual(inputObj.b); | ||
// type | ||
expectTypeOf(pickedObj).toEqualTypeOf<{ b: number; c: number }>(); | ||
}); | ||
}); |