remove unused forEach

This commit is contained in:
MathMan05
2025-11-25 23:37:20 -06:00
parent 9871ce0028
commit 319b420fc0
2 changed files with 0 additions and 31 deletions
-13
View File
@@ -5,19 +5,6 @@ import { describe, it } from "node:test";
import assert from "node:assert/strict";
describe("Object extensions", () => {
it("forEach", async () => {
const obj: { [index:string]: number } = { a: 1, b: 2, c: 3 };
const keys: string[] = [];
const values: number[] = [];
obj.forEach<number>((value, key, _) => {
keys.push(key);
values.push(value);
});
console.log(keys, values);
assert.deepEqual(keys, ["a", "b", "c"]);
assert.deepEqual(values, [1, 2, 3]);
});
it("map", async () => {
const obj = { a: 1, b: 2, c: 3 };
const result = obj.map((value, key) => `${key}:${value}`);
-18
View File
@@ -1,16 +1,9 @@
declare global {
interface Object {
forEach<T>(callback: (value: T, key: string, object: { [index: string]: T }) => void): void;
map<SV, TV>(callback: (value: SV, key: string, object: { [index: string]: SV }) => TV): { [index: string]: TV };
}
}
export function objectForEach<T>(obj: { [index: string]: T }, callback: (value: T, key: string, object: { [index: string]: T }) => void): void {
Object.keys(obj).forEach((key) => {
callback(obj[key], key, obj);
});
}
export function objectMap<SV, TV>(srcObj: { [index: string]: SV }, callback: (value: SV, key: string, object: { [index: string]: SV }) => TV): { [index: string]: TV } {
if (typeof callback !== "function") throw new TypeError(`${callback} is not a function`);
const obj: { [index: string]: TV } = {};
@@ -20,17 +13,6 @@ export function objectMap<SV, TV>(srcObj: { [index: string]: SV }, callback: (va
return obj;
}
if (!Object.prototype.forEach)
Object.defineProperty(Object.prototype, "forEach", {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
value: function (cb) {
return objectForEach(this, cb);
},
enumerable: false,
writable: true,
});
if (!Object.prototype.map)
Object.defineProperty(Object.prototype, "map", {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment