├── .travis.yml ├── .gitignore ├── docs ├── assets │ ├── fonts │ │ ├── EOT │ │ │ ├── SourceCodePro-Bold.eot │ │ │ └── SourceCodePro-Regular.eot │ │ ├── OTF │ │ │ ├── SourceCodePro-Bold.otf │ │ │ └── SourceCodePro-Regular.otf │ │ ├── TTF │ │ │ ├── SourceCodePro-Bold.ttf │ │ │ └── SourceCodePro-Regular.ttf │ │ ├── WOFF │ │ │ ├── OTF │ │ │ │ ├── SourceCodePro-Bold.otf.woff │ │ │ │ └── SourceCodePro-Regular.otf.woff │ │ │ └── TTF │ │ │ │ ├── SourceCodePro-Bold.ttf.woff │ │ │ │ └── SourceCodePro-Regular.ttf.woff │ │ ├── WOFF2 │ │ │ ├── OTF │ │ │ │ ├── SourceCodePro-Bold.otf.woff2 │ │ │ │ └── SourceCodePro-Regular.otf.woff2 │ │ │ └── TTF │ │ │ │ ├── SourceCodePro-Bold.ttf.woff2 │ │ │ │ └── SourceCodePro-Regular.ttf.woff2 │ │ ├── source-code-pro.css │ │ └── LICENSE.txt │ ├── bass-addons.css │ ├── github.css │ ├── style.css │ ├── site.js │ ├── anchor.js │ └── bass.css └── index.html ├── src ├── util.js └── index.js ├── package.json ├── test └── index.js └── README.md /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - stable 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /dist 2 | node_modules 3 | npm-debug.log 4 | package-lock.json 5 | .DS_Store 6 | -------------------------------------------------------------------------------- /docs/assets/fonts/EOT/SourceCodePro-Bold.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/developit/asyncro/HEAD/docs/assets/fonts/EOT/SourceCodePro-Bold.eot -------------------------------------------------------------------------------- /docs/assets/fonts/OTF/SourceCodePro-Bold.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/developit/asyncro/HEAD/docs/assets/fonts/OTF/SourceCodePro-Bold.otf -------------------------------------------------------------------------------- /docs/assets/fonts/TTF/SourceCodePro-Bold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/developit/asyncro/HEAD/docs/assets/fonts/TTF/SourceCodePro-Bold.ttf -------------------------------------------------------------------------------- /docs/assets/fonts/EOT/SourceCodePro-Regular.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/developit/asyncro/HEAD/docs/assets/fonts/EOT/SourceCodePro-Regular.eot -------------------------------------------------------------------------------- /docs/assets/fonts/OTF/SourceCodePro-Regular.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/developit/asyncro/HEAD/docs/assets/fonts/OTF/SourceCodePro-Regular.otf -------------------------------------------------------------------------------- /docs/assets/fonts/TTF/SourceCodePro-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/developit/asyncro/HEAD/docs/assets/fonts/TTF/SourceCodePro-Regular.ttf -------------------------------------------------------------------------------- /docs/assets/fonts/WOFF/OTF/SourceCodePro-Bold.otf.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/developit/asyncro/HEAD/docs/assets/fonts/WOFF/OTF/SourceCodePro-Bold.otf.woff -------------------------------------------------------------------------------- /docs/assets/fonts/WOFF/TTF/SourceCodePro-Bold.ttf.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/developit/asyncro/HEAD/docs/assets/fonts/WOFF/TTF/SourceCodePro-Bold.ttf.woff -------------------------------------------------------------------------------- /docs/assets/fonts/WOFF/OTF/SourceCodePro-Regular.otf.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/developit/asyncro/HEAD/docs/assets/fonts/WOFF/OTF/SourceCodePro-Regular.otf.woff -------------------------------------------------------------------------------- /docs/assets/fonts/WOFF/TTF/SourceCodePro-Regular.ttf.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/developit/asyncro/HEAD/docs/assets/fonts/WOFF/TTF/SourceCodePro-Regular.ttf.woff -------------------------------------------------------------------------------- /docs/assets/fonts/WOFF2/OTF/SourceCodePro-Bold.otf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/developit/asyncro/HEAD/docs/assets/fonts/WOFF2/OTF/SourceCodePro-Bold.otf.woff2 -------------------------------------------------------------------------------- /docs/assets/fonts/WOFF2/TTF/SourceCodePro-Bold.ttf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/developit/asyncro/HEAD/docs/assets/fonts/WOFF2/TTF/SourceCodePro-Bold.ttf.woff2 -------------------------------------------------------------------------------- /docs/assets/fonts/WOFF2/OTF/SourceCodePro-Regular.otf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/developit/asyncro/HEAD/docs/assets/fonts/WOFF2/OTF/SourceCodePro-Regular.otf.woff2 -------------------------------------------------------------------------------- /docs/assets/fonts/WOFF2/TTF/SourceCodePro-Regular.ttf.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/developit/asyncro/HEAD/docs/assets/fonts/WOFF2/TTF/SourceCodePro-Regular.ttf.woff2 -------------------------------------------------------------------------------- /docs/assets/bass-addons.css: -------------------------------------------------------------------------------- 1 | .input { 2 | font-family: inherit; 3 | display: block; 4 | width: 100%; 5 | height: 2rem; 6 | padding: .5rem; 7 | margin-bottom: 1rem; 8 | border: 1px solid #ccc; 9 | font-size: .875rem; 10 | border-radius: 3px; 11 | box-sizing: border-box; 12 | } 13 | -------------------------------------------------------------------------------- /docs/assets/fonts/source-code-pro.css: -------------------------------------------------------------------------------- 1 | @font-face{ 2 | font-family: 'Source Code Pro'; 3 | font-weight: 400; 4 | font-style: normal; 5 | font-stretch: normal; 6 | src: url('EOT/SourceCodePro-Regular.eot') format('embedded-opentype'), 7 | url('WOFF2/TTF/SourceCodePro-Regular.ttf.woff2') format('woff2'), 8 | url('WOFF/OTF/SourceCodePro-Regular.otf.woff') format('woff'), 9 | url('OTF/SourceCodePro-Regular.otf') format('opentype'), 10 | url('TTF/SourceCodePro-Regular.ttf') format('truetype'); 11 | } 12 | 13 | @font-face{ 14 | font-family: 'Source Code Pro'; 15 | font-weight: 700; 16 | font-style: normal; 17 | font-stretch: normal; 18 | src: url('EOT/SourceCodePro-Bold.eot') format('embedded-opentype'), 19 | url('WOFF2/TTF/SourceCodePro-Bold.ttf.woff2') format('woff2'), 20 | url('WOFF/OTF/SourceCodePro-Bold.otf.woff') format('woff'), 21 | url('OTF/SourceCodePro-Bold.otf') format('opentype'), 22 | url('TTF/SourceCodePro-Bold.ttf') format('truetype'); 23 | } 24 | -------------------------------------------------------------------------------- /src/util.js: -------------------------------------------------------------------------------- 1 | 2 | /** @private */ 3 | export function map(array, mapper) { 4 | return Promise.all(array.map(mapper)); 5 | } 6 | 7 | /** Invoke a list (object or array) of functions, returning their results in the same structure. 8 | * @private 9 | */ 10 | export function resolve(list) { 11 | let out = Array.isArray(list) ? [] : {}; 12 | for (let i in list) if (list.hasOwnProperty(i)) out[i] = list[i](); 13 | return out; 14 | } 15 | 16 | /** reduce() callback that pushes values into an Array accumulator 17 | * @private 18 | */ 19 | export async function pushReducer(acc, v) { 20 | acc.push(await v()); 21 | return acc; 22 | } 23 | 24 | /** 25 | * Base `map` to invoke `Array` operation **in parallel**. 26 | * @private 27 | * @param {String} operation The operation name of `Array` to be invoked. 28 | * @return {Array} resulting mapped/transformed values. 29 | */ 30 | export function baseMap(operation) { 31 | return async (array, predicate) => { 32 | let mapped = await map(array, predicate); 33 | return array[operation]( (v, i) => mapped[i] ); 34 | }; 35 | } -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "asyncro", 3 | "version": "3.0.0", 4 | "description": "Asynchronous Array Utilities (for await)", 5 | "main": "dist/asyncro.js", 6 | "module": "dist/asyncro.m.js", 7 | "source": "src/index.js", 8 | "scripts": { 9 | "build": "microbundle && npm run -s docs", 10 | "prepublish": "npm run -s build && npm t", 11 | "transpile": "rollup -c rollup.config.js -m ${npm_package_main}.map -f umd -n $npm_package_name $npm_package_jsnext_main -o $npm_package_main", 12 | "docs": "documentation readme src/*.js -q -s API && documentation build src/*.js -f html -o docs", 13 | "test": "eslint src test && npm run -s build && ava --verbose", 14 | "release": "npm run -s build && git commit -am $npm_package_version && git tag $npm_package_version && git push && git push --tags && npm publish" 15 | }, 16 | "eslintConfig": { 17 | "extends": "eslint-config-developit" 18 | }, 19 | "repository": "developit/asyncro", 20 | "keywords": [ 21 | "async", 22 | "await", 23 | "arrays" 24 | ], 25 | "files": [ 26 | "src", 27 | "dist" 28 | ], 29 | "author": "Jason Miller ", 30 | "license": "MIT", 31 | "bugs": { 32 | "url": "https://github.com/developit/asyncro/issues" 33 | }, 34 | "homepage": "https://github.com/developit/asyncro", 35 | "devDependencies": { 36 | "ava": "^0.16.0", 37 | "documentation": "^4.0.0-beta11", 38 | "eslint": "^3.19.0", 39 | "eslint-config-developit": "^1.1.1", 40 | "microbundle": "^0.3.1", 41 | "sinon": "^1.17.6" 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /test/index.js: -------------------------------------------------------------------------------- 1 | import test from 'ava'; 2 | import { spy } from 'sinon'; 3 | import { series, parallel, map, filter, find, every, some } from '../dist/asyncro.js'; 4 | 5 | const get = v => Promise.resolve(v); 6 | 7 | const sleep = time => new Promise( r => setTimeout(r, time) ); 8 | 9 | 10 | test('series', async t => { 11 | t.is(typeof series, 'function'); 12 | 13 | t.deepEqual( 14 | await series([ 15 | async () => await get(1), 16 | async () => await get(2) 17 | ]), 18 | [1, 2] 19 | ); 20 | }); 21 | 22 | 23 | test('parallel', async t => { 24 | t.is(typeof parallel, 'function', 'should be a function'); 25 | 26 | t.deepEqual( 27 | await parallel([ 28 | async () => await get(1), 29 | async () => await get(2) 30 | ]), 31 | [1, 2] 32 | ); 33 | }); 34 | 35 | 36 | test('map', async t => { 37 | t.is(typeof map, 'function'); 38 | 39 | let fn = spy( async value => (await sleep(50), await get(value * 2)) ); 40 | 41 | let start = Date.now(); 42 | 43 | let out = await map([1, 2, 3], fn); 44 | 45 | t.deepEqual(out, [2, 4, 6]); 46 | 47 | let elapsed = Date.now() - start; 48 | 49 | t.true(elapsed < 100, 'Should invoke in parallel'); 50 | }); 51 | 52 | test('baseMap', async t => { 53 | t.is(typeof filter, 'function'); 54 | t.is(typeof find, 'function'); 55 | t.is(typeof every, 'function'); 56 | t.is(typeof some, 'function'); 57 | 58 | let fn = spy( async value => (await sleep(50), await get(value) > 1) ); 59 | 60 | let filterOut = await filter([1, 2, 3], fn); 61 | let findOut = await find([1,2,3], fn); 62 | let everyOut = await every([1, 2, 3], fn); 63 | let someOut = await some([1,2,3], fn); 64 | 65 | t.deepEqual(filterOut, [2, 3]); 66 | t.deepEqual(findOut, 2); 67 | t.false(everyOut); 68 | t.true(someOut); 69 | }); 70 | -------------------------------------------------------------------------------- /docs/assets/github.css: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | github.com style (c) Vasily Polovnyov 4 | 5 | */ 6 | 7 | .hljs { 8 | display: block; 9 | overflow-x: auto; 10 | padding: 0.5em; 11 | color: #333; 12 | background: #f8f8f8; 13 | -webkit-text-size-adjust: none; 14 | } 15 | 16 | .hljs-comment, 17 | .diff .hljs-header, 18 | .hljs-javadoc { 19 | color: #998; 20 | font-style: italic; 21 | } 22 | 23 | .hljs-keyword, 24 | .css .rule .hljs-keyword, 25 | .hljs-winutils, 26 | .nginx .hljs-title, 27 | .hljs-subst, 28 | .hljs-request, 29 | .hljs-status { 30 | color: #1184CE; 31 | } 32 | 33 | .hljs-number, 34 | .hljs-hexcolor, 35 | .ruby .hljs-constant { 36 | color: #ed225d; 37 | } 38 | 39 | .hljs-string, 40 | .hljs-tag .hljs-value, 41 | .hljs-phpdoc, 42 | .hljs-dartdoc, 43 | .tex .hljs-formula { 44 | color: #ed225d; 45 | } 46 | 47 | .hljs-title, 48 | .hljs-id, 49 | .scss .hljs-preprocessor { 50 | color: #900; 51 | font-weight: bold; 52 | } 53 | 54 | .hljs-list .hljs-keyword, 55 | .hljs-subst { 56 | font-weight: normal; 57 | } 58 | 59 | .hljs-class .hljs-title, 60 | .hljs-type, 61 | .vhdl .hljs-literal, 62 | .tex .hljs-command { 63 | color: #458; 64 | font-weight: bold; 65 | } 66 | 67 | .hljs-tag, 68 | .hljs-tag .hljs-title, 69 | .hljs-rules .hljs-property, 70 | .django .hljs-tag .hljs-keyword { 71 | color: #000080; 72 | font-weight: normal; 73 | } 74 | 75 | .hljs-attribute, 76 | .hljs-variable, 77 | .lisp .hljs-body { 78 | color: #008080; 79 | } 80 | 81 | .hljs-regexp { 82 | color: #009926; 83 | } 84 | 85 | .hljs-symbol, 86 | .ruby .hljs-symbol .hljs-string, 87 | .lisp .hljs-keyword, 88 | .clojure .hljs-keyword, 89 | .scheme .hljs-keyword, 90 | .tex .hljs-special, 91 | .hljs-prompt { 92 | color: #990073; 93 | } 94 | 95 | .hljs-built_in { 96 | color: #0086b3; 97 | } 98 | 99 | .hljs-preprocessor, 100 | .hljs-pragma, 101 | .hljs-pi, 102 | .hljs-doctype, 103 | .hljs-shebang, 104 | .hljs-cdata { 105 | color: #999; 106 | font-weight: bold; 107 | } 108 | 109 | .hljs-deletion { 110 | background: #fdd; 111 | } 112 | 113 | .hljs-addition { 114 | background: #dfd; 115 | } 116 | 117 | .diff .hljs-change { 118 | background: #0086b3; 119 | } 120 | 121 | .hljs-chunk { 122 | color: #aaa; 123 | } 124 | -------------------------------------------------------------------------------- /docs/assets/style.css: -------------------------------------------------------------------------------- 1 | .documentation { 2 | font-family: Helvetica, sans-serif; 3 | color: #666; 4 | line-height: 1.5; 5 | background: #f5f5f5; 6 | } 7 | 8 | .black { 9 | color: #666; 10 | } 11 | 12 | .bg-white { 13 | background-color: #fff; 14 | } 15 | 16 | h4 { 17 | margin: 20px 0 10px 0; 18 | } 19 | 20 | .documentation h3 { 21 | color: #000; 22 | } 23 | 24 | .border-bottom { 25 | border-color: #ddd; 26 | } 27 | 28 | a { 29 | color: #1184CE; 30 | text-decoration: none; 31 | } 32 | 33 | .documentation a[href]:hover { 34 | text-decoration: underline; 35 | } 36 | 37 | a:hover { 38 | cursor: pointer; 39 | } 40 | 41 | .py1-ul li { 42 | padding: 5px 0; 43 | } 44 | 45 | .max-height-100 { 46 | max-height: 100%; 47 | } 48 | 49 | section:target h3 { 50 | font-weight:700; 51 | } 52 | 53 | .documentation td, 54 | .documentation th { 55 | padding: .25rem .25rem; 56 | } 57 | 58 | h1:hover .anchorjs-link, 59 | h2:hover .anchorjs-link, 60 | h3:hover .anchorjs-link, 61 | h4:hover .anchorjs-link { 62 | opacity: 1; 63 | } 64 | 65 | .fix-3 { 66 | width: 25%; 67 | max-width: 244px; 68 | } 69 | 70 | .fix-3 { 71 | width: 25%; 72 | max-width: 244px; 73 | } 74 | 75 | @media (min-width: 52em) { 76 | .fix-margin-3 { 77 | margin-left: 25%; 78 | } 79 | } 80 | 81 | .pre, pre, code, .code { 82 | font-family: Source Code Pro,Menlo,Consolas,Liberation Mono,monospace; 83 | font-size: 14px; 84 | } 85 | 86 | .fill-light { 87 | background: #F9F9F9; 88 | } 89 | 90 | .width2 { 91 | width: 1rem; 92 | } 93 | 94 | .input { 95 | font-family: inherit; 96 | display: block; 97 | width: 100%; 98 | height: 2rem; 99 | padding: .5rem; 100 | margin-bottom: 1rem; 101 | border: 1px solid #ccc; 102 | font-size: .875rem; 103 | border-radius: 3px; 104 | box-sizing: border-box; 105 | } 106 | 107 | table { 108 | border-collapse: collapse; 109 | } 110 | 111 | .prose table th, 112 | .prose table td { 113 | text-align: left; 114 | padding:8px; 115 | border:1px solid #ddd; 116 | } 117 | 118 | .prose table th:nth-child(1) { border-right: none; } 119 | .prose table th:nth-child(2) { border-left: none; } 120 | 121 | .prose table { 122 | border:1px solid #ddd; 123 | } 124 | 125 | .prose-big { 126 | font-size: 18px; 127 | line-height: 30px; 128 | } 129 | 130 | .quiet { 131 | opacity: 0.7; 132 | } 133 | 134 | .minishadow { 135 | box-shadow: 2px 2px 10px #f3f3f3; 136 | } 137 | -------------------------------------------------------------------------------- /docs/assets/site.js: -------------------------------------------------------------------------------- 1 | /* global anchors */ 2 | 3 | // add anchor links to headers 4 | anchors.options.placement = 'left'; 5 | anchors.add('h3'); 6 | 7 | // Filter UI 8 | var tocElements = document.getElementById('toc') 9 | .getElementsByTagName('li'); 10 | 11 | document.getElementById('filter-input') 12 | .addEventListener('keyup', function (e) { 13 | 14 | var i, element, children; 15 | 16 | // enter key 17 | if (e.keyCode === 13) { 18 | // go to the first displayed item in the toc 19 | for (i = 0; i < tocElements.length; i++) { 20 | element = tocElements[i]; 21 | if (!element.classList.contains('display-none')) { 22 | location.replace(element.firstChild.href); 23 | return e.preventDefault(); 24 | } 25 | } 26 | } 27 | 28 | var match = function () { 29 | return true; 30 | }; 31 | 32 | var value = this.value.toLowerCase(); 33 | 34 | if (!value.match(/^\s*$/)) { 35 | match = function (element) { 36 | return element.firstChild.innerHTML.toLowerCase().indexOf(value) !== -1; 37 | }; 38 | } 39 | 40 | for (i = 0; i < tocElements.length; i++) { 41 | element = tocElements[i]; 42 | children = Array.from(element.getElementsByTagName('li')); 43 | if (match(element) || children.some(match)) { 44 | element.classList.remove('display-none'); 45 | } else { 46 | element.classList.add('display-none'); 47 | } 48 | } 49 | }); 50 | 51 | var toggles = document.getElementsByClassName('toggle-step-sibling'); 52 | for (var i = 0; i < toggles.length; i++) { 53 | toggles[i].addEventListener('click', toggleStepSibling); 54 | } 55 | 56 | function toggleStepSibling() { 57 | var stepSibling = this.parentNode.parentNode.parentNode.getElementsByClassName('toggle-target')[0]; 58 | var klass = 'display-none'; 59 | if (stepSibling.classList.contains(klass)) { 60 | stepSibling.classList.remove(klass); 61 | stepSibling.innerHTML = '▾'; 62 | } else { 63 | stepSibling.classList.add(klass); 64 | stepSibling.innerHTML = '▸'; 65 | } 66 | } 67 | 68 | var items = document.getElementsByClassName('toggle-sibling'); 69 | for (var j = 0; j < items.length; j++) { 70 | items[j].addEventListener('click', toggleSibling); 71 | } 72 | 73 | function toggleSibling() { 74 | var stepSibling = this.parentNode.getElementsByClassName('toggle-target')[0]; 75 | var icon = this.getElementsByClassName('icon')[0]; 76 | var klass = 'display-none'; 77 | if (stepSibling.classList.contains(klass)) { 78 | stepSibling.classList.remove(klass); 79 | icon.innerHTML = '▾'; 80 | } else { 81 | stepSibling.classList.add(klass); 82 | icon.innerHTML = '▸'; 83 | } 84 | } 85 | 86 | function showHashTarget(targetId) { 87 | var hashTarget = document.getElementById(targetId); 88 | // new target is hidden 89 | if (hashTarget && hashTarget.offsetHeight === 0 && 90 | hashTarget.parentNode.parentNode.classList.contains('display-none')) { 91 | hashTarget.parentNode.parentNode.classList.remove('display-none'); 92 | } 93 | } 94 | 95 | window.addEventListener('hashchange', function() { 96 | showHashTarget(location.hash.substring(1)); 97 | }); 98 | 99 | showHashTarget(location.hash.substring(1)); 100 | 101 | var toclinks = document.getElementsByClassName('pre-open'); 102 | for (var k = 0; k < toclinks.length; k++) { 103 | toclinks[k].addEventListener('mousedown', preOpen, false); 104 | } 105 | 106 | function preOpen() { 107 | showHashTarget(this.hash.substring(1)); 108 | } 109 | -------------------------------------------------------------------------------- /docs/assets/fonts/LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright 2010, 2012 Adobe Systems Incorporated (http://www.adobe.com/), with Reserved Font Name 'Source'. All Rights Reserved. Source is a trademark of Adobe Systems Incorporated in the United States and/or other countries. 2 | 3 | This Font Software is licensed under the SIL Open Font License, Version 1.1. 4 | 5 | This license is copied below, and is also available with a FAQ at: http://scripts.sil.org/OFL 6 | 7 | 8 | ----------------------------------------------------------- 9 | SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 10 | ----------------------------------------------------------- 11 | 12 | PREAMBLE 13 | The goals of the Open Font License (OFL) are to stimulate worldwide 14 | development of collaborative font projects, to support the font creation 15 | efforts of academic and linguistic communities, and to provide a free and 16 | open framework in which fonts may be shared and improved in partnership 17 | with others. 18 | 19 | The OFL allows the licensed fonts to be used, studied, modified and 20 | redistributed freely as long as they are not sold by themselves. The 21 | fonts, including any derivative works, can be bundled, embedded, 22 | redistributed and/or sold with any software provided that any reserved 23 | names are not used by derivative works. The fonts and derivatives, 24 | however, cannot be released under any other type of license. The 25 | requirement for fonts to remain under this license does not apply 26 | to any document created using the fonts or their derivatives. 27 | 28 | DEFINITIONS 29 | "Font Software" refers to the set of files released by the Copyright 30 | Holder(s) under this license and clearly marked as such. This may 31 | include source files, build scripts and documentation. 32 | 33 | "Reserved Font Name" refers to any names specified as such after the 34 | copyright statement(s). 35 | 36 | "Original Version" refers to the collection of Font Software components as 37 | distributed by the Copyright Holder(s). 38 | 39 | "Modified Version" refers to any derivative made by adding to, deleting, 40 | or substituting -- in part or in whole -- any of the components of the 41 | Original Version, by changing formats or by porting the Font Software to a 42 | new environment. 43 | 44 | "Author" refers to any designer, engineer, programmer, technical 45 | writer or other person who contributed to the Font Software. 46 | 47 | PERMISSION & CONDITIONS 48 | Permission is hereby granted, free of charge, to any person obtaining 49 | a copy of the Font Software, to use, study, copy, merge, embed, modify, 50 | redistribute, and sell modified and unmodified copies of the Font 51 | Software, subject to the following conditions: 52 | 53 | 1) Neither the Font Software nor any of its individual components, 54 | in Original or Modified Versions, may be sold by itself. 55 | 56 | 2) Original or Modified Versions of the Font Software may be bundled, 57 | redistributed and/or sold with any software, provided that each copy 58 | contains the above copyright notice and this license. These can be 59 | included either as stand-alone text files, human-readable headers or 60 | in the appropriate machine-readable metadata fields within text or 61 | binary files as long as those fields can be easily viewed by the user. 62 | 63 | 3) No Modified Version of the Font Software may use the Reserved Font 64 | Name(s) unless explicit written permission is granted by the corresponding 65 | Copyright Holder. This restriction only applies to the primary font name as 66 | presented to the users. 67 | 68 | 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font 69 | Software shall not be used to promote, endorse or advertise any 70 | Modified Version, except to acknowledge the contribution(s) of the 71 | Copyright Holder(s) and the Author(s) or with their explicit written 72 | permission. 73 | 74 | 5) The Font Software, modified or unmodified, in part or in whole, 75 | must be distributed entirely under this license, and must not be 76 | distributed under any other license. The requirement for fonts to 77 | remain under this license does not apply to any document created 78 | using the Font Software. 79 | 80 | TERMINATION 81 | This license becomes null and void if any of the above conditions are 82 | not met. 83 | 84 | DISCLAIMER 85 | THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 86 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF 87 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT 88 | OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE 89 | COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 90 | INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL 91 | DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 92 | FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM 93 | OTHER DEALINGS IN THE FONT SOFTWARE. 94 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import { resolve, pushReducer, map, baseMap } from './util'; 2 | 3 | 4 | /** Invoke an async reducer function on each item in the given Array, 5 | * where the reducer transforms an accumulator value based on each item iterated over. 6 | * **Note:** because `reduce()` is order-sensitive, iteration is sequential. 7 | * 8 | * > This is an asynchronous version of `Array.prototype.reduce()` 9 | * 10 | * @param {Array} array The Array to reduce 11 | * @param {Function} reducer Async function, gets passed `(accumulator, value, index, array)` and returns a new value for `accumulator` 12 | * @param {*} [accumulator] Optional initial accumulator value 13 | * @returns final `accumulator` value 14 | * 15 | * @example 16 | * await reduce( 17 | * ['/foo', '/bar', '/baz'], 18 | * async (accumulator, value) => { 19 | * accumulator[v] = await fetch(value); 20 | * return accumulator; 21 | * }, 22 | * {} 23 | * ); 24 | */ 25 | export async function reduce(array, reducer, accumulator) { 26 | for (let i=0; i This is an asynchronous, parallelized version of `Array.prototype.map()`. 37 | * 38 | * @function 39 | * @name map 40 | * @param {Array} array The Array to map over 41 | * @param {Function} mapper Async function, gets passed `(value, index, array)`, returns the new value. 42 | * @returns {Array} resulting mapped/transformed values. 43 | * 44 | * @example 45 | * await map( 46 | * ['foo', 'baz'], 47 | * async v => await fetch(v) 48 | * ) 49 | */ 50 | export { map }; 51 | 52 | 53 | /** Invoke an async filter function on each item in the given Array **in parallel**, 54 | * returning an Array of values for which the filter function returned a truthy value. 55 | * 56 | * > This is an asynchronous, parallelized version of `Array.prototype.filter()`. 57 | * 58 | * @param {Array} array The Array to filter 59 | * @param {Function} filterer Async function. Gets passed `(value, index, array)`, returns true to keep the value in the resulting filtered Array. 60 | * @returns {Array} resulting filtered values 61 | * 62 | * @example 63 | * await filter( 64 | * ['foo', 'baz'], 65 | * async v => (await fetch(v)).ok 66 | * ) 67 | */ 68 | export const filter = baseMap('filter'); 69 | 70 | 71 | /** Invoke an async function on each item in the given Array **in parallel**, 72 | * returning the first element predicate returns truthy for. 73 | * 74 | * > This is an asynchronous, parallelized version of `Array.prototype.find()`. 75 | * 76 | * @param {Array} array The Array to find 77 | * @param {Function} predicate Async function. Gets passed `(value, index, array)`, returns true to be the find result. 78 | * @returns {*} resulting find value 79 | * 80 | * @example 81 | * await find( 82 | * ['foo', 'baz', 'root'], 83 | * async v => (await fetch(v)).name === 'baz' 84 | * ) 85 | */ 86 | export const find = baseMap('find'); 87 | 88 | 89 | /** Checks if predicate returns truthy for **all** elements of collection **in parallel**. 90 | * 91 | * > This is an asynchronous, parallelized version of `Array.prototype.every()`. 92 | * 93 | * @param {Array} array The Array to iterate over. 94 | * @param {Function} predicate Async function. Gets passed `(value, index, array)`, The function invoked per iteration. 95 | * @returns {Boolean} Returns true if **all** element passes the predicate check, else false. 96 | * 97 | * @example 98 | * await every( 99 | * [2, 3], 100 | * async v => (await fetch(v)).ok 101 | * ) 102 | */ 103 | export const every = baseMap('every'); 104 | 105 | 106 | /** Checks if predicate returns truthy for **any** element of collection **in parallel**. 107 | * 108 | * > This is an asynchronous, parallelized version of `Array.prototype.some()`. 109 | * 110 | * @param {Array} array The Array to iterate over. 111 | * @param {Function} filterer Async function. Gets passed `(value, index, array)`, The function invoked per iteration. 112 | * @returns {Boolean} Returns true if **any** element passes the predicate check, else false. 113 | * 114 | * @example 115 | * await some( 116 | * ['foo', 'baz'], 117 | * async v => (await fetch(v)).ok 118 | * ) 119 | */ 120 | export const some = baseMap('some'); 121 | 122 | 123 | /** Invoke all async functions in an Array or Object **in parallel**, returning the result. 124 | * @param {Array|Object} list Array/Object with values that are async functions to invoke. 125 | * @returns {Array|Object} same structure as `list` input, but with values now resolved. 126 | * 127 | * @example 128 | * await parallel([ 129 | * async () => await fetch('foo'), 130 | * async () => await fetch('baz') 131 | * ]) 132 | */ 133 | export async function parallel(list) { 134 | return await Promise.all(resolve(list)); 135 | } 136 | 137 | 138 | /** Invoke all async functions in an Array or Object **sequentially**, returning the result. 139 | * @param {Array|Object} list Array/Object with values that are async functions to invoke. 140 | * @returns {Array|Object} same structure as `list` input, but with values now resolved. 141 | * 142 | * @example 143 | * await series([ 144 | * async () => await fetch('foo'), 145 | * async () => await fetch('baz') 146 | * ]) 147 | */ 148 | export async function series(list) { 149 | return reduce(list, pushReducer, []); 150 | } 151 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # `asyncro` [![NPM](https://img.shields.io/npm/v/asyncro.svg?style=flat)](https://www.npmjs.org/package/asyncro) [![travis-ci](https://travis-ci.org/developit/asyncro.svg?branch=master)](https://travis-ci.org/developit/asyncro) 2 | 3 | The same `map()`, `reduce()` & `filter()` you know and love, but with async iterator functions! 4 | 5 | Do `fetch()` networking in loops, resolve Promises, anything async goes. Performance-friendly _by default_. 6 | 7 | **Here's what it looks like:** 8 | 9 | Asyncro Example 10 | 11 | * * * 12 | 13 | ## What's in the Box 14 | 15 | Asyncro Example 2 16 | 17 | * * * 18 | 19 | ## Installation 20 | 21 | ```sh 22 | npm install --save asyncro 23 | ``` 24 | 25 | ## Import and Usage Example 26 | 27 | ```js 28 | import { map } from 'asyncro'; 29 | 30 | async function example() { 31 | return await map( 32 | ['foo', 'bar', 'baz'], 33 | async name => fetch('./'+name) 34 | ) 35 | } 36 | ``` 37 | 38 | ## API 39 | 40 | 41 | 42 | ### reduce 43 | 44 | Invoke an async reducer function on each item in the given Array, 45 | where the reducer transforms an accumulator value based on each item iterated over. 46 | **Note:** because `reduce()` is order-sensitive, iteration is sequential. 47 | 48 | > This is an asynchronous version of `Array.prototype.reduce()` 49 | 50 | **Parameters** 51 | 52 | - `array` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)** The Array to reduce 53 | - `reducer` **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** Async function, gets passed `(accumulator, value, index, array)` and returns a new value for `accumulator` 54 | - `accumulator` **\[any]** Optional initial accumulator value 55 | 56 | **Examples** 57 | 58 | ```javascript 59 | await reduce( 60 | ['/foo', '/bar', '/baz'], 61 | async (accumulator, value) => { 62 | accumulator[v] = await fetch(value); 63 | return accumulator; 64 | }, 65 | {} 66 | ); 67 | ``` 68 | 69 | Returns **any** final `accumulator` value 70 | 71 | ### map 72 | 73 | Invoke an async transform function on each item in the given Array **in parallel**, 74 | returning the resulting Array of mapped/transformed items. 75 | 76 | > This is an asynchronous, parallelized version of `Array.prototype.map()`. 77 | 78 | **Parameters** 79 | 80 | - `array` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)** The Array to map over 81 | - `mapper` **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** Async function, gets passed `(value, index, array)`, returns the new value. 82 | 83 | **Examples** 84 | 85 | ```javascript 86 | await map( 87 | ['foo', 'baz'], 88 | async v => await fetch(v) 89 | ) 90 | ``` 91 | 92 | Returns **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)** resulting mapped/transformed values. 93 | 94 | ### filter 95 | 96 | Invoke an async filter function on each item in the given Array **in parallel**, 97 | returning an Array of values for which the filter function returned a truthy value. 98 | 99 | > This is an asynchronous, parallelized version of `Array.prototype.filter()`. 100 | 101 | **Parameters** 102 | 103 | - `array` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)** The Array to filter 104 | - `filterer` **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** Async function. Gets passed `(value, index, array)`, returns true to keep the value in the resulting filtered Array. 105 | 106 | **Examples** 107 | 108 | ```javascript 109 | await filter( 110 | ['foo', 'baz'], 111 | async v => (await fetch(v)).ok 112 | ) 113 | ``` 114 | 115 | Returns **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)** resulting filtered values 116 | 117 | ### find 118 | 119 | Invoke an async function on each item in the given Array **in parallel**, 120 | returning the first element predicate returns truthy for. 121 | 122 | > This is an asynchronous, parallelized version of `Array.prototype.find()`. 123 | 124 | **Parameters** 125 | 126 | - `array` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)** The Array to find 127 | - `predicate` **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** Async function. Gets passed `(value, index, array)`, returns true to be the find result. 128 | 129 | **Examples** 130 | 131 | ```javascript 132 | await find( 133 | ['foo', 'baz', 'root'], 134 | async v => (await fetch(v)).name === 'baz' 135 | ) 136 | ``` 137 | 138 | Returns **any** resulting find value 139 | 140 | ### every 141 | 142 | Checks if predicate returns truthy for **all** elements of collection **in parallel**. 143 | 144 | > This is an asynchronous, parallelized version of `Array.prototype.every()`. 145 | 146 | **Parameters** 147 | 148 | - `array` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)** The Array to iterate over. 149 | - `predicate` **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** Async function. Gets passed `(value, index, array)`, The function invoked per iteration. 150 | 151 | **Examples** 152 | 153 | ```javascript 154 | await every( 155 | [2, 3], 156 | async v => (await fetch(v)).ok 157 | ) 158 | ``` 159 | 160 | Returns **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Returns true if **all** element passes the predicate check, else false. 161 | 162 | ### some 163 | 164 | Checks if predicate returns truthy for **any** element of collection **in parallel**. 165 | 166 | > This is an asynchronous, parallelized version of `Array.prototype.some()`. 167 | 168 | **Parameters** 169 | 170 | - `array` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)** The Array to iterate over. 171 | - `filterer` **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** Async function. Gets passed `(value, index, array)`, The function invoked per iteration. 172 | 173 | **Examples** 174 | 175 | ```javascript 176 | await some( 177 | ['foo', 'baz'], 178 | async v => (await fetch(v)).ok 179 | ) 180 | ``` 181 | 182 | Returns **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Returns true if **any** element passes the predicate check, else false. 183 | 184 | ### parallel 185 | 186 | Invoke all async functions in an Array or Object **in parallel**, returning the result. 187 | 188 | **Parameters** 189 | 190 | - `list` **([Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)<[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)> | [Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)<[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)>)** Array/Object with values that are async functions to invoke. 191 | 192 | **Examples** 193 | 194 | ```javascript 195 | await parallel([ 196 | async () => await fetch('foo'), 197 | async () => await fetch('baz') 198 | ]) 199 | ``` 200 | 201 | Returns **([Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array) \| [Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object))** same structure as `list` input, but with values now resolved. 202 | 203 | ### series 204 | 205 | Invoke all async functions in an Array or Object **sequentially**, returning the result. 206 | 207 | **Parameters** 208 | 209 | - `list` **([Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)<[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)> | [Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)<[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)>)** Array/Object with values that are async functions to invoke. 210 | 211 | **Examples** 212 | 213 | ```javascript 214 | await series([ 215 | async () => await fetch('foo'), 216 | async () => await fetch('baz') 217 | ]) 218 | ``` 219 | 220 | Returns **([Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array) \| [Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object))** same structure as `list` input, but with values now resolved. 221 | 222 | ## License 223 | 224 | [MIT](https://oss.ninja/mit/developit) 225 | -------------------------------------------------------------------------------- /docs/assets/anchor.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * AnchorJS - v1.2.1 - 2015-07-02 3 | * https://github.com/bryanbraun/anchorjs 4 | * Copyright (c) 2015 Bryan Braun; Licensed MIT 5 | */ 6 | 7 | function AnchorJS(options) { 8 | 'use strict'; 9 | 10 | this.options = options || {}; 11 | 12 | this._applyRemainingDefaultOptions = function(opts) { 13 | this.options.icon = this.options.hasOwnProperty('icon') ? opts.icon : '\ue9cb'; // Accepts characters (and also URLs?), like '#', '¶', '❡', or '§'. 14 | this.options.visible = this.options.hasOwnProperty('visible') ? opts.visible : 'hover'; // Also accepts 'always' 15 | this.options.placement = this.options.hasOwnProperty('placement') ? opts.placement : 'right'; // Also accepts 'left' 16 | this.options.class = this.options.hasOwnProperty('class') ? opts.class : ''; // Accepts any class name. 17 | }; 18 | 19 | this._applyRemainingDefaultOptions(options); 20 | 21 | this.add = function(selector) { 22 | var elements, 23 | elsWithIds, 24 | idList, 25 | elementID, 26 | i, 27 | roughText, 28 | tidyText, 29 | index, 30 | count, 31 | newTidyText, 32 | readableID, 33 | anchor; 34 | 35 | this._applyRemainingDefaultOptions(this.options); 36 | 37 | // Provide a sensible default selector, if none is given. 38 | if (!selector) { 39 | selector = 'h1, h2, h3, h4, h5, h6'; 40 | } else if (typeof selector !== 'string') { 41 | throw new Error('The selector provided to AnchorJS was invalid.'); 42 | } 43 | 44 | elements = document.querySelectorAll(selector); 45 | if (elements.length === 0) { 46 | return false; 47 | } 48 | 49 | this._addBaselineStyles(); 50 | 51 | // We produce a list of existing IDs so we don't generate a duplicate. 52 | elsWithIds = document.querySelectorAll('[id]'); 53 | idList = [].map.call(elsWithIds, function assign(el) { 54 | return el.id; 55 | }); 56 | 57 | for (i = 0; i < elements.length; i++) { 58 | 59 | if (elements[i].hasAttribute('id')) { 60 | elementID = elements[i].getAttribute('id'); 61 | } else { 62 | roughText = elements[i].textContent; 63 | 64 | // Refine it so it makes a good ID. Strip out non-safe characters, replace 65 | // spaces with hyphens, truncate to 32 characters, and make toLowerCase. 66 | // 67 | // Example string: // '⚡⚡⚡ Unicode icons are cool--but they definitely don't belong in a URL fragment.' 68 | tidyText = roughText.replace(/[^\w\s-]/gi, '') // ' Unicode icons are cool--but they definitely dont belong in a URL fragment' 69 | .replace(/\s+/g, '-') // '-Unicode-icons-are-cool--but-they-definitely-dont-belong-in-a-URL-fragment' 70 | .replace(/-{2,}/g, '-') // '-Unicode-icons-are-cool-but-they-definitely-dont-belong-in-a-URL-fragment' 71 | .substring(0, 64) // '-Unicode-icons-are-cool-but-they-definitely-dont-belong-in-a-URL' 72 | .replace(/^-+|-+$/gm, '') // 'Unicode-icons-are-cool-but-they-definitely-dont-belong-in-a-URL' 73 | .toLowerCase(); // 'unicode-icons-are-cool-but-they-definitely-dont-belong-in-a-url' 74 | 75 | // Compare our generated ID to existing IDs (and increment it if needed) 76 | // before we add it to the page. 77 | newTidyText = tidyText; 78 | count = 0; 79 | do { 80 | if (index !== undefined) { 81 | newTidyText = tidyText + '-' + count; 82 | } 83 | // .indexOf is supported in IE9+. 84 | index = idList.indexOf(newTidyText); 85 | count += 1; 86 | } while (index !== -1); 87 | index = undefined; 88 | idList.push(newTidyText); 89 | 90 | // Assign it to our element. 91 | // Currently the setAttribute element is only supported in IE9 and above. 92 | elements[i].setAttribute('id', newTidyText); 93 | 94 | elementID = newTidyText; 95 | } 96 | 97 | readableID = elementID.replace(/-/g, ' '); 98 | 99 | // The following code builds the following DOM structure in a more effiecient (albeit opaque) way. 100 | // ''; 101 | anchor = document.createElement('a'); 102 | anchor.className = 'anchorjs-link ' + this.options.class; 103 | anchor.href = '#' + elementID; 104 | anchor.setAttribute('aria-label', 'Anchor link for: ' + readableID); 105 | anchor.setAttribute('data-anchorjs-icon', this.options.icon); 106 | 107 | if (this.options.visible === 'always') { 108 | anchor.style.opacity = '1'; 109 | } 110 | 111 | if (this.options.icon === '\ue9cb') { 112 | anchor.style.fontFamily = 'anchorjs-icons'; 113 | anchor.style.fontStyle = 'normal'; 114 | anchor.style.fontVariant = 'normal'; 115 | anchor.style.fontWeight = 'normal'; 116 | anchor.style.lineHeight = 1; 117 | } 118 | 119 | if (this.options.placement === 'left') { 120 | anchor.style.position = 'absolute'; 121 | anchor.style.marginLeft = '-1em'; 122 | anchor.style.paddingRight = '0.5em'; 123 | elements[i].insertBefore(anchor, elements[i].firstChild); 124 | } else { // if the option provided is `right` (or anything else). 125 | anchor.style.paddingLeft = '0.375em'; 126 | elements[i].appendChild(anchor); 127 | } 128 | } 129 | 130 | return this; 131 | }; 132 | 133 | this.remove = function(selector) { 134 | var domAnchor, 135 | elements = document.querySelectorAll(selector); 136 | for (var i = 0; i < elements.length; i++) { 137 | domAnchor = elements[i].querySelector('.anchorjs-link'); 138 | if (domAnchor) { 139 | elements[i].removeChild(domAnchor); 140 | } 141 | } 142 | return this; 143 | }; 144 | 145 | this._addBaselineStyles = function() { 146 | // We don't want to add global baseline styles if they've been added before. 147 | if (document.head.querySelector('style.anchorjs') !== null) { 148 | return; 149 | } 150 | 151 | var style = document.createElement('style'), 152 | linkRule = 153 | ' .anchorjs-link {' + 154 | ' opacity: 0;' + 155 | ' text-decoration: none;' + 156 | ' -webkit-font-smoothing: antialiased;' + 157 | ' -moz-osx-font-smoothing: grayscale;' + 158 | ' }', 159 | hoverRule = 160 | ' *:hover > .anchorjs-link,' + 161 | ' .anchorjs-link:focus {' + 162 | ' opacity: 1;' + 163 | ' }', 164 | anchorjsLinkFontFace = 165 | ' @font-face {' + 166 | ' font-family: "anchorjs-icons";' + 167 | ' font-style: normal;' + 168 | ' font-weight: normal;' + // Icon from icomoon; 10px wide & 10px tall; 2 empty below & 4 above 169 | ' src: url(data:application/x-font-ttf;charset=utf-8;base64,AAEAAAALAIAAAwAwT1MvMg8SBTUAAAC8AAAAYGNtYXAWi9QdAAABHAAAAFRnYXNwAAAAEAAAAXAAAAAIZ2x5Zgq29TcAAAF4AAABNGhlYWQEZM3pAAACrAAAADZoaGVhBhUDxgAAAuQAAAAkaG10eASAADEAAAMIAAAAFGxvY2EAKACuAAADHAAAAAxtYXhwAAgAVwAAAygAAAAgbmFtZQ5yJ3cAAANIAAAB2nBvc3QAAwAAAAAFJAAAACAAAwJAAZAABQAAApkCzAAAAI8CmQLMAAAB6wAzAQkAAAAAAAAAAAAAAAAAAAABEAAAAAAAAAAAAAAAAAAAAABAAADpywPA/8AAQAPAAEAAAAABAAAAAAAAAAAAAAAgAAAAAAADAAAAAwAAABwAAQADAAAAHAADAAEAAAAcAAQAOAAAAAoACAACAAIAAQAg6cv//f//AAAAAAAg6cv//f//AAH/4xY5AAMAAQAAAAAAAAAAAAAAAQAB//8ADwABAAAAAAAAAAAAAgAANzkBAAAAAAEAAAAAAAAAAAACAAA3OQEAAAAAAQAAAAAAAAAAAAIAADc5AQAAAAACADEARAJTAsAAKwBUAAABIiYnJjQ/AT4BMzIWFxYUDwEGIicmND8BNjQnLgEjIgYPAQYUFxYUBw4BIwciJicmND8BNjIXFhQPAQYUFx4BMzI2PwE2NCcmNDc2MhcWFA8BDgEjARQGDAUtLXoWOR8fORYtLTgKGwoKCjgaGg0gEhIgDXoaGgkJBQwHdR85Fi0tOAobCgoKOBoaDSASEiANehoaCQkKGwotLXoWOR8BMwUFLYEuehYXFxYugC44CQkKGwo4GkoaDQ0NDXoaShoKGwoFBe8XFi6ALjgJCQobCjgaShoNDQ0NehpKGgobCgoKLYEuehYXAAEAAAABAACiToc1Xw889QALBAAAAAAA0XnFFgAAAADRecUWAAAAAAJTAsAAAAAIAAIAAAAAAAAAAQAAA8D/wAAABAAAAAAAAlMAAQAAAAAAAAAAAAAAAAAAAAUAAAAAAAAAAAAAAAACAAAAAoAAMQAAAAAACgAUAB4AmgABAAAABQBVAAIAAAAAAAIAAAAAAAAAAAAAAAAAAAAAAAAADgCuAAEAAAAAAAEADgAAAAEAAAAAAAIABwCfAAEAAAAAAAMADgBLAAEAAAAAAAQADgC0AAEAAAAAAAUACwAqAAEAAAAAAAYADgB1AAEAAAAAAAoAGgDeAAMAAQQJAAEAHAAOAAMAAQQJAAIADgCmAAMAAQQJAAMAHABZAAMAAQQJAAQAHADCAAMAAQQJAAUAFgA1AAMAAQQJAAYAHACDAAMAAQQJAAoANAD4YW5jaG9yanMtaWNvbnMAYQBuAGMAaABvAHIAagBzAC0AaQBjAG8AbgBzVmVyc2lvbiAxLjAAVgBlAHIAcwBpAG8AbgAgADEALgAwYW5jaG9yanMtaWNvbnMAYQBuAGMAaABvAHIAagBzAC0AaQBjAG8AbgBzYW5jaG9yanMtaWNvbnMAYQBuAGMAaABvAHIAagBzAC0AaQBjAG8AbgBzUmVndWxhcgBSAGUAZwB1AGwAYQByYW5jaG9yanMtaWNvbnMAYQBuAGMAaABvAHIAagBzAC0AaQBjAG8AbgBzRm9udCBnZW5lcmF0ZWQgYnkgSWNvTW9vbi4ARgBvAG4AdAAgAGcAZQBuAGUAcgBhAHQAZQBkACAAYgB5ACAASQBjAG8ATQBvAG8AbgAuAAAAAwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==) format("truetype");' + 170 | ' }', 171 | pseudoElContent = 172 | ' [data-anchorjs-icon]::after {' + 173 | ' content: attr(data-anchorjs-icon);' + 174 | ' }', 175 | firstStyleEl; 176 | 177 | style.className = 'anchorjs'; 178 | style.appendChild(document.createTextNode('')); // Necessary for Webkit. 179 | 180 | // We place it in the head with the other style tags, if possible, so as to 181 | // not look out of place. We insert before the others so these styles can be 182 | // overridden if necessary. 183 | firstStyleEl = document.head.querySelector('[rel="stylesheet"], style'); 184 | if (firstStyleEl === undefined) { 185 | document.head.appendChild(style); 186 | } else { 187 | document.head.insertBefore(style, firstStyleEl); 188 | } 189 | 190 | style.sheet.insertRule(linkRule, style.sheet.cssRules.length); 191 | style.sheet.insertRule(hoverRule, style.sheet.cssRules.length); 192 | style.sheet.insertRule(pseudoElContent, style.sheet.cssRules.length); 193 | style.sheet.insertRule(anchorjsLinkFontFace, style.sheet.cssRules.length); 194 | }; 195 | } 196 | 197 | var anchors = new AnchorJS(); 198 | -------------------------------------------------------------------------------- /docs/assets/bass.css: -------------------------------------------------------------------------------- 1 | /*! Basscss | http://basscss.com | MIT License */ 2 | 3 | .h1{ font-size: 2rem } 4 | .h2{ font-size: 1.5rem } 5 | .h3{ font-size: 1.25rem } 6 | .h4{ font-size: 1rem } 7 | .h5{ font-size: .875rem } 8 | .h6{ font-size: .75rem } 9 | 10 | .font-family-inherit{ font-family:inherit } 11 | .font-size-inherit{ font-size:inherit } 12 | .text-decoration-none{ text-decoration:none } 13 | 14 | .bold{ font-weight: bold; font-weight: bold } 15 | .regular{ font-weight:normal } 16 | .italic{ font-style:italic } 17 | .caps{ text-transform:uppercase; letter-spacing: .2em; } 18 | 19 | .left-align{ text-align:left } 20 | .center{ text-align:center } 21 | .right-align{ text-align:right } 22 | .justify{ text-align:justify } 23 | 24 | .nowrap{ white-space:nowrap } 25 | .break-word{ word-wrap:break-word } 26 | 27 | .line-height-1{ line-height: 1 } 28 | .line-height-2{ line-height: 1.125 } 29 | .line-height-3{ line-height: 1.25 } 30 | .line-height-4{ line-height: 1.5 } 31 | 32 | .list-style-none{ list-style:none } 33 | .underline{ text-decoration:underline } 34 | 35 | .truncate{ 36 | max-width:100%; 37 | overflow:hidden; 38 | text-overflow:ellipsis; 39 | white-space:nowrap; 40 | } 41 | 42 | .list-reset{ 43 | list-style:none; 44 | padding-left:0; 45 | } 46 | 47 | .inline{ display:inline } 48 | .block{ display:block } 49 | .inline-block{ display:inline-block } 50 | .table{ display:table } 51 | .table-cell{ display:table-cell } 52 | 53 | .overflow-hidden{ overflow:hidden } 54 | .overflow-scroll{ overflow:scroll } 55 | .overflow-auto{ overflow:auto } 56 | 57 | .clearfix:before, 58 | .clearfix:after{ 59 | content:" "; 60 | display:table 61 | } 62 | .clearfix:after{ clear:both } 63 | 64 | .left{ float:left } 65 | .right{ float:right } 66 | 67 | .fit{ max-width:100% } 68 | 69 | .max-width-1{ max-width: 24rem } 70 | .max-width-2{ max-width: 32rem } 71 | .max-width-3{ max-width: 48rem } 72 | .max-width-4{ max-width: 64rem } 73 | 74 | .border-box{ box-sizing:border-box } 75 | 76 | .align-baseline{ vertical-align:baseline } 77 | .align-top{ vertical-align:top } 78 | .align-middle{ vertical-align:middle } 79 | .align-bottom{ vertical-align:bottom } 80 | 81 | .m0{ margin:0 } 82 | .mt0{ margin-top:0 } 83 | .mr0{ margin-right:0 } 84 | .mb0{ margin-bottom:0 } 85 | .ml0{ margin-left:0 } 86 | .mx0{ margin-left:0; margin-right:0 } 87 | .my0{ margin-top:0; margin-bottom:0 } 88 | 89 | .m1{ margin: .5rem } 90 | .mt1{ margin-top: .5rem } 91 | .mr1{ margin-right: .5rem } 92 | .mb1{ margin-bottom: .5rem } 93 | .ml1{ margin-left: .5rem } 94 | .mx1{ margin-left: .5rem; margin-right: .5rem } 95 | .my1{ margin-top: .5rem; margin-bottom: .5rem } 96 | 97 | .m2{ margin: 1rem } 98 | .mt2{ margin-top: 1rem } 99 | .mr2{ margin-right: 1rem } 100 | .mb2{ margin-bottom: 1rem } 101 | .ml2{ margin-left: 1rem } 102 | .mx2{ margin-left: 1rem; margin-right: 1rem } 103 | .my2{ margin-top: 1rem; margin-bottom: 1rem } 104 | 105 | .m3{ margin: 2rem } 106 | .mt3{ margin-top: 2rem } 107 | .mr3{ margin-right: 2rem } 108 | .mb3{ margin-bottom: 2rem } 109 | .ml3{ margin-left: 2rem } 110 | .mx3{ margin-left: 2rem; margin-right: 2rem } 111 | .my3{ margin-top: 2rem; margin-bottom: 2rem } 112 | 113 | .m4{ margin: 4rem } 114 | .mt4{ margin-top: 4rem } 115 | .mr4{ margin-right: 4rem } 116 | .mb4{ margin-bottom: 4rem } 117 | .ml4{ margin-left: 4rem } 118 | .mx4{ margin-left: 4rem; margin-right: 4rem } 119 | .my4{ margin-top: 4rem; margin-bottom: 4rem } 120 | 121 | .mxn1{ margin-left: -.5rem; margin-right: -.5rem; } 122 | .mxn2{ margin-left: -1rem; margin-right: -1rem; } 123 | .mxn3{ margin-left: -2rem; margin-right: -2rem; } 124 | .mxn4{ margin-left: -4rem; margin-right: -4rem; } 125 | 126 | .ml-auto{ margin-left:auto } 127 | .mr-auto{ margin-right:auto } 128 | .mx-auto{ margin-left:auto; margin-right:auto; } 129 | 130 | .p0{ padding:0 } 131 | .pt0{ padding-top:0 } 132 | .pr0{ padding-right:0 } 133 | .pb0{ padding-bottom:0 } 134 | .pl0{ padding-left:0 } 135 | .px0{ padding-left:0; padding-right:0 } 136 | .py0{ padding-top:0; padding-bottom:0 } 137 | 138 | .p1{ padding: .5rem } 139 | .pt1{ padding-top: .5rem } 140 | .pr1{ padding-right: .5rem } 141 | .pb1{ padding-bottom: .5rem } 142 | .pl1{ padding-left: .5rem } 143 | .py1{ padding-top: .5rem; padding-bottom: .5rem } 144 | .px1{ padding-left: .5rem; padding-right: .5rem } 145 | 146 | .p2{ padding: 1rem } 147 | .pt2{ padding-top: 1rem } 148 | .pr2{ padding-right: 1rem } 149 | .pb2{ padding-bottom: 1rem } 150 | .pl2{ padding-left: 1rem } 151 | .py2{ padding-top: 1rem; padding-bottom: 1rem } 152 | .px2{ padding-left: 1rem; padding-right: 1rem } 153 | 154 | .p3{ padding: 2rem } 155 | .pt3{ padding-top: 2rem } 156 | .pr3{ padding-right: 2rem } 157 | .pb3{ padding-bottom: 2rem } 158 | .pl3{ padding-left: 2rem } 159 | .py3{ padding-top: 2rem; padding-bottom: 2rem } 160 | .px3{ padding-left: 2rem; padding-right: 2rem } 161 | 162 | .p4{ padding: 4rem } 163 | .pt4{ padding-top: 4rem } 164 | .pr4{ padding-right: 4rem } 165 | .pb4{ padding-bottom: 4rem } 166 | .pl4{ padding-left: 4rem } 167 | .py4{ padding-top: 4rem; padding-bottom: 4rem } 168 | .px4{ padding-left: 4rem; padding-right: 4rem } 169 | 170 | .col{ 171 | float:left; 172 | box-sizing:border-box; 173 | } 174 | 175 | .col-right{ 176 | float:right; 177 | box-sizing:border-box; 178 | } 179 | 180 | .col-1{ 181 | width:8.33333%; 182 | } 183 | 184 | .col-2{ 185 | width:16.66667%; 186 | } 187 | 188 | .col-3{ 189 | width:25%; 190 | } 191 | 192 | .col-4{ 193 | width:33.33333%; 194 | } 195 | 196 | .col-5{ 197 | width:41.66667%; 198 | } 199 | 200 | .col-6{ 201 | width:50%; 202 | } 203 | 204 | .col-7{ 205 | width:58.33333%; 206 | } 207 | 208 | .col-8{ 209 | width:66.66667%; 210 | } 211 | 212 | .col-9{ 213 | width:75%; 214 | } 215 | 216 | .col-10{ 217 | width:83.33333%; 218 | } 219 | 220 | .col-11{ 221 | width:91.66667%; 222 | } 223 | 224 | .col-12{ 225 | width:100%; 226 | } 227 | @media (min-width: 40em){ 228 | 229 | .sm-col{ 230 | float:left; 231 | box-sizing:border-box; 232 | } 233 | 234 | .sm-col-right{ 235 | float:right; 236 | box-sizing:border-box; 237 | } 238 | 239 | .sm-col-1{ 240 | width:8.33333%; 241 | } 242 | 243 | .sm-col-2{ 244 | width:16.66667%; 245 | } 246 | 247 | .sm-col-3{ 248 | width:25%; 249 | } 250 | 251 | .sm-col-4{ 252 | width:33.33333%; 253 | } 254 | 255 | .sm-col-5{ 256 | width:41.66667%; 257 | } 258 | 259 | .sm-col-6{ 260 | width:50%; 261 | } 262 | 263 | .sm-col-7{ 264 | width:58.33333%; 265 | } 266 | 267 | .sm-col-8{ 268 | width:66.66667%; 269 | } 270 | 271 | .sm-col-9{ 272 | width:75%; 273 | } 274 | 275 | .sm-col-10{ 276 | width:83.33333%; 277 | } 278 | 279 | .sm-col-11{ 280 | width:91.66667%; 281 | } 282 | 283 | .sm-col-12{ 284 | width:100%; 285 | } 286 | 287 | } 288 | @media (min-width: 52em){ 289 | 290 | .md-col{ 291 | float:left; 292 | box-sizing:border-box; 293 | } 294 | 295 | .md-col-right{ 296 | float:right; 297 | box-sizing:border-box; 298 | } 299 | 300 | .md-col-1{ 301 | width:8.33333%; 302 | } 303 | 304 | .md-col-2{ 305 | width:16.66667%; 306 | } 307 | 308 | .md-col-3{ 309 | width:25%; 310 | } 311 | 312 | .md-col-4{ 313 | width:33.33333%; 314 | } 315 | 316 | .md-col-5{ 317 | width:41.66667%; 318 | } 319 | 320 | .md-col-6{ 321 | width:50%; 322 | } 323 | 324 | .md-col-7{ 325 | width:58.33333%; 326 | } 327 | 328 | .md-col-8{ 329 | width:66.66667%; 330 | } 331 | 332 | .md-col-9{ 333 | width:75%; 334 | } 335 | 336 | .md-col-10{ 337 | width:83.33333%; 338 | } 339 | 340 | .md-col-11{ 341 | width:91.66667%; 342 | } 343 | 344 | .md-col-12{ 345 | width:100%; 346 | } 347 | 348 | } 349 | @media (min-width: 64em){ 350 | 351 | .lg-col{ 352 | float:left; 353 | box-sizing:border-box; 354 | } 355 | 356 | .lg-col-right{ 357 | float:right; 358 | box-sizing:border-box; 359 | } 360 | 361 | .lg-col-1{ 362 | width:8.33333%; 363 | } 364 | 365 | .lg-col-2{ 366 | width:16.66667%; 367 | } 368 | 369 | .lg-col-3{ 370 | width:25%; 371 | } 372 | 373 | .lg-col-4{ 374 | width:33.33333%; 375 | } 376 | 377 | .lg-col-5{ 378 | width:41.66667%; 379 | } 380 | 381 | .lg-col-6{ 382 | width:50%; 383 | } 384 | 385 | .lg-col-7{ 386 | width:58.33333%; 387 | } 388 | 389 | .lg-col-8{ 390 | width:66.66667%; 391 | } 392 | 393 | .lg-col-9{ 394 | width:75%; 395 | } 396 | 397 | .lg-col-10{ 398 | width:83.33333%; 399 | } 400 | 401 | .lg-col-11{ 402 | width:91.66667%; 403 | } 404 | 405 | .lg-col-12{ 406 | width:100%; 407 | } 408 | 409 | } 410 | .flex{ display:-webkit-box; display:-webkit-flex; display:-ms-flexbox; display:flex } 411 | 412 | @media (min-width: 40em){ 413 | .sm-flex{ display:-webkit-box; display:-webkit-flex; display:-ms-flexbox; display:flex } 414 | } 415 | 416 | @media (min-width: 52em){ 417 | .md-flex{ display:-webkit-box; display:-webkit-flex; display:-ms-flexbox; display:flex } 418 | } 419 | 420 | @media (min-width: 64em){ 421 | .lg-flex{ display:-webkit-box; display:-webkit-flex; display:-ms-flexbox; display:flex } 422 | } 423 | 424 | .flex-column{ -webkit-box-orient:vertical; -webkit-box-direction:normal; -webkit-flex-direction:column; -ms-flex-direction:column; flex-direction:column } 425 | .flex-wrap{ -webkit-flex-wrap:wrap; -ms-flex-wrap:wrap; flex-wrap:wrap } 426 | 427 | .items-start{ -webkit-box-align:start; -webkit-align-items:flex-start; -ms-flex-align:start; -ms-grid-row-align:flex-start; align-items:flex-start } 428 | .items-end{ -webkit-box-align:end; -webkit-align-items:flex-end; -ms-flex-align:end; -ms-grid-row-align:flex-end; align-items:flex-end } 429 | .items-center{ -webkit-box-align:center; -webkit-align-items:center; -ms-flex-align:center; -ms-grid-row-align:center; align-items:center } 430 | .items-baseline{ -webkit-box-align:baseline; -webkit-align-items:baseline; -ms-flex-align:baseline; -ms-grid-row-align:baseline; align-items:baseline } 431 | .items-stretch{ -webkit-box-align:stretch; -webkit-align-items:stretch; -ms-flex-align:stretch; -ms-grid-row-align:stretch; align-items:stretch } 432 | 433 | .self-start{ -webkit-align-self:flex-start; -ms-flex-item-align:start; align-self:flex-start } 434 | .self-end{ -webkit-align-self:flex-end; -ms-flex-item-align:end; align-self:flex-end } 435 | .self-center{ -webkit-align-self:center; -ms-flex-item-align:center; align-self:center } 436 | .self-baseline{ -webkit-align-self:baseline; -ms-flex-item-align:baseline; align-self:baseline } 437 | .self-stretch{ -webkit-align-self:stretch; -ms-flex-item-align:stretch; align-self:stretch } 438 | 439 | .justify-start{ -webkit-box-pack:start; -webkit-justify-content:flex-start; -ms-flex-pack:start; justify-content:flex-start } 440 | .justify-end{ -webkit-box-pack:end; -webkit-justify-content:flex-end; -ms-flex-pack:end; justify-content:flex-end } 441 | .justify-center{ -webkit-box-pack:center; -webkit-justify-content:center; -ms-flex-pack:center; justify-content:center } 442 | .justify-between{ -webkit-box-pack:justify; -webkit-justify-content:space-between; -ms-flex-pack:justify; justify-content:space-between } 443 | .justify-around{ -webkit-justify-content:space-around; -ms-flex-pack:distribute; justify-content:space-around } 444 | 445 | .content-start{ -webkit-align-content:flex-start; -ms-flex-line-pack:start; align-content:flex-start } 446 | .content-end{ -webkit-align-content:flex-end; -ms-flex-line-pack:end; align-content:flex-end } 447 | .content-center{ -webkit-align-content:center; -ms-flex-line-pack:center; align-content:center } 448 | .content-between{ -webkit-align-content:space-between; -ms-flex-line-pack:justify; align-content:space-between } 449 | .content-around{ -webkit-align-content:space-around; -ms-flex-line-pack:distribute; align-content:space-around } 450 | .content-stretch{ -webkit-align-content:stretch; -ms-flex-line-pack:stretch; align-content:stretch } 451 | .flex-auto{ 452 | -webkit-box-flex:1; 453 | -webkit-flex:1 1 auto; 454 | -ms-flex:1 1 auto; 455 | flex:1 1 auto; 456 | min-width:0; 457 | min-height:0; 458 | } 459 | .flex-none{ -webkit-box-flex:0; -webkit-flex:none; -ms-flex:none; flex:none } 460 | 461 | .order-0{ -webkit-box-ordinal-group:1; -webkit-order:0; -ms-flex-order:0; order:0 } 462 | .order-1{ -webkit-box-ordinal-group:2; -webkit-order:1; -ms-flex-order:1; order:1 } 463 | .order-2{ -webkit-box-ordinal-group:3; -webkit-order:2; -ms-flex-order:2; order:2 } 464 | .order-3{ -webkit-box-ordinal-group:4; -webkit-order:3; -ms-flex-order:3; order:3 } 465 | .order-last{ -webkit-box-ordinal-group:100000; -webkit-order:99999; -ms-flex-order:99999; order:99999 } 466 | 467 | .relative{ position:relative } 468 | .absolute{ position:absolute } 469 | .fixed{ position:fixed } 470 | 471 | .top-0{ top:0 } 472 | .right-0{ right:0 } 473 | .bottom-0{ bottom:0 } 474 | .left-0{ left:0 } 475 | 476 | .z1{ z-index: 1 } 477 | .z2{ z-index: 2 } 478 | .z3{ z-index: 3 } 479 | .z4{ z-index: 4 } 480 | 481 | .border{ 482 | border-style:solid; 483 | border-width: 1px; 484 | } 485 | 486 | .border-top{ 487 | border-top-style:solid; 488 | border-top-width: 1px; 489 | } 490 | 491 | .border-right{ 492 | border-right-style:solid; 493 | border-right-width: 1px; 494 | } 495 | 496 | .border-bottom{ 497 | border-bottom-style:solid; 498 | border-bottom-width: 1px; 499 | } 500 | 501 | .border-left{ 502 | border-left-style:solid; 503 | border-left-width: 1px; 504 | } 505 | 506 | .border-none{ border:0 } 507 | 508 | .rounded{ border-radius: 3px } 509 | .circle{ border-radius:50% } 510 | 511 | .rounded-top{ border-radius: 3px 3px 0 0 } 512 | .rounded-right{ border-radius: 0 3px 3px 0 } 513 | .rounded-bottom{ border-radius: 0 0 3px 3px } 514 | .rounded-left{ border-radius: 3px 0 0 3px } 515 | 516 | .not-rounded{ border-radius:0 } 517 | 518 | .hide{ 519 | position:absolute !important; 520 | height:1px; 521 | width:1px; 522 | overflow:hidden; 523 | clip:rect(1px, 1px, 1px, 1px); 524 | } 525 | 526 | @media (max-width: 40em){ 527 | .xs-hide{ display:none !important } 528 | } 529 | 530 | @media (min-width: 40em) and (max-width: 52em){ 531 | .sm-hide{ display:none !important } 532 | } 533 | 534 | @media (min-width: 52em) and (max-width: 64em){ 535 | .md-hide{ display:none !important } 536 | } 537 | 538 | @media (min-width: 64em){ 539 | .lg-hide{ display:none !important } 540 | } 541 | 542 | .display-none{ display:none !important } 543 | 544 | -------------------------------------------------------------------------------- /docs/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | | Documentation 6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 |
14 |
15 |
16 |

17 |
18 | 23 |
24 | 107 |
108 | 111 |
112 |
113 |
114 | 115 | 116 |
117 | 118 | 119 |
120 |

121 | reduce 122 |

123 | 124 |
125 | 126 | 127 |

Invoke an async reducer function on each item in the given Array, 128 | where the reducer transforms an accumulator value based on each item iterated over. 129 | Note: because reduce() is order-sensitive, iteration is sequential.

130 |
131 |

This is an asynchronous version of Array.prototype.reduce()

132 |
133 | 134 | 135 |
reduce(array: Array, reducer: Function, accumulator: [any]): any
136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 |
Parameters
147 |
148 | 149 |
150 |
151 | array (Array) The Array to reduce 152 | 153 |
154 | 155 |
156 | 157 |
158 |
159 | reducer (Function) Async function, gets passed 160 | (accumulator, value, index, array) 161 | and returns a new value for 162 | accumulator 163 | 164 |
165 | 166 |
167 | 168 |
169 |
170 | accumulator ([any]) Optional initial accumulator value 171 | 172 |
173 | 174 |
175 | 176 |
177 | 178 | 179 | 180 | 181 | 182 | 183 |
Returns
184 | any: 185 | final 186 | accumulator 187 | value 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 |
Example
197 | 198 | 199 |
await reduce(
200 | 	['/foo', '/bar', '/baz'],
201 | 	async (accumulator, value) => {
202 | 		accumulator[v] = await fetch(value);
203 | 		return accumulator;
204 | 	},
205 | 	{}
206 | );
207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 |
216 | 217 | 218 | 219 | 220 |
221 | 222 | 223 |
224 |

225 | map 226 |

227 | 228 |
229 | 230 | 231 |

Invoke an async transform function on each item in the given Array in parallel, 232 | returning the resulting Array of mapped/transformed items.

233 |
234 |

This is an asynchronous, parallelized version of Array.prototype.map().

235 |
236 | 237 | 238 |
map(array: Array, mapper: Function): Array
239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 |
Parameters
250 |
251 | 252 |
253 |
254 | array (Array) The Array to map over 255 | 256 |
257 | 258 |
259 | 260 |
261 |
262 | mapper (Function) Async function, gets passed 263 | (value, index, array) 264 | , returns the new value. 265 | 266 |
267 | 268 |
269 | 270 |
271 | 272 | 273 | 274 | 275 | 276 | 277 |
Returns
278 | Array: 279 | resulting mapped/transformed values. 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 |
Example
289 | 290 | 291 |
await map(
292 | 	['foo', 'baz'],
293 | 	async v => await fetch(v)
294 | )
295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 |
304 | 305 | 306 | 307 | 308 |
309 | 310 | 311 |
312 |

313 | filter 314 |

315 | 316 |
317 | 318 | 319 |

Invoke an async filter function on each item in the given Array in parallel, 320 | returning an Array of values for which the filter function returned a truthy value.

321 |
322 |

This is an asynchronous, parallelized version of Array.prototype.filter().

323 |
324 | 325 | 326 |
filter
327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 |
Parameters
338 |
339 | 340 |
341 |
342 | array (Array) The Array to filter 343 | 344 |
345 | 346 |
347 | 348 |
349 |
350 | filterer (Function) Async function. Gets passed 351 | (value, index, array) 352 | , returns true to keep the value in the resulting filtered Array. 353 | 354 |
355 | 356 |
357 | 358 |
359 | 360 | 361 | 362 | 363 | 364 | 365 |
Returns
366 | Array: 367 | resulting filtered values 368 | 369 | 370 | 371 | 372 | 373 | 374 | 375 | 376 |
Example
377 | 378 | 379 |
await filter(
380 | 	['foo', 'baz'],
381 | 	async v => (await fetch(v)).ok
382 | )
383 | 384 | 385 | 386 | 387 | 388 | 389 | 390 | 391 |
392 | 393 | 394 | 395 | 396 |
397 | 398 | 399 |
400 |

401 | find 402 |

403 | 404 |
405 | 406 | 407 |

Invoke an async function on each item in the given Array in parallel, 408 | returning the first element predicate returns truthy for.

409 |
410 |

This is an asynchronous, parallelized version of Array.prototype.find().

411 |
412 | 413 | 414 |
find
415 | 416 | 417 | 418 | 419 | 420 | 421 | 422 | 423 | 424 | 425 |
Parameters
426 |
427 | 428 |
429 |
430 | array (Array) The Array to find 431 | 432 |
433 | 434 |
435 | 436 |
437 |
438 | predicate (Function) Async function. Gets passed 439 | (value, index, array) 440 | , returns true to be the find result. 441 | 442 |
443 | 444 |
445 | 446 |
447 | 448 | 449 | 450 | 451 | 452 | 453 |
Returns
454 | any: 455 | resulting find value 456 | 457 | 458 | 459 | 460 | 461 | 462 | 463 | 464 |
Example
465 | 466 | 467 |
await find(
468 | 	['foo', 'baz', 'root'],
469 | 	async v => (await fetch(v)).name === 'baz'
470 | )
471 | 472 | 473 | 474 | 475 | 476 | 477 | 478 | 479 |
480 | 481 | 482 | 483 | 484 |
485 | 486 | 487 |
488 |

489 | every 490 |

491 | 492 |
493 | 494 | 495 |

Checks if predicate returns truthy for all elements of collection in parallel.

496 |
497 |

This is an asynchronous, parallelized version of Array.prototype.every().

498 |
499 | 500 | 501 |
every
502 | 503 | 504 | 505 | 506 | 507 | 508 | 509 | 510 | 511 | 512 |
Parameters
513 |
514 | 515 |
516 |
517 | array (Array) The Array to iterate over. 518 | 519 |
520 | 521 |
522 | 523 |
524 |
525 | predicate (Function) Async function. Gets passed 526 | (value, index, array) 527 | , The function invoked per iteration. 528 | 529 |
530 | 531 |
532 | 533 |
534 | 535 | 536 | 537 | 538 | 539 | 540 |
Returns
541 | Boolean: 542 | Returns true if 543 | all 544 | element passes the predicate check, else false. 545 | 546 | 547 | 548 | 549 | 550 | 551 | 552 | 553 |
Example
554 | 555 | 556 |
await every(
557 | 	[2, 3],
558 | 	async v => (await fetch(v)).ok
559 | )
560 | 561 | 562 | 563 | 564 | 565 | 566 | 567 | 568 |
569 | 570 | 571 | 572 | 573 |
574 | 575 | 576 |
577 |

578 | some 579 |

580 | 581 |
582 | 583 | 584 |

Checks if predicate returns truthy for any element of collection in parallel.

585 |
586 |

This is an asynchronous, parallelized version of Array.prototype.some().

587 |
588 | 589 | 590 |
some
591 | 592 | 593 | 594 | 595 | 596 | 597 | 598 | 599 | 600 | 601 |
Parameters
602 |
603 | 604 |
605 |
606 | array (Array) The Array to iterate over. 607 | 608 |
609 | 610 |
611 | 612 |
613 |
614 | filterer (Function) Async function. Gets passed 615 | (value, index, array) 616 | , The function invoked per iteration. 617 | 618 |
619 | 620 |
621 | 622 |
623 | 624 | 625 | 626 | 627 | 628 | 629 |
Returns
630 | Boolean: 631 | Returns true if 632 | any 633 | element passes the predicate check, else false. 634 | 635 | 636 | 637 | 638 | 639 | 640 | 641 | 642 |
Example
643 | 644 | 645 |
await some(
646 | 	['foo', 'baz'],
647 | 	async v => (await fetch(v)).ok
648 | )
649 | 650 | 651 | 652 | 653 | 654 | 655 | 656 | 657 |
658 | 659 | 660 | 661 | 662 |
663 | 664 | 665 |
666 |

667 | parallel 668 |

669 | 670 |
671 | 672 | 673 |

Invoke all async functions in an Array or Object in parallel, returning the result.

674 | 675 | 676 |
parallel(list: (Array<Function> | Object<Function>)): (Array | Object)
677 | 678 | 679 | 680 | 681 | 682 | 683 | 684 | 685 | 686 | 687 |
Parameters
688 |
689 | 690 |
691 |
692 | list ((Array<Function> | Object<Function>)) Array/Object with values that are async functions to invoke. 693 | 694 |
695 | 696 |
697 | 698 |
699 | 700 | 701 | 702 | 703 | 704 | 705 |
Returns
706 | (Array | Object): 707 | same structure as 708 | list 709 | input, but with values now resolved. 710 | 711 | 712 | 713 | 714 | 715 | 716 | 717 | 718 |
Example
719 | 720 | 721 |
await parallel([
722 | 	async () => await fetch('foo'),
723 | 	async () => await fetch('baz')
724 | ])
725 | 726 | 727 | 728 | 729 | 730 | 731 | 732 | 733 |
734 | 735 | 736 | 737 | 738 |
739 | 740 | 741 |
742 |

743 | series 744 |

745 | 746 |
747 | 748 | 749 |

Invoke all async functions in an Array or Object sequentially, returning the result.

750 | 751 | 752 |
series(list: (Array<Function> | Object<Function>)): (Array | Object)
753 | 754 | 755 | 756 | 757 | 758 | 759 | 760 | 761 | 762 | 763 |
Parameters
764 |
765 | 766 |
767 |
768 | list ((Array<Function> | Object<Function>)) Array/Object with values that are async functions to invoke. 769 | 770 |
771 | 772 |
773 | 774 |
775 | 776 | 777 | 778 | 779 | 780 | 781 |
Returns
782 | (Array | Object): 783 | same structure as 784 | list 785 | input, but with values now resolved. 786 | 787 | 788 | 789 | 790 | 791 | 792 | 793 | 794 |
Example
795 | 796 | 797 |
await series([
798 | 	async () => await fetch('foo'),
799 | 	async () => await fetch('baz')
800 | ])
801 | 802 | 803 | 804 | 805 | 806 | 807 | 808 | 809 |
810 | 811 | 812 | 813 |
814 |
815 |
816 | 817 | 818 | 819 | 820 | --------------------------------------------------------------------------------