twing
Version:
First-class Twig engine for Node.js
32 lines (31 loc) • 799 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.iterableToMap = exports.iteratorToMap = void 0;
/**
* Converts input to Map.
*
* @param {*} thing
* @returns {Map<any, any>}
*/
const iteratorToMap = (thing) => {
if (thing.entries) {
return new Map(thing.entries());
}
else {
const result = new Map();
if (typeof thing[Symbol.iterator] === 'function') {
let i = 0;
for (const value of thing) {
result.set(i++, value);
}
}
else {
for (const key in thing) {
result.set(key, thing[key]);
}
}
return result;
}
};
exports.iteratorToMap = iteratorToMap;
exports.iterableToMap = exports.iteratorToMap;