UNPKG

urns

Version:

An RFC 8141 compliant URN library with some interesting type related functionality

20 lines (19 loc) 853 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.mapFields = void 0; function mapFields(x) { /** Return a function that given an NSS of colon separated strings into an object. */ return function (nss) { /** Start with an empty object */ var ret = {}; /** Split up the NSS into parts */ var parts = nss.split(":"); /** If the number of parts doesn't match the number of field expected, throw an exception */ if (parts.length !== x.length) throw new Error("Expected nss with " + x.length + " segments but got " + nss); /** For each expected field, map the respective string in the NSS into the return object */ x.forEach(function (key, i) { return (ret[key] = parts[i]); }); return ret; }; } exports.mapFields = mapFields;