UNPKG

@n3okill/utils

Version:
22 lines 679 B
import { isArray } from "../type/isArray"; import { isMap } from "../type/isMap"; import { isObject } from "../type/isObject"; /** * Transforms argument into Map * @param arg Argument to be transformed into Map * @returns Resulting Map from argument given or undefined if the argument is not Object, Array or Map */ export function toMap(arg) { if (isMap(arg)) { return arg; } if (isObject(arg)) { // eslint-disable-next-line security/detect-object-injection return new Map(Object.keys(arg).map((k) => [k, arg[k]])); } if (isArray(arg)) { return new Map(arg); } return undefined; } //# sourceMappingURL=toMap.js.map