UNPKG

dotnet-deps-parser

Version:

Generate a dep tree given a collection of manifests

45 lines • 1.95 kB
"use strict"; // MSBuild, NuGet and dotnet treat XML element, attribute and property names // case-insensitively, but xml2js preserves the case it reads. These helpers // match names ourselves. An exact-case match always wins over a differently // cased spelling of the same name. Object.defineProperty(exports, "__esModule", { value: true }); exports.getAll = exports.getAttr = exports.getCaseInsensitive = exports.hasKey = exports.findKey = void 0; function findKey(obj, key) { if (obj === null || typeof obj !== 'object') { return undefined; } if (Object.prototype.hasOwnProperty.call(obj, key)) { return key; } const lower = key.toLowerCase(); return Object.keys(obj).find((k) => k.toLowerCase() === lower); } exports.findKey = findKey; function hasKey(obj, key) { return findKey(obj, key) !== undefined; } exports.hasKey = hasKey; function getCaseInsensitive(obj, key) { const found = findKey(obj, key); return found === undefined ? undefined : obj[found]; } exports.getCaseInsensitive = getCaseInsensitive; // Attribute lookup on an xml2js node, i.e. the `$` object. function getAttr(node, name) { return getCaseInsensitive(node === null || node === void 0 ? void 0 : node.$, name); } exports.getAttr = getAttr; // Child elements of one name. xml2js keys children by their exact spelling, so // <ItemGroup> and <itemgroup> siblings land under separate keys; merge them. function getAll(obj, key) { if (obj === null || typeof obj !== 'object') { return []; } const lower = key.toLowerCase(); const exact = Object.prototype.hasOwnProperty.call(obj, key) ? [key] : []; const others = Object.keys(obj).filter((k) => k !== key && k.toLowerCase() === lower); return [...exact, ...others].reduce((all, k) => { var _a; return all.concat((_a = obj[k]) !== null && _a !== void 0 ? _a : []); }, []); } exports.getAll = getAll; //# sourceMappingURL=case-insensitive.js.map