| { | ||
| "version": 3, | ||
| "sources": ["../src/index.ts", "../../it-all/src/index.ts"], | ||
| "sourcesContent": ["/**\n * @packageDocumentation\n *\n * Consumes all values from an (async)iterable and returns them sorted by the passed sort function.\n *\n * @example\n *\n * ```javascript\n * import sort from 'it-sort'\n * import all from 'it-all'\n *\n * const sorter = (a, b) => {\n * return a.localeCompare(b)\n * }\n *\n * // This can also be an iterator, generator, etc\n * const values = ['foo', 'bar']\n *\n * const arr = all(sort(values, sorter))\n *\n * console.info(arr) // 'bar', 'foo'\n * ```\n *\n * Async sources must be awaited:\n *\n * ```javascript\n * import sort from 'it-sort'\n * import all from 'it-all'\n *\n * const sorter = (a, b) => {\n * return a.localeCompare(b)\n * }\n *\n * const values = async function * () {\n * yield * ['foo', 'bar']\n * }\n *\n * const arr = await all(sort(values, sorter))\n *\n * console.info(arr) // 'bar', 'foo'\n * ```\n */\n\nimport all from 'it-all'\n\nfunction isAsyncIterable <T> (thing: any): thing is AsyncIterable<T> {\n return thing[Symbol.asyncIterator] != null\n}\n\nexport interface CompareFunction<T> {\n (a: T, b: T): number\n}\n\n/**\n * Collects all values from an async iterator, sorts them\n * using the passed function and yields them\n */\nfunction sort <T> (source: Iterable<T>, sorter: CompareFunction<T>): Generator<T, void, undefined>\nfunction sort <T> (source: Iterable<T> | AsyncIterable<T>, sorter: CompareFunction<T>): AsyncGenerator<T, void, undefined>\nfunction sort <T> (source: Iterable<T> | AsyncIterable<T>, sorter: CompareFunction<T>): AsyncGenerator<T, void, undefined> | Generator<T, void, undefined> {\n if (isAsyncIterable(source)) {\n return (async function * () {\n const arr = await all(source)\n\n yield * arr.sort(sorter)\n })()\n }\n\n return (function * () {\n const arr = all(source)\n\n yield * arr.sort(sorter)\n })()\n}\n\nexport default sort\n", "/**\n * @packageDocumentation\n *\n * For when you need a one-liner to collect iterable values.\n *\n * @example\n *\n * ```javascript\n * import all from 'it-all'\n *\n * // This can also be an iterator, etc\n * const values = function * () {\n * yield * [0, 1, 2, 3, 4]\n * }\n *\n * const arr = all(values)\n *\n * console.info(arr) // 0, 1, 2, 3, 4\n * ```\n *\n * Async sources must be awaited:\n *\n * ```javascript\n * const values = async function * () {\n * yield * [0, 1, 2, 3, 4]\n * }\n *\n * const arr = await all(values())\n *\n * console.info(arr) // 0, 1, 2, 3, 4\n * ```\n */\n\nfunction isAsyncIterable <T> (thing: any): thing is AsyncIterable<T> {\n return thing[Symbol.asyncIterator] != null\n}\n\n/**\n * Collects all values from an (async) iterable and returns them as an array\n */\nfunction all <T> (source: Iterable<T>): T[]\nfunction all <T> (source: Iterable<T> | AsyncIterable<T>): Promise<T[]>\nfunction all <T> (source: Iterable<T> | AsyncIterable<T>): Promise<T[]> | T[] {\n if (isAsyncIterable(source)) {\n return (async () => {\n const arr = []\n\n for await (const entry of source) {\n arr.push(entry)\n }\n\n return arr\n })()\n }\n\n const arr = []\n\n for (const entry of source) {\n arr.push(entry)\n }\n\n return arr\n}\n\nexport default all\n"], | ||
| "mappings": ";0bAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,ICiCA,SAASC,EAAqBC,EAAU,CACtC,OAAOA,EAAM,OAAO,aAAa,GAAK,IACxC,CAOA,SAASC,EAASC,EAAsC,CACtD,GAAIH,EAAgBG,CAAM,EACxB,OAAQ,SAAW,CACjB,IAAMC,EAAM,CAAA,EAEZ,cAAiBC,KAASF,EACxBC,EAAI,KAAKC,CAAK,EAGhB,OAAOD,CACT,GAAE,EAGJ,IAAMA,EAAM,CAAA,EAEZ,QAAWC,KAASF,EAClBC,EAAI,KAAKC,CAAK,EAGhB,OAAOD,CACT,CAEA,IAAAE,EAAeJ,EDnBf,SAASK,EAAqBC,EAAU,CACtC,OAAOA,EAAM,OAAO,aAAa,GAAK,IACxC,CAYA,SAASC,EAAUC,EAAwCC,EAA0B,CACnF,OAAIJ,EAAgBG,CAAM,EAChB,iBAAgB,CAGtB,OAFY,MAAME,EAAIF,CAAM,GAEhB,KAAKC,CAAM,CACzB,EAAE,EAGI,WAAU,CAGhB,MAFYC,EAAIF,CAAM,EAEV,KAAKC,CAAM,CACzB,EAAE,CACJ,CAEA,IAAAE,EAAeJ", | ||
| "names": ["index_exports", "__export", "index_default", "isAsyncIterable", "thing", "all", "source", "arr", "entry", "src_default", "isAsyncIterable", "thing", "sort", "source", "sorter", "src_default", "index_default"] | ||
| } |
| (function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.ItSort = factory()}(typeof self !== 'undefined' ? self : this, function () { | ||
| "use strict";var ItSort=(()=>{var e=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var i=Object.getOwnPropertyNames;var u=Object.prototype.hasOwnProperty;var c=(r,t)=>{for(var n in t)e(r,n,{get:t[n],enumerable:!0})},s=(r,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of i(t))!u.call(r,a)&&a!==n&&e(r,a,{get:()=>t[a],enumerable:!(o=f(t,a))||o.enumerable});return r};var y=r=>s(e({},"__esModule",{value:!0}),r);var h={};c(h,{default:()=>I});function p(r){return r[Symbol.asyncIterator]!=null}function b(r){if(p(r))return(async()=>{let n=[];for await(let o of r)n.push(o);return n})();let t=[];for(let n of r)t.push(n);return t}var l=b;function d(r){return r[Symbol.asyncIterator]!=null}function m(r,t){return d(r)?async function*(){yield*(await l(r)).sort(t)}():function*(){yield*l(r).sort(t)}()}var I=m;return y(h);})(); | ||
| return ItSort})); | ||
| //# sourceMappingURL=index.min.js.map |
+11
-3
| { | ||
| "name": "it-sort", | ||
| "version": "3.0.7", | ||
| "version": "3.0.8", | ||
| "description": "Collects all values from an async iterator, sorts them using the passed function and yields them", | ||
@@ -122,3 +122,11 @@ "author": "Alex Potsides <alex@achingbrain.net>", | ||
| "@semantic-release/github", | ||
| "@semantic-release/git" | ||
| [ | ||
| "@semantic-release/git", | ||
| { | ||
| "assets": [ | ||
| "CHANGELOG.md", | ||
| "package.json" | ||
| ] | ||
| } | ||
| ] | ||
| ] | ||
@@ -143,4 +151,4 @@ }, | ||
| "devDependencies": { | ||
| "aegir": "^45.1.2" | ||
| "aegir": "^46.0.1" | ||
| } | ||
| } |
17111
33.9%9
12.5%186
0.54%