/
githubmirror
/
wp-calypso
Обзор
Документация
Войти
/
githubmirror
/
wp-calypso
Код
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
trunk
packages/js-utils/src/pick.ts
28 строк
804 B
Griffith Chen
Remove lodash pick and omit in favor of @automattic/js-utils (#111735)
17 июн 2026, 05:08
Не верифицирован
17 июн 2026, 05:08
83c72d6
Код
Авторство
О чём код?
type Many< T > = T | readonly T[]; /** * Returns a shallow copy of `object` with only the given own keys. Keys are * flat — a dotted string is a literal key, not a deep path. */ function pick< T extends object, K extends keyof T >( object: T, ...keys: Many< K >[] ): Pick< T, K >; function pick< T extends object >( object: T | null | undefined, ...keys: Many< PropertyKey >[] ): Partial< T >; function pick( object: object | null | undefined, ...keys: Many< PropertyKey >[] ) { const result: Record< PropertyKey, unknown > = {}; if ( object == null ) { return result; } for ( const key of keys.flat() ) { if ( Object.prototype.hasOwnProperty.call( object, key ) ) { result[ key ] = ( object as Record< PropertyKey, unknown > )[ key ]; } } return result; } export default pick;