From c31dce37cdf383b4358fd5ab1231705ab54a2c78 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Sat, 14 Jun 2025 09:26:07 -0300 Subject: sugar: make withEntries map-aware --- src/common-util/sugar.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'src') 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); + } } } -- cgit 1.3.0-6-gf8a5