toObjMap.mjs 287 B

1234567891011121314151617
  1. export function toObjMap(obj) {
  2. if (obj == null) {
  3. return Object.create(null);
  4. }
  5. if (Object.getPrototypeOf(obj) === null) {
  6. return obj;
  7. }
  8. const map = Object.create(null);
  9. for (const [key, value] of Object.entries(obj)) {
  10. map[key] = value;
  11. }
  12. return map;
  13. }