-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bb0315d
commit a8165cd
Showing
8 changed files
with
181 additions
and
0 deletions.
There are no files selected for viewing
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,31 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
|
||
|
||
## keys variable | ||
|
||
> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment. | ||
> | ||
Returns the names of the enumerable string properties and methods of an object. | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
keys: <T extends PropertyKey>(val: Record<T, unknown>) => string[] | ||
``` | ||
|
||
## Remarks | ||
|
||
The order of the output array is not guaranteed to be consistent across different JS platforms. | ||
|
||
## Example | ||
|
||
|
||
```ts | ||
keys({}) // [] | ||
keys({ 'a': 'b' }) // ['a'] | ||
keys({ 0: 'hello', 1: 'world' }) // ['0', '1'] | ||
|
||
``` | ||
|
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,42 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
|
||
|
||
## values variable | ||
|
||
> This API is provided as a preview for developers and may change based on feedback that we receive. Do not use this API in a production environment. | ||
> | ||
Returns an array of values of the enumerable properties of an object. | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
values: <T extends unknown>(val: Record<PropertyKey, T> | ArrayLike<T>) => T[] | ||
``` | ||
|
||
## Remarks | ||
|
||
The order of the output array is not guaranteed to be consistent across different platforms. | ||
|
||
## Example 1 | ||
|
||
|
||
```ts | ||
// Object | ||
values({}) // [] | ||
values({ 'a': 'b' }) // ['b'] | ||
values({ 0: 'hello', 1: 'world' }) // ['hello', 'world'] | ||
|
||
``` | ||
|
||
## Example 2 | ||
|
||
|
||
```ts | ||
// Array | ||
values([]) // [] | ||
values(['hello', 'world']) // ['hello', 'world'] | ||
|
||
``` | ||
|
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,22 @@ | ||
/** | ||
* Returns the names of the enumerable string properties and methods of an object. | ||
* | ||
* @param val - `Object` that contains the properties and methods | ||
* @returns The result of `Object.keys(val)` | ||
* | ||
* @remarks | ||
* The order of the output array is not guaranteed to be consistent across different JS platforms. | ||
* | ||
* @example | ||
* ```ts | ||
* keys({}) // [] | ||
* keys({ 'a': 'b' }) // ['a'] | ||
* keys({ 0: 'hello', 1: 'world' }) // ['0', '1'] | ||
* ``` | ||
* | ||
* @beta | ||
*/ | ||
const keys = <T extends PropertyKey>(val: Record<T, unknown>): string[] => | ||
Object.keys(val) | ||
|
||
export { keys } |
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,31 @@ | ||
/** | ||
* Returns an array of values of the enumerable properties of an object. | ||
* | ||
* @param val - `Object` that contains the properties and methods | ||
* @returns The result of `Object.values(val)` | ||
* | ||
* @remarks | ||
* The order of the output array is not guaranteed to be consistent across different platforms. | ||
* | ||
* @example | ||
* ```ts | ||
* // Object | ||
* values({}) // [] | ||
* values({ 'a': 'b' }) // ['b'] | ||
* values({ 0: 'hello', 1: 'world' }) // ['hello', 'world'] | ||
* ``` | ||
* | ||
* @example | ||
* ```ts | ||
* // Array | ||
* values([]) // [] | ||
* values(['hello', 'world']) // ['hello', 'world'] | ||
* ``` | ||
* | ||
* @beta | ||
*/ | ||
const values = <T extends unknown>( | ||
val: Record<PropertyKey, T> | ArrayLike<T> | ||
): T[] => Object.values(val) | ||
|
||
export { values } |
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,21 @@ | ||
import { keys } from '@/keys' | ||
|
||
describe('keys', () => { | ||
const table: [Record<PropertyKey, unknown>, string[]][] = [ | ||
[{}, []], | ||
[{ '': '' }, ['']], | ||
[{ '': undefined }, ['']], | ||
[{ '': null }, ['']], | ||
[{ '': 0 }, ['']], | ||
[{ a: 0 }, ['a']], | ||
[{ a: 0, b: 1 }, ['a', 'b']], | ||
[{ a: 0, b: 1, c: 2 }, ['a', 'b', 'c']], | ||
[{ 0: '' }, ['0']], | ||
[{ 0: '', 1: 'a' }, ['0', '1']], | ||
[{ '': {}, 1: [] }, ['1', '']] | ||
] | ||
|
||
it.each(table)('keys(%s) -> %s', (val, expected) => { | ||
expect(keys(val)).toEqual(expected) | ||
}) | ||
}) |
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 @@ | ||
import { values } from '@/values' | ||
|
||
describe('values', () => { | ||
const table: [Record<PropertyKey, unknown> | ArrayLike<any>, any[]][] = [ | ||
[{}, []], | ||
[{ '': '' }, ['']], | ||
[{ '': undefined }, [undefined]], | ||
[{ '': null }, [null]], | ||
[{ '': 0 }, [0]], | ||
[{ a: 0 }, [0]], | ||
[{ a: 0, b: 1 }, [0, 1]], | ||
[{ a: 0, b: 1, c: 2 }, [0, 1, 2]], | ||
[{ 0: '' }, ['']], | ||
[{ 0: '', 1: 'a' }, ['', 'a']], | ||
[{ '': {}, 1: [] }, [[], {}]], | ||
[[], []], | ||
[[''], ['']], | ||
[[0], [0]], | ||
[[null], [null]], | ||
[[undefined], [undefined]], | ||
[ | ||
['hello', 'world'], | ||
['hello', 'world'] | ||
] | ||
] | ||
|
||
it.each(table)('values(%s) -> %s', (val, expected) => { | ||
expect(values(val)).toEqual(expected) | ||
}) | ||
}) |