@adobe/acc-js-sdk
Advanced tools
Comparing version 1.1.42 to 1.1.43
{ | ||
"name": "@adobe/acc-js-sdk", | ||
"version": "1.1.42", | ||
"version": "1.1.43", | ||
"description": "ACC Javascript SDK", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -199,2 +199,4 @@ /* | ||
let isNumKey = false; | ||
let updateIndex = -1; | ||
if (key) { | ||
@@ -205,4 +207,6 @@ // reserved keyworkds | ||
// already a child with the name => there's a problem with the schema | ||
if (!isReserved && this[key]) | ||
throw new Error(`Failed to add element '${key}' to ArrayMap. There's already an item with the same name`); | ||
// it seems the current behavior is to replace the existing item with the new one | ||
if (!isReserved && this[key]) { | ||
updateIndex = this._items.indexOf(this[key]); | ||
} | ||
@@ -227,10 +231,15 @@ // Set key as a enumerable property, so that elements can be accessed by key, | ||
// However, make it non-enumerable to make sure indexes do not show up in a for .. in loop | ||
Object.defineProperty(this, this._items.length, { | ||
const numKey = updateIndex == -1 ? this._items.length : updateIndex; | ||
Object.defineProperty(this, numKey, { | ||
value: value, | ||
writable: false, | ||
enumerable: false, | ||
configurable: true, // Allow to redefine the property later in case there's a duplicate key | ||
}); | ||
} | ||
// Add to array and set length | ||
this._items.push(value); | ||
if (updateIndex == -1) | ||
this._items.push(value); | ||
else | ||
this._items[updateIndex] = value; | ||
this.length = this._items.length; | ||
@@ -237,0 +246,0 @@ } |
@@ -374,8 +374,24 @@ /* | ||
it("Should not support adding the same key twice", () => { | ||
it("Should support adding the same key twice. The last value overwrites", () => { | ||
const am = new ArrayMap(); | ||
am._push("hello", "Hello"); | ||
expect(() => { am._push("hello", "World"); }).toThrow("Failed to add element 'hello' to ArrayMap. There's already an item with the same name"); | ||
expect(am.length).toBe(1); | ||
am._push("hello", "World"); | ||
expect(am.length).toBe(1); | ||
expect(am.get(0)).toBe("World"); | ||
}); | ||
it("Should support adding the same key twice. The last value overwrites in the middle of the array", () => { | ||
const am = new ArrayMap(); | ||
am._push("hello", "Hello"); | ||
am._push("cruel", "Cruel"); | ||
am._push("world", "World"); | ||
expect(am.length).toBe(3); | ||
am._push("cruel", "*cruel*"); | ||
expect(am.length).toBe(3); | ||
expect(am.get(0)).toBe("Hello"); | ||
expect(am.get(1)).toBe("*cruel*"); | ||
expect(am.get(2)).toBe("World"); | ||
}); | ||
it("Should support missing names", () => { | ||
@@ -382,0 +398,0 @@ const am = new ArrayMap(); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
AI-detected potential code anomaly
Supply chain riskAI has identified unusual behaviors that may pose a security risk.
Found 1 instance in 1 package
1879647
30390
6
192