forked from thi-ng/umbrella
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(associative): add renameKeysMap
- Loading branch information
1 parent
1f8af6c
commit bfabe80
Showing
1 changed file
with
13 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,22 @@ | ||
import { IObjectOf } from "@thi.ng/api/api"; | ||
|
||
import { empty } from "./utils"; | ||
|
||
export function renameKeysMap<T>(src: Map<any, T>, km: IObjectOf<T>): Map<any, T> { | ||
const dest = empty(src, Map); | ||
for (let p of src) { | ||
const k = p[0]; | ||
const kk = km[k]; | ||
dest.set(kk !== undefined ? kk : k, p[1]); | ||
} | ||
return dest; | ||
} | ||
|
||
export function renameKeysObj(src: any, km: IObjectOf<PropertyKey>) { | ||
const dest = {}; | ||
for (let k in src) { | ||
const kk = km[k]; | ||
dest[kk !== undefined ? kk : k] = src[k]; | ||
dest[kk != null ? kk : k] = src[k]; | ||
} | ||
return dest; | ||
} |