UNPKG

@codibre/fluent-iterable

Version:

Provides LINQ-like fluent api operations for iterables and async iterables (ES2018+).

41 lines (40 loc) 1.57 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.addFluentResolvingMethod = exports.FluentClass = void 0; exports.addFluentMethod = addFluentMethod; exports.addFluentAsyncMethod = addFluentAsyncMethod; const fluent_async_func_1 = require("./fluent-async-func"); const types_internal_1 = require("./types-internal"); const internal_utils_1 = require("./utils/internal-utils"); class FluentClass { constructor(base) { this.base = base; } [Symbol.iterator]() { return this.base[Symbol.iterator](); } get [types_internal_1.orderAssured]() { return this.base[types_internal_1.orderAssured]; } set [types_internal_1.orderAssured](value) { this.base[types_internal_1.orderAssured] = value; } } exports.FluentClass = FluentClass; function addFluentMethod(method, body) { if (FluentClass.prototype.hasOwnProperty(method)) { throw new TypeError(`Prototype already has a method called ${method}`); } FluentClass.prototype[method] = function (...args) { return new FluentClass(body.call(this['base'], ...args)); }; } function addFluentAsyncMethod(method, body) { if (FluentClass.prototype.hasOwnProperty(method)) { throw new TypeError(`Prototype already has a method called ${method}`); } FluentClass.prototype[method] = function (...args) { return (0, fluent_async_func_1.fluentAsync)(body.apply(this['base'], args)); }; } exports.addFluentResolvingMethod = (0, internal_utils_1.addFluentResolvingFactory)(FluentClass);