UNPKG

1.46 kBJavaScriptView Raw
1import { isFunc, objectDefinedNotNull } from "./util.js";
2/**
3 * Used to calculate the object properties, with polyfill if needed
4 */
5var objectEntries = isFunc(Object.entries) ? Object.entries : function (o) { return Object.keys(o).map(function (k) { return [k, o[k]]; }); };
6/**
7 * Converts the supplied object to a map
8 *
9 * @param o The object to map
10 */
11export function objectToMap(o) {
12 if (objectDefinedNotNull(o)) {
13 return new Map(objectEntries(o));
14 }
15 return new Map();
16}
17/**
18 * Merges to Map instances together, overwriting values in target with matching keys, last in wins
19 *
20 * @param target map into which the other maps are merged
21 * @param maps One or more maps to merge into the target
22 */
23export function mergeMaps(target) {
24 var maps = [];
25 for (var _i = 1; _i < arguments.length; _i++) {
26 maps[_i - 1] = arguments[_i];
27 }
28 for (var i = 0; i < maps.length; i++) {
29 maps[i].forEach(function (v, k) {
30 // let's not run the spfx context through Object.assign :)
31 if ((typeof k === "string" && k !== "spfxContext") && Object.prototype.toString.call(v) === "[object Object]") {
32 // we only handle one level of deep object merging
33 target.set(k, Object.assign({}, target.get(k) || {}, v));
34 }
35 else {
36 target.set(k, v);
37 }
38 });
39 }
40 return target;
41}
42//# sourceMappingURL=collections.js.map
\No newline at end of file