UNPKG

@pnp/common

Version:

pnp - provides shared functionality across all pnp libraries

42 lines 1.46 kB
import { isFunc, objectDefinedNotNull } from "./util.js"; /** * Used to calculate the object properties, with polyfill if needed */ var objectEntries = isFunc(Object.entries) ? Object.entries : function (o) { return Object.keys(o).map(function (k) { return [k, o[k]]; }); }; /** * Converts the supplied object to a map * * @param o The object to map */ export function objectToMap(o) { if (objectDefinedNotNull(o)) { return new Map(objectEntries(o)); } return new Map(); } /** * Merges to Map instances together, overwriting values in target with matching keys, last in wins * * @param target map into which the other maps are merged * @param maps One or more maps to merge into the target */ export function mergeMaps(target) { var maps = []; for (var _i = 1; _i < arguments.length; _i++) { maps[_i - 1] = arguments[_i]; } for (var i = 0; i < maps.length; i++) { maps[i].forEach(function (v, k) { // let's not run the spfx context through Object.assign :) if ((typeof k === "string" && k !== "spfxContext") && Object.prototype.toString.call(v) === "[object Object]") { // we only handle one level of deep object merging target.set(k, Object.assign({}, target.get(k) || {}, v)); } else { target.set(k, v); } }); } return target; } //# sourceMappingURL=collections.js.map