es-toolkit
Version:
A state-of-the-art, high-performance JavaScript utility library with a small bundle size and strong type annotations.
30 lines (25 loc) • 789 B
JavaScript
;
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
const keys = require('./keys.js');
const mapToEntries = require('../_internal/mapToEntries.js');
const setToEntries = require('../_internal/setToEntries.js');
function toPairs(object) {
if (object == null) {
return [];
}
if (object instanceof Set) {
return setToEntries.setToEntries(object);
}
if (object instanceof Map) {
return mapToEntries.mapToEntries(object);
}
const keys$1 = keys.keys(object);
const result = new Array(keys$1.length);
for (let i = 0; i < keys$1.length; i++) {
const key = keys$1[i];
const value = object[key];
result[i] = [key, value];
}
return result;
}
exports.toPairs = toPairs;