@naverpay/hidash
Version:
improved lodash
21 lines (18 loc) • 861 B
TypeScript
import { AnyKindOfDictionary } from './internal/types.js';
/**
* @description
* Converts a given object, array, or collection into an array of key-value pairs.
*
* @param {AnyKindOfDictionary<Value> | object | Map<Key, Value> | Set<Value>} [object] The object to convert
* @returns {[Key, Value][]} An array of key-value pairs
*
* @example
* toPairs({ a: 1, b: 2 }) // [['a', 1], ['b', 2]]
* toPairs([1, 2, 3]) // [['0', 1], ['1', 2], ['2', 3]]
* toPairs(new Map([['a', 1], ['b', 2]])) // [['a', 1], ['b', 2]]
* toPairs(new Set([1, 2, 3])) // [[1, 1], [2, 2], [3, 3]]
* toPairs('abc') // [['0', 'a'], ['1', 'b'], ['2', 'c']]
* toPairs(null) // [], but type error
*/
declare function toPairs<Value, Key = Value>(object?: AnyKindOfDictionary<Value> | object | Map<Key, Value> | Set<Value>): [Key, Value][];
export { toPairs as default, toPairs };