toObjMap.js 391 B

123456789101112131415161718192021222324
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', {
  3. value: true,
  4. });
  5. exports.toObjMap = toObjMap;
  6. function toObjMap(obj) {
  7. if (obj == null) {
  8. return Object.create(null);
  9. }
  10. if (Object.getPrototypeOf(obj) === null) {
  11. return obj;
  12. }
  13. const map = Object.create(null);
  14. for (const [key, value] of Object.entries(obj)) {
  15. map[key] = value;
  16. }
  17. return map;
  18. }