-
-
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
46c5492
commit e34bd23
Showing
6 changed files
with
192 additions
and
4 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
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
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,37 @@ | ||
// Copyright 2021-present the Fonction authors. All rights reserved. MIT license. | ||
import { entries as _entries } from './constants/index.ts' | ||
/** | ||
* Returns an array of key/values of the enumerable properties of an object. | ||
* | ||
* @param val - `Object` that contains the properties and methods | ||
* @returns The result of `Object.entries(val)` | ||
* | ||
* @remarks | ||
* The order of the output array is not guaranteed to be consistent across different JS platforms. | ||
* | ||
* @example | ||
* ```ts | ||
* entries({ a: 'b' }) // [['a', 'b']] | ||
* entries(['a', 'b', 'c']) // [['0', 'a'], ['1', 'b'], ['2', 'c']] | ||
* entries({}) // [] | ||
* entries([]) // [] | ||
* ``` | ||
* | ||
* @category `Object` `Array` | ||
* | ||
* @see Related to {@link keys} {@link values} | ||
* | ||
* @beta | ||
*/ | ||
const entries: { | ||
<T>( | ||
val: | ||
| { | ||
[key: string]: T | ||
} | ||
| ArrayLike<T> | ||
): [string, T][] | ||
(val: Record<string, unknown>): [string, unknown][] | ||
} = (val: any) => _entries(val) | ||
|
||
export { entries } |
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,36 @@ | ||
// Copyright 2021-present the Fonction authors. All rights reserved. MIT license. | ||
import { assertEquals } from '../deps.ts' | ||
import { entries } from '../src/entries.ts' | ||
|
||
Deno.test('entries', () => { | ||
const table: [Record<PropertyKey, unknown> | ArrayLike<any>, any[]][] = [ | ||
[[], []], | ||
[{}, []], | ||
[[''], [['0', '']]], | ||
[{ a: 1 }, [['a', 1]]], | ||
[{ [Symbol('key')]: 1 }, []], | ||
[{ [Symbol('key')]: 1, key: 'value' }, [['key', 'value']]], | ||
[{ a: 'b' }, [['a', 'b']]], | ||
[ | ||
{ a: 'b', c: 'd', e: 'f' }, | ||
[ | ||
['a', 'b'], | ||
['c', 'd'], | ||
['e', 'f'] | ||
] | ||
], | ||
[ | ||
{ a: 'b', 1: 'z', 0: 10, z: 1 }, | ||
[ | ||
['0', 10], | ||
['1', 'z'], | ||
['a', 'b'], | ||
['z', 1] | ||
] | ||
], | ||
[{ 1: 1 }, [['1', 1]]] | ||
] | ||
table.forEach(([val, expected]) => { | ||
assertEquals(entries(val), expected, `entries(${val}) -> ${expected}`) | ||
}) | ||
}) |