@agoric/internal
Advanced tools
Comparing version 0.2.1-dev-885125e.0 to 0.2.1-dev-8ac3c4c.0
{ | ||
"name": "@agoric/internal", | ||
"version": "0.2.1-dev-885125e.0+885125e", | ||
"version": "0.2.1-dev-8ac3c4c.0+8ac3c4c", | ||
"description": "Externally unsupported utilities internal to agoric-sdk", | ||
@@ -37,3 +37,3 @@ "type": "module", | ||
}, | ||
"gitHead": "885125e69c57b78923cc2aa6862c06af68f6b590" | ||
"gitHead": "8ac3c4c434e732c30f90f3709a5cbc7750ef14bf" | ||
} |
@@ -11,5 +11,31 @@ // @ts-check | ||
const { details: X } = assert; | ||
const { details: X, quote: q } = assert; | ||
/** | ||
* Throws if multiple entries use the same property name. Otherwise acts | ||
* like `Object.fromEntries`. Use it to protect from property names | ||
* computed from user-provided data. | ||
* | ||
* @template K,V | ||
* @param {Iterable<[K,V]>} allEntries | ||
* @returns {{[k: K]: V}} | ||
*/ | ||
export const fromUniqueEntries = allEntries => { | ||
const entriesArray = [...allEntries]; | ||
const result = fromEntries(entriesArray); | ||
if (ownKeys(result).length === entriesArray.length) { | ||
return result; | ||
} | ||
const names = new Set(); | ||
for (const [name, _] of entriesArray) { | ||
if (names.has(name)) { | ||
assert.fail(X`collision on property name ${q(name)}: ${entriesArray}`); | ||
} | ||
names.add(name); | ||
} | ||
assert.fail(X`internal: failed to create object from unique entries`); | ||
}; | ||
harden(fromUniqueEntries); | ||
/** | ||
* By analogy with how `Array.prototype.map` will map the elements of | ||
@@ -16,0 +42,0 @@ * an array to transformed elements of an array of the same shape, |
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
25950
347