@oscarpalmer/atoms 0.77.0 → 0.77.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/dist/js/array/chunk.cjs +1 -1
  2. package/dist/js/array/chunk.js +1 -1
  3. package/dist/js/value/equal.cjs +4 -1
  4. package/dist/js/value/equal.js +4 -1
  5. package/package.json +1 -1
  6. package/src/js/array/chunk.ts +1 -1
  7. package/src/js/array/count.ts +6 -6
  8. package/src/js/array/exists.ts +6 -6
  9. package/src/js/array/filter.ts +6 -6
  10. package/src/js/array/find.ts +6 -6
  11. package/src/js/array/group-by.ts +67 -55
  12. package/src/js/array/index-of.ts +6 -6
  13. package/src/js/array/sort.ts +20 -0
  14. package/src/js/array/to-map.ts +55 -47
  15. package/src/js/array/to-record.ts +61 -57
  16. package/src/js/array/unique.ts +6 -6
  17. package/src/js/internal/value/handle.ts +5 -5
  18. package/src/js/value/clone.ts +3 -1
  19. package/src/js/value/equal.ts +4 -1
  20. package/src/js/value/get.ts +9 -9
  21. package/src/js/value/set.ts +10 -11
  22. package/types/array/count.d.cts +34 -2
  23. package/types/array/count.d.ts +3 -3
  24. package/types/array/exists.d.cts +34 -2
  25. package/types/array/exists.d.ts +3 -3
  26. package/types/array/filter.d.cts +34 -2
  27. package/types/array/filter.d.ts +3 -3
  28. package/types/array/find.d.cts +34 -2
  29. package/types/array/find.d.ts +3 -3
  30. package/types/array/group-by.d.cts +44 -12
  31. package/types/array/group-by.d.ts +14 -14
  32. package/types/array/index-of.d.cts +34 -2
  33. package/types/array/index-of.d.ts +3 -3
  34. package/types/array/index.d.cts +88 -46
  35. package/types/array/sort.d.cts +42 -0
  36. package/types/array/sort.d.ts +11 -1
  37. package/types/array/to-map.d.cts +42 -10
  38. package/types/array/to-map.d.ts +13 -13
  39. package/types/array/to-record.d.cts +44 -12
  40. package/types/array/to-record.d.ts +13 -13
  41. package/types/array/unique.d.cts +34 -2
  42. package/types/array/unique.d.ts +3 -3
  43. package/types/index.d.cts +1034 -317
  44. package/types/internal/value/handle.d.cts +27 -2
  45. package/types/internal/value/handle.d.ts +2 -2
  46. package/types/models.d.cts +467 -210
  47. package/types/value/clone.d.cts +1 -1
  48. package/types/value/clone.d.ts +1 -1
  49. package/types/value/get.d.cts +470 -211
  50. package/types/value/get.d.ts +3 -3
  51. package/types/value/index.d.cts +515 -224
  52. package/types/value/set.d.cts +357 -170
  53. package/types/value/set.d.ts +3 -3
  54. package/types/value/smush.d.cts +463 -209
@@ -1,5 +1,5 @@
1
1
  import {groupValues} from '~/array/group-by';
2
- import type {KeyedValue, PlainObject, Key as SimpleKey} from '~/models';
2
+ import type {Key, KeyedValue, PlainObject} from '~/models';
3
3
 
4
4
  /**
5
5
  * Create a record from an array of items _(using their indices as keys)_
@@ -9,143 +9,147 @@ export function toRecord<Item>(array: Item[]): Record<number, Item>;
9
9
  /**
10
10
  * Create a record from an array of items using a specific key
11
11
  */
12
- export function toRecord<Item, Key extends keyof Item>(
12
+ export function toRecord<Item extends PlainObject, ItemKey extends keyof Item>(
13
13
  array: Item[],
14
- key: Key,
15
- ): Record<KeyedValue<Item, Key>, Item>;
14
+ key: ItemKey,
15
+ ): Record<KeyedValue<Item, ItemKey>, Item>;
16
16
 
