UNPKG

@codibre/fluent-iterable

Version:

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

36 lines (35 loc) 2.26 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.fluentAsync = void 0; exports.fluentEmit = fluentEmit; const mounters_1 = require("./mounters"); const mounters_2 = require("./mounters"); const emitter_1 = require("./emitter"); const fluent_async_func_1 = require("./fluent-async-func"); Object.defineProperty(exports, "fluentAsync", { enumerable: true, get: function () { return fluent_async_func_1.fluentAsync; } }); const fluent_async_class_1 = require("./fluent-async-class"); const internal_utils_1 = require("./utils/internal-utils"); /** * Transforms an EventEmitter into a [[FluentAsyncIterable]]. * * * **IMPORTANT**: the AsyncIterable created from the EventEmitter is always based on a key event which every * emission generates a new yielded result. The default key event is **'data'**. * * Also, the generated AsyncIterable will be infinite unless an ending event is emitted at some point. * The defaults ending events are **'end'** and **'close'**. So, it's important to have in mind this behavior * to use this feature properly. Operations that requires finiteness to be used may fall into an infinite loop. * * If you need to change the key event or other characteristics, you can do it through the **options** parameter * @typeparam T The type of the items in the created FluentAsyncIterable. * @param emitter The EventEmitter * @param options The EventEmitter options. Optional * @returns The [[FluentAsyncIterable]] instance. */ function fluentEmit(emitter, options) { return new fluent_async_class_1.FluentAsyncClass((0, emitter_1.getIterableFromEmitter)(emitter, options)); } Object.keys(mounters_1.asyncIterableFuncs).forEach((0, internal_utils_1.addFactory)(fluent_async_class_1.addAsyncFluentMethod, mounters_1.asyncIterableFuncs)); const mountedSpecial = (0, mounters_2.mountSpecial)(mounters_1.asyncSpecial, fluent_async_func_1.fluentAsync, fluent_async_func_1.fluentAsync); Object.keys(mountedSpecial).forEach((0, internal_utils_1.addFactory)(fluent_async_class_1.addAsyncFluentMethod, mountedSpecial)); Object.keys(mounters_1.asyncResolvingFuncs).forEach((0, internal_utils_1.addFactory)(fluent_async_class_1.addAsyncFluentResolvingMethod, mounters_1.asyncResolvingFuncs));