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

26 lines
664 B
JavaScript

import { keysIn } from './keysIn.mjs';
import { mapToEntries } from '../_internal/mapToEntries.mjs';
import { setToEntries } from '../_internal/setToEntries.mjs';
function toPairsIn(object) {
if (object == null) {
return [];
}
if (object instanceof Set) {
return setToEntries(object);
}
if (object instanceof Map) {
return mapToEntries(object);
}
const keys = keysIn(object);
const result = new Array(keys.length);
for (let i = 0; i < keys.length; i++) {
const key = keys[i];
const value = object[key];
result[i] = [key, value];
}
return result;
}
export { toPairsIn };