17
17
  /**
18
18
  * Create a record from an array of items using a specific key, and grouping them into arrays
19
19
  */
20
- export function toRecord<Item, Key extends keyof Item>(
20
+ export function toRecord<Item extends PlainObject, ItemKey extends keyof Item>(
21
21
  array: Item[],
22
- key: Key,
22
+ key: ItemKey,
23
23
  arrays: true,
24
- ): Record<KeyedValue<Item, Key>, Item[]>;
24
+ ): Record<KeyedValue<Item, ItemKey>, Item[]>;
25
25
 
26
26
  /**
27
27
  * Create a record from an array of items using a specific key
28
28
  */
29
29
  export function toRecord<
30
30
  Item,
31
- Key extends (item: Item, index: number, array: Item[]) => SimpleKey,
32
- >(array: Item[], key: Key): Record<ReturnType<Key>, Item>;
31
+ ItemKey extends (item: Item, index: number, array: Item[]) => Key,
32
+ >(array: Item[], key: ItemKey): Record<ReturnType<ItemKey>, Item>;
33
33
 
34
34
  /**
35
35
  * Create a record from an array of items using a specific key, and grouping them into arrays
36
36
  */
37
37
  export function toRecord<
38
38
  Item,
39
- Key extends (item: Item, index: number, array: Item[]) => SimpleKey,
40
- >(array: Item[], key: Key, arrays: true): Record<ReturnType<Key>, Item[]>;
39
+ ItemKey extends (item: Item, index: number, array: Item[]) => Key,
40
+ >(
41
+ array: Item[],
42
+ key: ItemKey,
43
+ arrays: true,
44
+ ): Record<ReturnType<ItemKey>, Item[]>;
41
45
 
42
46
  /**
43
47
  * Create a record from an array of items using a specific key and value
44
48
  */
45
49
  export function toRecord<
46
- Item,
47
- Key extends keyof Item,
48
- Value extends keyof Item,
50
+ Item extends PlainObject,
51
+ ItemKey extends keyof Item,
52
+ ItemValue extends keyof Item,
49
53
  >(
50
54
  array: Item[],
51
- key: Key,
52
- value: Value,
53
- ): Record<KeyedValue<Item, Key>, KeyedValue<Item, Value>>;
55
+ key: ItemKey,
56
+ value: ItemValue,
57
+ ): Record<KeyedValue<Item, ItemKey>, KeyedValue<Item, ItemValue>>;
54
58
 
55
59
  /**
56
60
  * Create a record from an array of items using a specific key and value, and grouping them into arrays
57
61
  */
58
62
  export function toRecord<
59
- Item,
60
- Key extends keyof Item,
61
- Value extends keyof Item,
63
+ Item extends PlainObject,
64
+ ItemKey extends keyof Item,
65
+ ItemValue extends keyof Item,
62
66
  >(
63
67
  array: Item[],
64
- key: Key,
65
- value: Value,
68
+ key: ItemKey,
69
+ value: ItemValue,
66
70
  arrays: true,
67
- ): Record<KeyedValue<Item, Key>, Array<KeyedValue<Item, Value>>>;
71
+ ): Record<KeyedValue<Item, ItemKey>, Array<KeyedValue<Item, ItemValue>>>;
68
72
 
69
73
  /**
70
74
  * Create a record from an array of items using a specific key and value
71
75
  */
72
76
  export function toRecord<
73
- Item,
74
- Key extends keyof Item,
75
- Value extends (item: Item, index: number, array: Item[]) => unknown,
77
+ Item extends PlainObject,
78
+ ItemKey extends keyof Item,
79
+ ItemValue extends (item: Item, index: number, array: Item[]) => unknown,
76
80
  >(
77
81
  array: Item[],
78
- key: Key,
79
- value: Value,
80
- ): Record<KeyedValue<Item, Key>, ReturnType<Value>>;
82
+ key: ItemKey,
83
+ value: ItemValue,
84
+ ): Record<KeyedValue<Item, ItemKey>, ReturnType<ItemValue>>;
81
85
 
