UNPKG

@ibrokethat/factory

Version:
46 lines (29 loc) 1.03 kB
"use strict"; var _require = require('@ibrokethat/iter'); const find = _require.find; const curry = require('@ibrokethat/curry'); module.exports = function factory() { return _factory.apply(undefined, arguments); }; const _factory = curry(function _factory(items, data) { for (var _len = arguments.length, args = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) { args[_key - 2] = arguments[_key]; } if (!(items instanceof Map)) { throw new TypeError(`factory expects ${ items } to be an instance of Map`); } let fn = find(items, function (fn, matcher) { if (typeof matcher !== 'function') { throw new TypeError(`factory expects ${ matcher } to be a function`); } if (matcher.apply(undefined, [data].concat(args))) { return true; } return false; }); if (typeof fn !== 'function') { throw new TypeError(`factory expects ${ fn } to be a function`); } return fn.apply(undefined, [data].concat(args)); }); //# sourceMappingURL=index.js.map