diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2025-06-14 09:26:07 -0300 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2025-06-14 09:26:07 -0300 |
commit | c31dce37cdf383b4358fd5ab1231705ab54a2c78 (patch) | |
tree | acd886f9a3ce8bddc9bd0123ab23ce93906b12d1 /src/common-util/sugar.js | |
parent | 2e644a786783aac2fb5d08e48c2af7a54b98ea00 (diff) |
sugar: make withEntries map-aware
Diffstat (limited to 'src/common-util/sugar.js')
-rw-r--r-- | src/common-util/sugar.js | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/src/common-util/sugar.js b/src/common-util/sugar.js index 699f1091..48442b13 100644 --- a/src/common-util/sugar.js +++ b/src/common-util/sugar.js @@ -254,11 +254,20 @@ export function compareObjects(obj1, obj2, { // Stolen from jq! Which pro8a8ly stole the concept from other places. Nice. export const withEntries = (obj, fn) => { - const result = fn(Object.entries(obj)); - if (result instanceof Promise) { - return result.then(entries => Object.fromEntries(entries)); + if (obj instanceof Map) { + const result = fn(Array.from(obj.entries())); + if (result instanceof Promise) { + return result.then(entries => new map(entries)); + } else { + return new Map(result); + } } else { - return Object.fromEntries(result); + const result = fn(Object.entries(obj)); + if (result instanceof Promise) { + return result.then(entries => Object.fromEntries(entries)); + } else { + return Object.fromEntries(result); + } } } |