@augment-vir/common
Version:
A collection of augments, helpers types, functions, and classes for any JavaScript environment.
44 lines (43 loc) • 1.24 kB
JavaScript
import { filterObject } from './object-filter.js';
/**
* Same as the TypeScript built-in type `Omit` except that it works on actual runtime values.
*
* @category Object
* @category Package : @augment-vir/common
* @example
*
* ```ts
* import {omitObjectKeys} from '@augment-vir/common';
*
* omitObjectKeys({a: 'a', b: 'b'}, ['a']);
* // output is `{b: 'b'}`
* ```
*
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
*/
export function omitObjectKeys(inputObject, omitTheseKeys) {
return filterObject(inputObject, (currentKey) => {
return !omitTheseKeys.includes(currentKey);
});
}
/**
* Same as the TypeScript built-in type `Pick` except that it works on actual runtime values.
*
* @category Object
* @category Package : @augment-vir/common
* @example
*
* ```ts
* import {pickObjectKeys} from '@augment-vir/common';
*
* pickObjectKeys({a: 'a', b: 'b'}, ['a']);
* // output is `{a: 'a'}`
* ```
*
* @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
*/
export function pickObjectKeys(inputObject, pickTheseKeys) {
return filterObject(inputObject, (currentKey) => {
return pickTheseKeys.includes(currentKey);
});
}