82
86
  /**
83
87
  * Create a record from an array of items using a specific key and value, and grouping them into arrays
84
88
  */
85
89
  export function toRecord<
86
- Item,
87
- Key extends keyof Item,
88
- Value extends (item: Item, index: number, array: Item[]) => unknown,
90
+ Item extends PlainObject,
91
+ ItemKey extends keyof Item,
92
+ ItemValue extends (item: Item, index: number, array: Item[]) => unknown,
89
93
  >(
90
94
  array: Item[],
91
- key: Key,
92
- value: Value,
95
+ key: ItemKey,
96
+ value: ItemValue,
93
97
  arrays: true,
94
- ): Record<KeyedValue<Item, Key>, Array<ReturnType<Value>>>;
98
+ ): Record<KeyedValue<Item, ItemKey>, Array<ReturnType<ItemValue>>>;
95
99
 
96
100
  /**
97
101
  * Create a record from an array of items using a specific key and value
98
102
  */
99
103
  export function toRecord<
100
- Item,
101
- Key extends (item: Item, index: number, array: Item[]) => SimpleKey,
102
- Value extends keyof Item,
104
+ Item extends PlainObject,
105
+ ItemKey extends (item: Item, index: number, array: Item[]) => Key,
106
+ ItemValue extends keyof Item,
103
107
  >(
104
108
  array: Item[],
105
- key: Key,
106
- value: Value,
107
- ): Record<ReturnType<Key>, KeyedValue<Item, Value>>;
109
+ key: ItemKey,
110
+ value: ItemValue,
111
+ ): Record<ReturnType<ItemKey>, KeyedValue<Item, ItemValue>>;
108
112
 
109
113
  /**
110
114
  * Create a record from an array of items using a specific key and value, and grouping them into arrays
111
115
  */
112
116
  export function toRecord<
113
- Item,
114
- Key extends (item: Item, index: number, array: Item[]) => SimpleKey,
115
- Value extends keyof Item,
117
+ Item extends PlainObject,
118
+ ItemKey extends (item: Item, index: number, array: Item[]) => Key,
119
+ ItemValue extends keyof Item,
116
120
  >(
117
121
  array: Item[],
118
- key: Key,
119
- value: Value,
122
+ key: ItemKey,
123
+ value: ItemValue,
120
124
  arrays: true,
121
- ): Record<ReturnType<Key>, Array<KeyedValue<Item, Value>>>;
125
+ ): Record<ReturnType<ItemKey>, Array<KeyedValue<Item, ItemValue>>>;
122
126
 
123
127
  /**
124
128
  * Create a record from an array of items using a specific key and value
125
129
  */
126
130
  export function toRecord<
127
131
  Item,
128
- Key extends (item: Item, index: number, array: Item[]) => SimpleKey,
129
- Value extends (item: Item, index: number, array: Item[]) => unknown,
132
+ ItemKey extends (item: Item, index: number, array: Item[]) => Key,
133
+ ItemValue extends (item: Item, index: number, array: Item[]) => unknown,
130
134
  >(
131
135
  array: Item[],
132
- key: Key,
133
- value: Value,
134
- ): Record<ReturnType<Key>, ReturnType<Value>>;
136
+ key: ItemKey,
137
+ value: ItemValue,
138
+ ): Record<ReturnType<ItemKey>, ReturnType<ItemValue>>;
135
139
 
136
140
  /**
137
141
  * Create a record from an array of items using a specific key and value, and grouping them into arrays
138
142
  */
139
143
  export function toRecord<
140
144
  Item,
