feat(pkg): Add core extensions package
This commit is contained in:
21
packages/core-extensions/src/object/map.ts
Normal file
21
packages/core-extensions/src/object/map.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
declare global {
|
||||
interface Object {
|
||||
map<T, U>(
|
||||
this: Record<string, T>,
|
||||
callback: (value: T, key: string, obj: Record<string, T>) => U
|
||||
): Record<string, U>
|
||||
}
|
||||
}
|
||||
|
||||
Object.prototype.map = function <T, U>(
|
||||
this: Record<string, T>,
|
||||
callback: (value: T, key: string, obj: Record<string, T>) => U
|
||||
): Record<string, U> {
|
||||
const result: Record<string, U> = {}
|
||||
for (const [key, value] of Object.entries(this)) {
|
||||
result[key] = callback(value, key, this)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
export {}
|
||||
Reference in New Issue
Block a user