@daiso-tech/core
Version:
The library offers flexible, framework-agnostic solutions for modern web applications, built on adaptable components that integrate seamlessly with popular frameworks like Next Js.
78 lines • 2.52 kB
JavaScript
/**
* @module Collection
*/
import { CORE, resolveOneOrMore, } from "../../utilities/_module-exports.js";
import { IterableCollection, ListCollection, } from "../../collection/implementations/_module-exports.js";
/**
* @internal
*/
class RangeIterable {
from;
to;
constructor(from, to) {
this.from = from;
this.to = to;
}
*[Symbol.iterator]() {
for (let i = this.from; i <= this.to; i++) {
yield i;
}
}
}
/**
* The `range` function return a {@link Iterable | `Iterable`} of numbers, starting from `from`,increments by 1 and stops at `to`.
* @example
* ```ts
* import { ListCollection, range } from "@daiso-tech/core/collection";
*
* const collection = new ListCollection(range(1, 10))
* collection.toArray();
* // [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
* ```
*
* IMPORT_PATH: `"@daiso-tech/core/collection"`
* @group Utilities
*/
export function range(from, to) {
return new RangeIterable(from, to);
}
/**
* The `isIterable` returns true if the value is {@link Iterable | `Iterable`}.
*
* IMPORT_PATH: `"@daiso-tech/core/collection"`
* @group Utilities
*/
export function isIterable(
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
value) {
return (typeof value === "object" &&
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
typeof value[Symbol.iterator] === "function");
}
/**
* The `isAsyncIterable` returns true if the value is {@link AsyncIterable | `AsyncIterable`}.
*
* IMPORT_PATH: `"@daiso-tech/core/collection"`
* @group Utilities
*/
export function isAsyncIterable(
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
value) {
return (typeof value === "object" &&
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
typeof value[Symbol.asyncIterator] === "function");
}
/**
* The `registerCollectionsToSerde` function registers the `ListCollection` and `IterableCollection` classes with `ISerderRegister`, ensuring they will properly be serialized and deserialized.
*
* IMPORT_PATH: `"@daiso-tech/core/collection"`
* @group Utilities
*/
export function registerCollectionsToSerde(serde) {
for (const serde_ of resolveOneOrMore(serde)) {
serde_
.registerClass(ListCollection, CORE)
.registerClass(IterableCollection, CORE);
}
}
//# sourceMappingURL=_shared.js.map