LendAndRegret/node_modules/es-toolkit/dist/compat/object/toPairs.js
2026-05-02 17:27:43 +08:00

30 lines
789 B
JavaScript

'use strict';
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;