@codibre/fluent-iterable
Version:
Provides LINQ-like fluent api operations for iterables and async iterables (ES2018+).
29 lines (28 loc) • 868 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.addFactory = addFactory;
exports.addFluentResolvingFactory = addFluentResolvingFactory;
exports.isClassFactory = isClassFactory;
function addFactory(adder, origin) {
return (method) => {
const body = origin[method];
return adder(method, body);
};
}
function addFluentResolvingFactory(FluentClass) {
return (method, body) => {
if (FluentClass.prototype.hasOwnProperty(method)) {
throw new TypeError(`Prototype already has a method called ${method}`);
}
FluentClass.prototype[method] = body;
};
}
function isClassFactory(Class) {
const methodName = `is${Class.name}`;
const result = {
[methodName](value) {
return value instanceof Class;
},
};
return result[methodName];
}