+32
-0
| /** | ||
| * @packageDocumentation | ||
| * | ||
| * Return the first value in an (async)iterable | ||
| * | ||
| * @example | ||
| * | ||
| * ```javascript | ||
| * import first from 'it-first' | ||
| * | ||
| * // This can also be an iterator, generator, etc | ||
| * const values = [0, 1, 2, 3, 4] | ||
| * | ||
| * const res = first(values) | ||
| * | ||
| * console.info(res) // 0 | ||
| * ``` | ||
| * | ||
| * Async sources must be awaited: | ||
| * | ||
| * ```javascript | ||
| * import first from 'it-first' | ||
| * | ||
| * const values = async function * () { | ||
| * yield * [0, 1, 2, 3, 4] | ||
| * } | ||
| * | ||
| * const res = await first(values()) | ||
| * | ||
| * console.info(res) // 0 | ||
| * ``` | ||
| */ | ||
| /** | ||
| * Returns the first result from an (async) iterable, unless empty, in which | ||
@@ -3,0 +35,0 @@ * case returns `undefined` |
+32
-0
@@ -0,1 +1,33 @@ | ||
| /** | ||
| * @packageDocumentation | ||
| * | ||
| * Return the first value in an (async)iterable | ||
| * | ||
| * @example | ||
| * | ||
| * ```javascript | ||
| * import first from 'it-first' | ||
| * | ||
| * // This can also be an iterator, generator, etc | ||
| * const values = [0, 1, 2, 3, 4] | ||
| * | ||
| * const res = first(values) | ||
| * | ||
| * console.info(res) // 0 | ||
| * ``` | ||
| * | ||
| * Async sources must be awaited: | ||
| * | ||
| * ```javascript | ||
| * import first from 'it-first' | ||
| * | ||
| * const values = async function * () { | ||
| * yield * [0, 1, 2, 3, 4] | ||
| * } | ||
| * | ||
| * const res = await first(values()) | ||
| * | ||
| * console.info(res) // 0 | ||
| * ``` | ||
| */ | ||
| function isAsyncIterable(thing) { | ||
@@ -2,0 +34,0 @@ return thing[Symbol.asyncIterator] != null; |
+3
-2
| { | ||
| "name": "it-first", | ||
| "version": "3.0.3", | ||
| "version": "3.0.4", | ||
| "description": "Returns the first result from an async iterator", | ||
@@ -32,2 +32,3 @@ "author": "Alex Potsides <alex@achingbrain.net>", | ||
| "parserOptions": { | ||
| "project": true, | ||
| "sourceType": "module" | ||
@@ -135,4 +136,4 @@ } | ||
| "devDependencies": { | ||
| "aegir": "^40.0.11" | ||
| "aegir": "^41.1.9" | ||
| } | ||
| } |
+19
-27
@@ -1,3 +0,1 @@ | ||
| # it-first <!-- omit in toc --> | ||
| [](https://codecov.io/gh/achingbrain/it) | ||
@@ -8,28 +6,8 @@ [](https://github.com/achingbrain/it/actions/workflows/js-test-and-release.yml?query=branch%3Amaster) | ||
| ## Table of contents <!-- omit in toc --> | ||
| # About | ||
| - [Install](#install) | ||
| - [Browser `<script>` tag](#browser-script-tag) | ||
| - [Usage](#usage) | ||
| - [License](#license) | ||
| - [Contribution](#contribution) | ||
| Return the first value in an (async)iterable | ||
| ## Install | ||
| ## Example | ||
| ```console | ||
| $ npm i it-first | ||
| ``` | ||
| ### Browser `<script>` tag | ||
| Loading this module through a script tag will make it's exports available as `ItFirst` in the global namespace. | ||
| ```html | ||
| <script src="https://unpkg.com/it-first/dist/index.min.js"></script> | ||
| ``` | ||
| Mostly useful for tests. | ||
| ## Usage | ||
| ```javascript | ||
@@ -60,4 +38,18 @@ import first from 'it-first' | ||
| ## License | ||
| # Install | ||
| ```console | ||
| $ npm i it-first | ||
| ``` | ||
| ## Browser `<script>` tag | ||
| Loading this module through a script tag will make it's exports available as `ItFirst` in the global namespace. | ||
| ```html | ||
| <script src="https://unpkg.com/it-first/dist/index.min.js"></script> | ||
| ``` | ||
| # License | ||
| Licensed under either of | ||
@@ -68,4 +60,4 @@ | ||
| ## Contribution | ||
| # Contribution | ||
| Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions. |
+33
-0
@@ -0,1 +1,34 @@ | ||
| /** | ||
| * @packageDocumentation | ||
| * | ||
| * Return the first value in an (async)iterable | ||
| * | ||
| * @example | ||
| * | ||
| * ```javascript | ||
| * import first from 'it-first' | ||
| * | ||
| * // This can also be an iterator, generator, etc | ||
| * const values = [0, 1, 2, 3, 4] | ||
| * | ||
| * const res = first(values) | ||
| * | ||
| * console.info(res) // 0 | ||
| * ``` | ||
| * | ||
| * Async sources must be awaited: | ||
| * | ||
| * ```javascript | ||
| * import first from 'it-first' | ||
| * | ||
| * const values = async function * () { | ||
| * yield * [0, 1, 2, 3, 4] | ||
| * } | ||
| * | ||
| * const res = await first(values()) | ||
| * | ||
| * console.info(res) // 0 | ||
| * ``` | ||
| */ | ||
| function isAsyncIterable <T> (thing: any): thing is AsyncIterable<T> { | ||
@@ -2,0 +35,0 @@ return thing[Symbol.asyncIterator] != null |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
10264
17.9%150
177.78%61
-11.59%