-
Notifications
You must be signed in to change notification settings - Fork 313
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1397 from SukkaW/reduce-bundle-size
- Loading branch information
Showing
17 changed files
with
142 additions
and
166 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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,30 @@ | ||
/** Creates an object composed of the picked `object` properties. */ | ||
export function pick<T extends object, U extends keyof T>(obj: T, props: U[]): Pick<T, U> { | ||
const newObject = {} as Pick<T, U> | ||
|
||
for (const prop of props) { | ||
newObject[prop] = obj[prop] | ||
} | ||
|
||
return newObject | ||
} | ||
|
||
/** | ||
* Creates an object composed of the `object` properties `predicate` returns | ||
* truthy for. The predicate is invoked with two arguments: (value, key). | ||
*/ | ||
export function pickBy<R, K extends keyof R>( | ||
object: R | null | undefined, | ||
predicate: (value: R[K], key: keyof R) => any, | ||
): Record<K, R[K]> { | ||
const newObject = {} as Record<K, R[K]> | ||
|
||
for (const [key, value] of Object.entries<R[K]>(object ?? {})) { | ||
const _key = key as K | ||
if (predicate(value, _key)) { | ||
newObject[_key] = value | ||
} | ||
} | ||
|
||
return newObject | ||
} |
Oops, something went wrong.