141
- Key extends (item: Item, index: number, array: Item[]) => SimpleKey,
142
- Value extends (item: Item, index: number, array: Item[]) => unknown,
145
+ ItemKey extends (item: Item, index: number, array: Item[]) => Key,
146
+ ItemValue extends (item: Item, index: number, array: Item[]) => unknown,
143
147
  >(
144
148
  array: Item[],
145
- key: Key,
146
- value: Value,
149
+ key: ItemKey,
150
+ value: ItemValue,
147
151
  arrays: true,
148
- ): Record<ReturnType<Key>, Array<ReturnType<Value>>>;
152
+ ): Record<ReturnType<ItemKey>, Array<ReturnType<ItemValue>>>;
149
153
 
150
154
  export function toRecord(
151
155
  array: unknown[],
@@ -1,5 +1,5 @@
1
1
  import {findValues} from '~/internal/array/find';
2
- import type {Key as SimpleKey} from '~/models';
2
+ import type {Key, PlainObject} from '~/models';
3
3
 
4
4
  /**
5
5
  * Get an array of unique items
@@ -10,9 +10,9 @@ export function unique<Item>(array: Item[]): Item[];
10
10
  * - Get an array of unique items
11
11
  * - Use `key` to find a comparison value for an item
12
12
  */
13
- export function unique<Item, Key extends keyof Item>(
13
+ export function unique<Item extends PlainObject, ItemKey extends keyof Item>(
14
14
  array: Item[],
15
- key: Key,
15
+ key: ItemKey,
16
16
  ): Item[];
17
17
 
18
18
  /**
@@ -20,9 +20,9 @@ export function unique<Item, Key extends keyof Item>(
20
20
  * - Use `key` to find a comparison value for an item
21
21
  */
22
22
  export function unique<
23
- Item,
24
- Key extends (item: Item, index: number, array: Item[]) => SimpleKey,
25
- >(array: Item[], key: Key): Item[];
23
+ Item,
24
+ ItemKey extends (item: Item, index: number, array: Item[]) => Key,
25
+ >(array: Item[], key: ItemKey): Item[];
26
26
 
27
27
  export function unique(array: unknown[], key?: unknown): unknown[] {
28
28
  return findValues('unique', array, [key, undefined]);
@@ -1,8 +1,8 @@
1
- import type {PlainObject} from '~/models';
1
+ import type {ArrayOrPlainObject, PlainObject} from '~/models';
2
2
 
3
3
  function findKey(
4
4
  needle: string,
5
- haystack: PlainObject,
5
+ haystack: ArrayOrPlainObject,
6
6
  ignoreCase: boolean,
7
7
  ): string {
8
8
  if (!ignoreCase) {
@@ -17,7 +17,7 @@ function findKey(
17
17
  }
18
18
 
19
19
  export function handleValue(
20
- data: PlainObject,
20
+ data: ArrayOrPlainObject,
21
21
  path: string,
22
22
  value: unknown,
23
23
  get: boolean,
@@ -31,9 +31,9 @@ export function handleValue(
31
31
  const key = findKey(path, data, ignoreCase);
32
32
 
33
33
  if (get) {
34
- return data[key];
34
+ return data[key as never];
35
35
  }
36
36
 
37
- data[key] = value;
37
+ (data as PlainObject)[key] = value;
38
38
  }
39
39
  }
@@ -4,6 +4,8 @@ import type {ArrayOrPlainObject, GenericCallback, PlainObject} from '~/models';
4
4
  /**
5
5
  * Clone any kind of value _(deeply, if needed)_
6
6
  */
7
+ export function clone<Value>(value: Value): Value;
8
+
7
9
  export function clone(value: unknown) {
8
10
  switch (true) {
9
11
  case value == null:
@@ -60,7 +62,7 @@ function cloneArrayBuffer(value: ArrayBuffer): ArrayBuffer {
60
62
  }
61
63
 
62
64
  function cloneDataView(value: DataView): DataView {
63
- const buffer = cloneArrayBuffer(value.buffer);
65
+ const buffer = cloneArrayBuffer(value.buffer as ArrayBuffer);
64
66
 
65
67
  return new DataView(buffer, value.byteOffset, value.byteLength);
66
68
  }
@@ -75,7 +75,10 @@ function equalArrayBuffer(first: ArrayBuffer, second: ArrayBuffer): boolean {
75
75
 
76
76
  function equalDataView(first: DataView, second: DataView): boolean {
77
77
  return first.byteOffset === second.byteOffset
78
- ? equalArrayBuffer(first.buffer, second.buffer)
78
+ ? equalArrayBuffer(
79
+ first.buffer as ArrayBuffer,
80
+ second.buffer as ArrayBuffer,
81
+ )
79
82
  : false;
80
83
  }
81
84
 
@@ -1,16 +1,16 @@
1
1
  import type {ToString} from 'type-fest/source/internal/string';
2
2
  import {handleValue} from '~/internal/value/handle';
3
- import type {Get, Paths, PlainObject} from '~/models';
3
+ import type {ArrayOrPlainObject, Get, Paths} from '~/models';
4
4
 
5
5
  /**
6
6
  * - Get the value from an object using a known path
7
7
  * - You can retrieve a nested value by using dot notation, e.g., `foo.bar.baz`
8
8
  * - Returns `undefined` if the value is not found
9
9
  */
10
- export function getValue<Data extends PlainObject, Path extends Paths<Data>>(
11
- data: Data,
12
- path: Path,
13
- ): Get<Data, ToString<Path>>;
10
+ export function getValue<
11
+ Data extends ArrayOrPlainObject,
12
+ Path extends Paths<Data>,
13
+ >(data: Data, path: Path): Get<Data, ToString<Path>>;
14
14
 
15
15
  /**
16
16
  * - Get the value from an object using an unknown path
@@ -18,14 +18,14 @@ export function getValue<Data extends PlainObject, Path extends Paths<Data>>(
18
18
  * - If `ignoreCase` is `true`, path matching will be case-insensitive
19
19
  * - Returns `undefined` if the value is not found
20
20
  */
21
- export function getValue<Data extends PlainObject>(
21
+ export function getValue<Data extends ArrayOrPlainObject>(
22
22
  data: Data,
23
23
  path: string,
24
24
  ignoreCase?: boolean,
25
25
  ): unknown;
26
26
 
27
27
  export function getValue(
28
- data: PlainObject,
28
+ data: ArrayOrPlainObject,
29
29
  path: string,
30
30
  ignoreCase?: boolean,
31
31
  ): unknown {
@@ -34,7 +34,7 @@ export function getValue(
34
34
  const {length} = parts;
35
35
 
36
36
  let index = 0;
37
- let value: PlainObject = data;
37
+ let value: ArrayOrPlainObject = data;
38
38
 
39
39
  while (index < length && value != null) {
40
40
  value = handleValue(
@@ -43,7 +43,7 @@ export function getValue(
43
43
  null,
44
44
  true,
45
45
  shouldIgnoreCase,
46
- ) as PlainObject;
46
+ ) as ArrayOrPlainObject;
47
47
  }
48
48
 
49
49
  return value as never;
@@ -1,5 +1,5 @@
1
1
  import {handleValue} from '~/internal/value/handle';
2
- import type {Paths, PlainObject} from '~/models';
2
+ import type {ArrayOrPlainObject, Paths, PlainObject} from '~/models';
3
3
 
4
4
  /**
5
5
  * - Set the value in an object using a known path
@@ -7,11 +7,10 @@ import type {Paths, PlainObject} from '~/models';
7
7
  * - If a part of the path does not exist, it will be created, either as an array or a generic object, depending on the path
8
8
  * - Returns the original object
9
9
  */
10
- export function setValue<Data extends PlainObject, Path extends Paths<Data>>(
11
- data: Data,
12
- path: Path,
13
- value: unknown,
14
- ): Data;
10
+ export function setValue<
11
+ Data extends ArrayOrPlainObject,
12
+ Path extends Paths<Data>,
13
+ >(data: Data, path: Path, value: unknown): Data;
15
14
 
16
15
  /**
17
16
  * - Set the value in an object using an unknown path
@@ -20,14 +19,14 @@ export function setValue<Data extends PlainObject, Path extends Paths<Data>>(
20
19
  * - If `ignoreCase` is `true`, path matching will be case-insensitive
21
20
  * - Returns the original object
22
21
  */
23
- export function setValue<Data extends PlainObject>(
22
+ export function setValue<Data extends ArrayOrPlainObject>(
24
23
  data: Data,
25
24
  path: string,
26
25
  value: unknown,
27
26
  ignoreCase?: boolean,
28
27
  ): Data;
29
28
 
30
- export function setValue<Data extends PlainObject>(
29
+ export function setValue<Data extends ArrayOrPlainObject>(
31
30
  data: Data,
32
31
  path: string,
33
32
  value: unknown,
@@ -38,7 +37,7 @@ export function setValue<Data extends PlainObject>(
38
37
  const {length} = parts;
39
38
  const lastIndex = length - 1;
40
39
 
41
- let target: PlainObject = data;
40
+ let target: ArrayOrPlainObject = data;
42
41
 
43
42
  for (let index = 0; index < length; index += 1) {
44
43
  const part = parts[index];
@@ -54,10 +53,10 @@ export function setValue<Data extends PlainObject>(
54
53
  if (typeof next !== 'object' || next === null) {
55
54
  next = {};
56
55
 
57
- target[part] = next;
56
+ (target as PlainObject)[part] = next;
58
57
  }
59
58
 
60
- target = next as PlainObject;
59
+ target = next as ArrayOrPlainObject;
61
60
  }
62
61
 
63
62
  return data;
@@ -1,6 +1,38 @@
1
1
  // Generated by dts-bundle-generator v9.5.1
2
2
 
3
+ /**
4
+ Represents an object with `unknown` value. You probably want this instead of `{}`.
5
+
6
+ Use case: You have an object whose keys and values are unknown to you.
7
+
8
+ @example
9
+ ```
10
+ import type {UnknownRecord} from 'type-fest';
11
+
12
+ function toJson(object: UnknownRecord) {
13
+ return JSON.stringify(object);
14
+ }
15
+
16
+ toJson({hello: 'world'});
17
+ //=> '{"hello":"world"}'
18
+
19
+ function isObject(value: unknown): value is UnknownRecord {
20
+ return typeof value === 'object' && value !== null;
21
+ }
22
+
23
+ isObject({hello: 'world'});
24
+ //=> true
25
+
26
+ isObject('hello');
27
+ //=> false
28
+ ```
29
+
30
+ @category Type
31
+ @category Object
32
+ */
33
+ export type UnknownRecord = Record<PropertyKey, unknown>;
3
34
  export type Key = number | string;
35
+ export type PlainObject = UnknownRecord;
4
36
  /**
5
37
  * Get the number of items _(count)_ that match the given value
6
38
  */
@@ -12,10 +44,10 @@ export declare function count<Item>(array: Item[], matches: (item: Item, index:
12
44
  /**
13
45
  * Get the number of items _(count)_ that match the given value
14
46
  */
15
- export declare function count<Item, Key extends keyof Item>(array: Item[], key: Key, value: Item[Key]): number;
47
+ export declare function count<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, value: Item[ItemKey]): number;
16
48
  /**
17
49
  * Get the number of items _(count)_ that match the given value
18
50
  */
19
- export declare function count<Item, Key extends (item: Item, index: number, array: Item[]) => Key>(array: Item[], key: Key, value: ReturnType<Key>): number;
51
+ export declare function count<Item, ItemKey extends (item: Item, index: number, array: Item[]) => Key>(array: Item[], key: ItemKey, value: ReturnType<ItemKey>): number;
20
52
 
21
53
  export {};
@@ -1,4 +1,4 @@
1
- import type { Key as SimpleKey } from '~/models';
1
+ import type { Key, PlainObject } from '~/models';
2
2
  /**
3
3
  * Get the number of items _(count)_ that match the given value
4
4
  */
@@ -10,8 +10,8 @@ export declare function count<Item>(array: Item[], matches: (item: Item, index:
10
10
  /**
11
11
  * Get the number of items _(count)_ that match the given value
12
12
  */
13
- export declare function count<Item, Key extends keyof Item>(array: Item[], key: Key, value: Item[Key]): number;
13
+ export declare function count<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, value: Item[ItemKey]): number;
14
14
  /**
15
15
  * Get the number of items _(count)_ that match the given value
16
16
  */
17
- export declare function count<Item, Key extends (item: Item, index: number, array: Item[]) => SimpleKey>(array: Item[], key: Key, value: ReturnType<Key>): number;
17
+ export declare function count<Item, ItemKey extends (item: Item, index: number, array: Item[]) => Key>(array: Item[], key: ItemKey, value: ReturnType<ItemKey>): number;
@@ -1,6 +1,38 @@
1
1
  // Generated by dts-bundle-generator v9.5.1
2
2
 
3
+ /**
4
+ Represents an object with `unknown` value. You probably want this instead of `{}`.
5
+
6
+ Use case: You have an object whose keys and values are unknown to you.
7
+
8
+ @example
9
+ ```
10
+ import type {UnknownRecord} from 'type-fest';
11
+
12
+ function toJson(object: UnknownRecord) {
13
+ return JSON.stringify(object);
14
+ }
15
+
16
+ toJson({hello: 'world'});
17
+ //=> '{"hello":"world"}'
18
+
19
+ function isObject(value: unknown): value is UnknownRecord {
20
+ return typeof value === 'object' && value !== null;
21
+ }
22
+
23
+ isObject({hello: 'world'});
24
+ //=> true
25
+
26
+ isObject('hello');
27
+ //=> false
28
+ ```
29
+
30
+ @category Type
31
+ @category Object
32
+ */
33
+ export type UnknownRecord = Record<PropertyKey, unknown>;
3
34
  export type Key = number | string;
35
+ export type PlainObject = UnknownRecord;
4
36
  /**
5
37
  * Does the value exist in array?
6
38
  */
@@ -13,11 +45,11 @@ export declare function exists<Item>(array: Item[], matches: (item: Item, index:
13
45
  * - Does the value exist in array?
14
46
  * - Use `key` to find a comparison value to match with `value`
15
47
  */
16
- export declare function exists<Item, Key extends keyof Item>(array: Item[], key: Key, value: Item[Key]): boolean;
48
+ export declare function exists<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, value: Item[ItemKey]): boolean;
17
49
  /**
18
50
  * - Does the value exist in array?
19
51
  * - Use `key` to find a comparison value to match with `value`
20
52
  */
21
- export declare function exists<Item, Key extends (item: Item, index: number, array: Item[]) => Key>(array: Item[], key: Key, value: ReturnType<Key>): boolean;
53
+ export declare function exists<Item, ItemKey extends (item: Item, index: number, array: Item[]) => Key>(array: Item[], key: ItemKey, value: ReturnType<ItemKey>): boolean;
22
54
 
23
55
  export {};
@@ -1,4 +1,4 @@
1
- import type { Key as SimpleKey } from '~/models';
1
+ import type { Key, PlainObject } from '~/models';
2
2
  /**
3
3
  * Does the value exist in array?
4
4
  */
@@ -11,9 +11,9 @@ export declare function exists<Item>(array: Item[], matches: (item: Item, index:
11
11
  * - Does the value exist in array?
12
12
  * - Use `key` to find a comparison value to match with `value`
13
13
  */
14
- export declare function exists<Item, Key extends keyof Item>(array: Item[], key: Key, value: Item[Key]): boolean;
14
+ export declare function exists<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, value: Item[ItemKey]): boolean;
15
15
  /**
16
16
  * - Does the value exist in array?
17
17
  * - Use `key` to find a comparison value to match with `value`
18
18
  */
19
- export declare function exists<Item, Key extends (item: Item, index: number, array: Item[]) => SimpleKey>(array: Item[], key: Key, value: ReturnType<Key>): boolean;
19
+ export declare function exists<Item, ItemKey extends (item: Item, index: number, array: Item[]) => Key>(array: Item[], key: ItemKey, value: ReturnType<ItemKey>): boolean;
@@ -1,6 +1,38 @@
1
1
  // Generated by dts-bundle-generator v9.5.1
2
2
 
3
+ /**
4
+ Represents an object with `unknown` value. You probably want this instead of `{}`.
5
+
6
+ Use case: You have an object whose keys and values are unknown to you.
7
+
8
+ @example
9
+ ```
10
+ import type {UnknownRecord} from 'type-fest';
11
+
12
+ function toJson(object: UnknownRecord) {
13
+ return JSON.stringify(object);
14
+ }
15
+
16
+ toJson({hello: 'world'});
17
+ //=> '{"hello":"world"}'
18
+
19
+ function isObject(value: unknown): value is UnknownRecord {
20
+ return typeof value === 'object' && value !== null;
21
+ }
22
+
23
+ isObject({hello: 'world'});
24
+ //=> true
25
+
26
+ isObject('hello');
27
+ //=> false
28
+ ```
29
+
30
+ @category Type
31
+ @category Object
32
+ */
33
+ export type UnknownRecord = Record<PropertyKey, unknown>;
3
34
  export type Key = number | string;
35
+ export type PlainObject = UnknownRecord;
4
36
  /**
5
37
  * Get a filtered array of items matching `value`
6
38
  */
@@ -13,11 +45,11 @@ export declare function filter<Item>(array: Item[], matches: (item: Item, index:
13
45
  * - Get a filtered array of items
14
46
  * - Use `key` to find a comparison value to match with `value`
15
47
  */
16
- export declare function filter<Item, Key extends keyof Item>(array: Item[], key: Key, value: Item[Key]): Item[];
48
+ export declare function filter<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, value: Item[ItemKey]): Item[];
17
49
  /**
18
50
  * - Get a filtered array of items
19
51
  * - Use `key` to find a comparison value to match with `value`
20
52
  */
21
- export declare function filter<Item, Key extends (item: Item, index: number, array: Item[]) => Key>(array: Item[], key: Key, value: ReturnType<Key>): Item[];
53
+ export declare function filter<Item, ItemKey extends (item: Item, index: number, array: Item[]) => Key>(array: Item[], key: ItemKey, value: ReturnType<ItemKey>): Item[];
22
54
 
23
55
  export {};
@@ -1,4 +1,4 @@
1
- import type { Key as SimpleKey } from '~/models';
1
+ import type { Key, PlainObject } from '~/models';
2
2
  /**
3
3
  * Get a filtered array of items matching `value`
4
4
  */
@@ -11,9 +11,9 @@ export declare function filter<Item>(array: Item[], matches: (item: Item, index:
11
11
  * - Get a filtered array of items
12
12
  * - Use `key` to find a comparison value to match with `value`
13
13
  */
14
- export declare function filter<Item, Key extends keyof Item>(array: Item[], key: Key, value: Item[Key]): Item[];
14
+ export declare function filter<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, value: Item[ItemKey]): Item[];
15
15
  /**
16
16
  * - Get a filtered array of items
17
17
  * - Use `key` to find a comparison value to match with `value`
18
18
  */
19
- export declare function filter<Item, Key extends (item: Item, index: number, array: Item[]) => SimpleKey>(array: Item[], key: Key, value: ReturnType<Key>): Item[];
19
+ export declare function filter<Item, ItemKey extends (item: Item, index: number, array: Item[]) => Key>(array: Item[], key: ItemKey, value: ReturnType<ItemKey>): Item[];