forked from sindresorhus/filter-obj
/
index.d.ts
75 lines (64 loc) · 1.91 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/**
Filter object keys and values into a new object.
@param object - The source object to filter properties from.
@param predicate - Predicate function that determines whether a property should be assigned to the new object.
@param keys - Property keys that should be assigned to the new object.
@example
```
import {includeKeys} from 'filter-obj';
const object = {
foo: true,
bar: false
};
const newObject = includeKeys(object, (key, value) => value === true);
//=> {foo: true}
const newObject2 = includeKeys(object, ['bar']);
//=> {bar: false}
```
*/
export function includeKeys<ObjectType extends Record<PropertyKey, any>>(
object: ObjectType,
predicate: (
key: keyof ObjectType,
value: ObjectType[keyof ObjectType]
) => boolean
): Partial<ObjectType>;
export function includeKeys<
ObjectType extends Record<PropertyKey, any>,
IncludedKeys extends keyof ObjectType,
>(
object: ObjectType,
keys: readonly IncludedKeys[]
): Pick<ObjectType, IncludedKeys>;
/**
Filter object keys and values into a new object.
@param object - The source object to filter properties from.
@param predicate - Predicate function that determines whether a property should not be assigned to the new object.
@param keys - Property keys that should not be assigned to the new object.
@example
```
import {excludeKeys} from 'filter-obj';
const object = {
foo: true,
bar: false
};
const newObject = excludeKeys(object, (key, value) => value === true);
//=> {bar: false}
const newObject3 = excludeKeys(object, ['bar']);
//=> {foo: true}
```
*/
export function excludeKeys<ObjectType extends Record<PropertyKey, any>>(
object: ObjectType,
predicate: (
key: keyof ObjectType,
value: ObjectType[keyof ObjectType]
) => boolean
): Partial<ObjectType>;
export function excludeKeys<
ObjectType extends Record<PropertyKey, any>,
ExcludedKeys extends keyof ObjectType,
>(
object: ObjectType,
keys: readonly ExcludedKeys[]
): Omit<ObjectType, ExcludedKeys>;