Skip to content

Commit b4a1e11

Browse files
authoredMay 6, 2024··
fix: override Array.prototype.map (#567)
also: fix image naming issue causing #562 closes #562
1 parent 207e149 commit b4a1e11

File tree

5 files changed

+35
-1
lines changed

5 files changed

+35
-1
lines changed
 

‎build/parser.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ class Parser {
531531
str
532532
.replace('/', '')
533533
.replace(/[ /*]/g, '-')
534-
.replace(/[:<>[\]?!]/g, '')
534+
.replace(/[:<>[\]?!"]/g, '')
535535
.toLowerCase();
536536
const imageStub = image.textureLocation;
537537
const ext = imageStub.split('.')[imageStub.split('.').length - 1].replace(/\?!.*/, '').replace(/!.*$/, ''); // .png, .jpg, etc
File renamed without changes.

‎index.js

+12
Original file line numberDiff line numberDiff line change
@@ -167,4 +167,16 @@ module.exports = class Items extends Array {
167167
}
168168
return A;
169169
}
170+
171+
/**
172+
* @Override Array.prototype.map
173+
*
174+
* See filter override
175+
*/
176+
map(fn) {
177+
const a = [];
178+
for (const el of this) a.push(fn(el));
179+
180+
return a;
181+
}
170182
};

‎index.mjs

+12
Original file line numberDiff line numberDiff line change
@@ -166,4 +166,16 @@ export default class Items extends Array {
166166
}
167167
return A;
168168
}
169+
170+
/**
171+
* @Override Array.prototype.filter
172+
*
173+
* See filter override
174+
*/
175+
map(fn) {
176+
const a = [];
177+
for (const el of this) a.push(fn(el));
178+
179+
return a;
180+
}
169181
}

‎test/index.spec.mjs

+10
Original file line numberDiff line numberDiff line change
@@ -268,5 +268,15 @@ for (const base of ['index.js', 'index.mjs']) {
268268
});
269269
});
270270
});
271+
it('should not change size when using filter', async () => {
272+
const items = await wrapConstr({ category: ['Arch-Gun'] });
273+
const realLength = items.length;
274+
assert(realLength === items.filter(() => true).length);
275+
});
276+
it('should not change size when using map', async () => {
277+
const items = await wrapConstr({ category: ['Arch-Gun'] });
278+
const realLength = items.length;
279+
assert(realLength === items.map((x) => x).length);
280+
});
271281
});
272282
}

0 commit comments

Comments
 (0)
Please sign in to comment.