8 | ├── dist ├── coroutines.js ├── es6 │ ├── is-object.js │ ├── yastjson │ │ └── lib │ │ │ ├── yielder.js │ │ │ ├── expression.js │ │ │ ├── token.js │ │ │ └── parse.js │ ├── concat-async.js │ ├── map-async.js │ ├── append-async.js │ ├── filter-async.js │ ├── index-of-async.js │ ├── find-async.js │ ├── for-each-async.js │ ├── last-index-of-async.js │ ├── call.js │ ├── reduce-async.js │ ├── includes-async.js │ ├── index-of.js │ ├── find-index-async.js │ ├── useInternalEngine.js │ ├── includes.js │ ├── some-async.js │ ├── last-index-of.js │ ├── async-wrapper-utils.js │ ├── key-by-async.js │ ├── group-by-async.js │ ├── unique-by-async.js │ ├── map.js │ ├── every.js │ ├── append.js │ ├── some.js │ ├── async-json-wrappers.js │ ├── branch.js │ ├── tap.js │ ├── async-array-wrappers.js │ ├── concat.js │ ├── find-index.js │ ├── repeat.js │ ├── sort-async.js │ ├── key-by.js │ ├── find.js │ ├── reduce.js │ ├── async-wrappers.js │ ├── group-by.js │ ├── array-utilities.js │ ├── filter.js │ ├── pipe.js │ ├── unique-by.js │ ├── compose.js │ ├── for-each.js │ ├── singleton.js │ ├── coroutines.js │ ├── wrappers.js │ └── update.js ├── yastjson │ └── lib │ │ ├── yielder.js │ │ ├── expression.js │ │ └── token.js ├── sort-async.js ├── append-async.js ├── concat-async.js ├── map-async.js ├── find-async.js ├── some-async.js ├── key-by-async.js ├── async-array-wrappers.js ├── filter-async.js ├── reduce-async.js ├── call.js ├── for-each-async.js ├── group-by-async.js ├── index-of-async.js ├── includes-async.js ├── unique-by-async.js ├── find-index-async.js ├── is-object.js ├── last-index-of-async.js ├── branch.js ├── useInternalEngine.js ├── async-json-wrappers.js ├── singleton.js ├── array-utilities.js ├── async-wrapper-utils.js ├── index-of.js ├── includes.js ├── last-index-of.js ├── append.js ├── key-by.js ├── concat.js ├── tap.js ├── map.js ├── reduce.js ├── some.js ├── every.js ├── find.js ├── repeat.js ├── find-index.js ├── compose.js ├── for-each.js ├── filter.js ├── wrappers.js ├── run.js ├── group-by.js ├── unique-by.js ├── update.js ├── polyfill.js ├── pipe.js ├── async-compression-wrappers.js └── json.js ├── _config.yml ├── .gitattributes ├── public ├── favicon.ico ├── logo192.png ├── logo512.png ├── robots.txt ├── manifest.json └── index.html ├── src ├── component │ ├── is-object.js │ ├── yastjson │ │ └── lib │ │ │ ├── yielder.js │ │ │ ├── expression.js │ │ │ ├── token.js │ │ │ └── parse.js │ ├── concat-async.js │ ├── map-async.js │ ├── append-async.js │ ├── filter-async.js │ ├── index-of-async.js │ ├── find-async.js │ ├── for-each-async.js │ ├── last-index-of-async.js │ ├── call.js │ ├── reduce-async.js │ ├── includes-async.js │ ├── index-of.js │ ├── find-index-async.js │ ├── useInternalEngine.js │ ├── includes.js │ ├── some-async.js │ ├── last-index-of.js │ ├── async-wrapper-utils.js │ ├── key-by-async.js │ ├── group-by-async.js │ ├── unique-by-async.js │ ├── map.js │ ├── every.js │ ├── append.js │ ├── some.js │ ├── async-json-wrappers.js │ ├── branch.js │ ├── tap.js │ ├── async-array-wrappers.js │ ├── concat.js │ ├── find-index.js │ ├── repeat.js │ ├── sort-async.js │ ├── key-by.js │ ├── find.js │ ├── reduce.js │ ├── async-wrappers.js │ ├── group-by.js │ ├── array-utilities.js │ ├── filter.js │ ├── pipe.js │ ├── unique-by.js │ ├── compose.js │ ├── for-each.js │ ├── singleton.js │ ├── coroutines.js │ ├── wrappers.js │ └── update.js ├── setupTests.js ├── App.test.js ├── test │ ├── basic-express.js │ ├── array-async.test.js │ ├── compression.test.js │ ├── sort.test.js │ ├── json.test.js │ └── functional.test.js ├── index.css ├── index.js ├── App.css └── logo.svg ├── .idea ├── .gitignore ├── codeStyles │ └── codeStyleConfig.xml ├── vcs.xml ├── misc.xml ├── inspectionProfiles │ └── Project_Default.xml ├── modules.xml └── js-coroutines.iml ├── template ├── tmpl │ ├── example.tmpl │ ├── source.tmpl │ ├── mainpage.tmpl │ ├── augments.tmpl │ ├── augments-spread.tmpl │ ├── type.tmpl │ ├── type-spread.tmpl │ ├── examples.tmpl │ ├── returns.tmpl │ ├── tutorial.tmpl │ ├── exceptions.tmpl │ ├── members.tmpl │ ├── properties.tmpl │ └── params.tmpl ├── static │ ├── fonts │ │ ├── OpenSans-Bold-webfont.eot │ │ ├── OpenSans-Bold-webfont.woff │ │ ├── OpenSans-Italic-webfont.eot │ │ ├── OpenSans-Light-webfont.eot │ │ ├── OpenSans-Light-webfont.woff │ │ ├── OpenSans-Italic-webfont.woff │ │ ├── OpenSans-Regular-webfont.eot │ │ ├── OpenSans-Regular-webfont.woff │ │ ├── OpenSans-Semibold-webfont.eot │ │ ├── OpenSans-Semibold-webfont.ttf │ │ ├── OpenSans-BoldItalic-webfont.eot │ │ ├── OpenSans-BoldItalic-webfont.woff │ │ ├── OpenSans-LightItalic-webfont.eot │ │ ├── OpenSans-Semibold-webfont.woff │ │ ├── OpenSans-LightItalic-webfont.woff │ │ ├── OpenSans-SemiboldItalic-webfont.eot │ │ ├── OpenSans-SemiboldItalic-webfont.ttf │ │ └── OpenSans-SemiboldItalic-webfont.woff │ ├── icons │ │ ├── home.svg │ │ └── search.svg │ ├── styles │ │ ├── collapse.css │ │ ├── prettify-jsdoc.css │ │ └── prettify-tomorrow.css │ └── scripts │ │ ├── linenumber.js │ │ └── pagelocation.js └── LICENSE ├── docs ├── fonts │ ├── Montserrat │ │ ├── Montserrat-Bold.eot │ │ ├── Montserrat-Bold.ttf │ │ ├── Montserrat-Bold.woff │ │ ├── Montserrat-Bold.woff2 │ │ ├── Montserrat-Regular.eot │ │ ├── Montserrat-Regular.ttf │ │ ├── Montserrat-Regular.woff │ │ └── Montserrat-Regular.woff2 │ └── Source-Sans-Pro │ │ ├── sourcesanspro-light-webfont.eot │ │ ├── sourcesanspro-light-webfont.ttf │ │ ├── sourcesanspro-light-webfont.woff │ │ ├── sourcesanspro-light-webfont.woff2 │ │ ├── sourcesanspro-regular-webfont.eot │ │ ├── sourcesanspro-regular-webfont.ttf │ │ ├── sourcesanspro-regular-webfont.woff │ │ └── sourcesanspro-regular-webfont.woff2 ├── scripts │ ├── polyfill.js │ ├── nav.js │ ├── linenumber.js │ ├── collapse.js │ ├── prettify │ │ └── lang-css.js │ └── search.js └── styles │ └── prettify.css ├── scripts └── build.sh ├── .prettierrc ├── .gitignore ├── .babelrc ├── CONTRIBUTING.md ├── .github └── ISSUE_TEMPLATE │ ├── feature_request.md │ └── bug_report.md ├── mocha.wallaby.js ├── doc.conf.json ├── PULL_REQUEST_TEMPLATE.md └── package.json /dist/coroutines.js: -------------------------------------------------------------------------------- 1 | "use strict"; -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-cayman -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/miketalbot/js-coroutines/HEAD/public/favicon.ico -------------------------------------------------------------------------------- /public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/miketalbot/js-coroutines/HEAD/public/logo192.png -------------------------------------------------------------------------------- /public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/miketalbot/js-coroutines/HEAD/public/logo512.png -------------------------------------------------------------------------------- /public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /dist/es6/is-object.js: -------------------------------------------------------------------------------- 1 | export function isObject(v) { 2 | return typeof v === 'object' && !Array.isArray(v) 3 | } 4 | -------------------------------------------------------------------------------- /src/component/is-object.js: -------------------------------------------------------------------------------- 1 | export function isObject(v) { 2 | return typeof v === 'object' && !Array.isArray(v) 3 | } 4 | -------------------------------------------------------------------------------- /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | # Editor-based HTTP Client requests 5 | /httpRequests/ 6 | -------------------------------------------------------------------------------- /template/tmpl/example.tmpl: -------------------------------------------------------------------------------- 1 | 2 |
3 |
--------------------------------------------------------------------------------
/docs/fonts/Montserrat/Montserrat-Bold.eot:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/miketalbot/js-coroutines/HEAD/docs/fonts/Montserrat/Montserrat-Bold.eot
--------------------------------------------------------------------------------
/docs/fonts/Montserrat/Montserrat-Bold.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/miketalbot/js-coroutines/HEAD/docs/fonts/Montserrat/Montserrat-Bold.ttf
--------------------------------------------------------------------------------
/docs/fonts/Montserrat/Montserrat-Bold.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/miketalbot/js-coroutines/HEAD/docs/fonts/Montserrat/Montserrat-Bold.woff
--------------------------------------------------------------------------------
/docs/fonts/Montserrat/Montserrat-Bold.woff2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/miketalbot/js-coroutines/HEAD/docs/fonts/Montserrat/Montserrat-Bold.woff2
--------------------------------------------------------------------------------
/docs/fonts/Montserrat/Montserrat-Regular.eot:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/miketalbot/js-coroutines/HEAD/docs/fonts/Montserrat/Montserrat-Regular.eot
--------------------------------------------------------------------------------
/docs/fonts/Montserrat/Montserrat-Regular.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/miketalbot/js-coroutines/HEAD/docs/fonts/Montserrat/Montserrat-Regular.ttf
--------------------------------------------------------------------------------
/docs/fonts/Montserrat/Montserrat-Regular.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/miketalbot/js-coroutines/HEAD/docs/fonts/Montserrat/Montserrat-Regular.woff
--------------------------------------------------------------------------------
/docs/fonts/Montserrat/Montserrat-Regular.woff2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/miketalbot/js-coroutines/HEAD/docs/fonts/Montserrat/Montserrat-Regular.woff2
--------------------------------------------------------------------------------
/template/static/fonts/OpenSans-Bold-webfont.eot:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/miketalbot/js-coroutines/HEAD/template/static/fonts/OpenSans-Bold-webfont.eot
--------------------------------------------------------------------------------
/template/static/fonts/OpenSans-Bold-webfont.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/miketalbot/js-coroutines/HEAD/template/static/fonts/OpenSans-Bold-webfont.woff
--------------------------------------------------------------------------------
/template/static/fonts/OpenSans-Italic-webfont.eot:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/miketalbot/js-coroutines/HEAD/template/static/fonts/OpenSans-Italic-webfont.eot
--------------------------------------------------------------------------------
/template/static/fonts/OpenSans-Light-webfont.eot:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/miketalbot/js-coroutines/HEAD/template/static/fonts/OpenSans-Light-webfont.eot
--------------------------------------------------------------------------------
/template/static/fonts/OpenSans-Light-webfont.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/miketalbot/js-coroutines/HEAD/template/static/fonts/OpenSans-Light-webfont.woff
--------------------------------------------------------------------------------
/template/static/fonts/OpenSans-Italic-webfont.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/miketalbot/js-coroutines/HEAD/template/static/fonts/OpenSans-Italic-webfont.woff
--------------------------------------------------------------------------------
/template/static/fonts/OpenSans-Regular-webfont.eot:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/miketalbot/js-coroutines/HEAD/template/static/fonts/OpenSans-Regular-webfont.eot
--------------------------------------------------------------------------------
/template/static/fonts/OpenSans-Regular-webfont.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/miketalbot/js-coroutines/HEAD/template/static/fonts/OpenSans-Regular-webfont.woff
--------------------------------------------------------------------------------
/template/static/fonts/OpenSans-Semibold-webfont.eot:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/miketalbot/js-coroutines/HEAD/template/static/fonts/OpenSans-Semibold-webfont.eot
--------------------------------------------------------------------------------
/template/static/fonts/OpenSans-Semibold-webfont.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/miketalbot/js-coroutines/HEAD/template/static/fonts/OpenSans-Semibold-webfont.ttf
--------------------------------------------------------------------------------
/template/static/fonts/OpenSans-BoldItalic-webfont.eot:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/miketalbot/js-coroutines/HEAD/template/static/fonts/OpenSans-BoldItalic-webfont.eot
--------------------------------------------------------------------------------
/template/static/fonts/OpenSans-BoldItalic-webfont.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/miketalbot/js-coroutines/HEAD/template/static/fonts/OpenSans-BoldItalic-webfont.woff
--------------------------------------------------------------------------------
/template/static/fonts/OpenSans-LightItalic-webfont.eot:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/miketalbot/js-coroutines/HEAD/template/static/fonts/OpenSans-LightItalic-webfont.eot
--------------------------------------------------------------------------------
/template/static/fonts/OpenSans-Semibold-webfont.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/miketalbot/js-coroutines/HEAD/template/static/fonts/OpenSans-Semibold-webfont.woff
--------------------------------------------------------------------------------
/template/static/fonts/OpenSans-LightItalic-webfont.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/miketalbot/js-coroutines/HEAD/template/static/fonts/OpenSans-LightItalic-webfont.woff
--------------------------------------------------------------------------------
/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.eot:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/miketalbot/js-coroutines/HEAD/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.eot
--------------------------------------------------------------------------------
/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/miketalbot/js-coroutines/HEAD/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.ttf
--------------------------------------------------------------------------------
/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/miketalbot/js-coroutines/HEAD/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.woff
--------------------------------------------------------------------------------
/template/static/fonts/OpenSans-SemiboldItalic-webfont.eot:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/miketalbot/js-coroutines/HEAD/template/static/fonts/OpenSans-SemiboldItalic-webfont.eot
--------------------------------------------------------------------------------
/template/static/fonts/OpenSans-SemiboldItalic-webfont.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/miketalbot/js-coroutines/HEAD/template/static/fonts/OpenSans-SemiboldItalic-webfont.ttf
--------------------------------------------------------------------------------
/template/static/fonts/OpenSans-SemiboldItalic-webfont.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/miketalbot/js-coroutines/HEAD/template/static/fonts/OpenSans-SemiboldItalic-webfont.woff
--------------------------------------------------------------------------------
/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.woff2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/miketalbot/js-coroutines/HEAD/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.woff2
--------------------------------------------------------------------------------
/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.eot:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/miketalbot/js-coroutines/HEAD/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.eot
--------------------------------------------------------------------------------
/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/miketalbot/js-coroutines/HEAD/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.ttf
--------------------------------------------------------------------------------
/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/miketalbot/js-coroutines/HEAD/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.woff
--------------------------------------------------------------------------------
/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.woff2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/miketalbot/js-coroutines/HEAD/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.woff2
--------------------------------------------------------------------------------
/.idea/codeStyles/codeStyleConfig.xml:
--------------------------------------------------------------------------------
1 |
8 | 9 | 10 |
11 | 12 | 13 |
14 |
15 |
--------------------------------------------------------------------------------
/dist/es6/map-async.js:
--------------------------------------------------------------------------------
1 | import {wrapAsPromiseAndYieldFn} from './async-wrapper-utils'
2 | import {map} from './map'
3 |
4 | /**
5 | * Maps the contents of an array asynchronously
6 | * @function mapAsync
7 | * @param {Array} array
8 | * @param {Map} mapFn
9 | * @returns {Promise.some operation
6 | * returning a promise for true if at least
7 | * one item matches
8 | * @function someAsync
9 | * @param {Array} array
10 | * @param {Filter} fn
11 | * @returns {Promise.some operation
6 | * returning a promise for true if at least
7 | * one item matches
8 | * @function someAsync
9 | * @param {Array} array
10 | * @param {Filter} fn
11 | * @returns {Promise.array1
10 | * @example
11 | *
12 | * // Updates array1
13 | * yield * append(array1, array2)
14 | */
15 | export function* append(array1, array2) {
16 | const l = array1.length
17 | yield true
18 | array1.length += array2.length
19 | yield
20 | yield* forEach(
21 | array2,
22 | yielding((a, i) => (array1[i + l] = a))
23 | )
24 |
25 | return array1
26 | }
27 |
--------------------------------------------------------------------------------
/src/component/every.js:
--------------------------------------------------------------------------------
1 | import {forEach} from './for-each'
2 | import {exitWith} from './array-utilities'
3 |
4 | /**
5 | * @generator
6 | * @param {Array|Object} collection
7 | * @param {Filter} fn
8 | * @returns {Generator<*, boolean, *>} true if all of the collection items matched the filter
9 | * @example
10 | *
11 | * if(! yield * every(records, yielding(r=>r.valid))) return
12 | */
13 | export function* every(collection, fn) {
14 | let result = true
15 | yield* forEach(collection, function* (value, key) {
16 | if (!(yield* fn(value, key, collection))) {
17 | result = false
18 | return exitWith(false)
19 | }
20 | })
21 | return result
22 | }
23 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/feature_request.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Feature request
3 | about: Suggest an idea for this project
4 | title: ''
5 | labels: ''
6 | assignees: ''
7 |
8 | ---
9 |
10 | **Is your feature request related to a problem? Please describe.**
11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
12 |
13 | **Describe the solution you'd like**
14 | A clear and concise description of what you want to happen.
15 |
16 | **Describe alternatives you've considered**
17 | A clear and concise description of any alternative solutions or features you've considered.
18 |
19 | **Additional context**
20 | Add any other context or screenshots about the feature request here.
21 |
--------------------------------------------------------------------------------
/src/component/append.js:
--------------------------------------------------------------------------------
1 | import {forEach} from './for-each'
2 | import {yielding} from './wrappers'
3 |
4 | /**
5 | * Appends one array to another
6 | * @generator
7 | * @param {Array} array1 - the destination
8 | * @param {Array} array2 - the source
9 | * @returns {Generator<*, Array, *>} returns array1
10 | * @example
11 | *
12 | * // Updates array1
13 | * yield * append(array1, array2)
14 | */
15 | export function* append(array1, array2) {
16 | const l = array1.length
17 | yield true
18 | array1.length += array2.length
19 | yield
20 | yield* forEach(
21 | array2,
22 | yielding((a, i) => (array1[i + l] = a))
23 | )
24 |
25 | return array1
26 | }
27 |
--------------------------------------------------------------------------------
/dist/es6/some.js:
--------------------------------------------------------------------------------
1 | import {forEach} from './for-each'
2 | import {exitWith} from './array-utilities'
3 |
4 | /**
5 | * @generator
6 | * @param {Array|Object} collection
7 | * @param {Filter} fn
8 | * @returns {Generator<*, boolean, *>} true if at least one item matched the filter
9 | * @example
10 | *
11 | *
12 | * if(yield * some(collection, yielding(v=>v > 2000)) {
13 | * ...
14 | * }
15 | */
16 | export function* some(collection, fn) {
17 | let result = false
18 | yield* forEach(collection, function* (value, key) {
19 | if (yield* fn(value, key, collection)) {
20 | result = true
21 | return exitWith(true)
22 | }
23 | })
24 | return result
25 | }
26 |
--------------------------------------------------------------------------------
/dist/es6/async-json-wrappers.js:
--------------------------------------------------------------------------------
1 | import {wrapAsPromise} from './wrappers'
2 | import {parse} from './yastjson/lib/parse'
3 | import {stringify} from './json'
4 |
5 | /**
6 | * Asynchronously stringify data into JSON
7 | * @function
8 | * @name stringifyAsync
9 | * @param {any} data - Object to store
10 | * @returns {Promise.data
11 | */
12 | export const stringifyAsync = wrapAsPromise(stringify)
13 | /**
14 | * Asynchronously parse JSON into an object
15 | * @function parseAsync
16 | * @param {String} json - the JSON to be parsed
17 | * @returns {Promise.data
11 | */
12 | export const stringifyAsync = wrapAsPromise(stringify)
13 | /**
14 | * Asynchronously parse JSON into an object
15 | * @function parseAsync
16 | * @param {String} json - the JSON to be parsed
17 | * @returns {Promise.Sort an array (in place) by a sorting function
6 | *Sorts an array in place asynchronously. This function is a yielding 7 | * implementation of Timsort (standard sort used in modern browsers). Timsort 8 | * is fast and stable making it ideal for multi-key sorts. It it not as fast 9 | * as Quicksort.
10 | * @function sortAsync 11 | * @param {Array} array - The array to sort 12 | * @param {SortFunction|ExtractFunction} sort - The method to sort the array 13 | * @returns {Promise.Sort an array (in place) by a sorting function
6 | *Sorts an array in place asynchronously. This function is a yielding 7 | * implementation of Timsort (standard sort used in modern browsers). Timsort 8 | * is fast and stable making it ideal for multi-key sorts. It it not as fast 9 | * as Quicksort.
10 | * @function sortAsync 11 | * @param {Array} array - The array to sort 12 | * @param {SortFunction|ExtractFunction} sort - The method to sort the array 13 | * @returns {Promise.12 | 13 |
14 | 15 | 16 | 17 |3 | * A coroutine to be run during the gaps in other processing and animation. 4 | *
5 | *
6 | * The coroutine should yield regularly to do a time check. A plain yield will cause
7 | * a check against the standard time remaining specified when running. yield {number} will
8 | * check that number milliseconds are available and yield true will abandon any more
9 | * processing on the current frame.
10 | *
yield will cause the routine to resume at the start
40 | * of the next frame.
41 | * @callback AnimationCoroutine
42 | * @generator
43 | * @returns the result of the function if any to be returned to the caller
44 | */
45 |
46 |
47 | /**
48 | * @callback GeneratorFunction
49 | * @generator
50 | * @param {...*} params - the parameters to pass
51 | * @returns {*} the result of the coroutine
52 | */
53 |
54 | /**
55 | * @callback AsyncFunction
56 | * @param {*} params - the parameters to pass
57 | * @async
58 | * @returns {*} result of calling the function
59 | */
60 |
61 |
62 |
63 |
--------------------------------------------------------------------------------
/src/component/coroutines.js:
--------------------------------------------------------------------------------
1 | /**
2 | *3 | * A coroutine to be run during the gaps in other processing and animation. 4 | *
5 | *
6 | * The coroutine should yield regularly to do a time check. A plain yield will cause
7 | * a check against the standard time remaining specified when running. yield {number} will
8 | * check that number milliseconds are available and yield true will abandon any more
9 | * processing on the current frame.
10 | *
yield will cause the routine to resume at the start
40 | * of the next frame.
41 | * @callback AnimationCoroutine
42 | * @generator
43 | * @returns the result of the function if any to be returned to the caller
44 | */
45 |
46 |
47 | /**
48 | * @callback GeneratorFunction
49 | * @generator
50 | * @param {...*} params - the parameters to pass
51 | * @returns {*} the result of the coroutine
52 | */
53 |
54 | /**
55 | * @callback AsyncFunction
56 | * @param {*} params - the parameters to pass
57 | * @async
58 | * @returns {*} result of calling the function
59 | */
60 |
61 |
62 |
63 |
--------------------------------------------------------------------------------
/dist/group-by.js:
--------------------------------------------------------------------------------
1 | "use strict";var _regeneratorRuntime2=require("@babel/runtime/regenerator"),_interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:!0}),exports.groupBy=groupBy;var _regenerator=_interopRequireDefault(require("@babel/runtime/regenerator")),_marked=_regeneratorRuntime2.mark(groupBy);function _createForOfIteratorHelper(o,a){var b;if("undefined"==typeof Symbol||null==o[Symbol.iterator]){if(Array.isArray(o)||(b=_unsupportedIterableToArray(o))||a&&o&&"number"==typeof o.length){b&&(o=b);var c=0,d=function(){};return{s:d,n:function n(){return c>=o.length?{done:!0}:{done:!1,value:o[c++]}},e:function e(a){throw a},f:d}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var e,f=!0,g=!1;return{s:function s(){b=o[Symbol.iterator]()},n:function n(){var a=b.next();return f=a.done,a},e:function e(a){g=!0,e=a},f:function f(){try{f||null==b.return||b.return()}finally{if(g)throw e}}}}function _unsupportedIterableToArray(o,a){if(o){if("string"==typeof o)return _arrayLikeToArray(o,a);var n=Object.prototype.toString.call(o).slice(8,-1);return"Object"===n&&o.constructor&&(n=o.constructor.name),"Map"===n||"Set"===n?Array.from(o):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?_arrayLikeToArray(o,a):void 0}}function _arrayLikeToArray(a,b){(null==b||b>a.length)&&(b=a.length);for(var c=0,d=Array(b);cyields on a regular basis
9 | * @param {Function} fn - the function to be wrapped
10 | * @param {number} [frequency=8] -
11 | * the number of times the function should be called
12 | * before performing a yield
13 | * @returns {Coroutine} The wrapped yielding
14 | * version of the function passed
15 | */
16 | export function yielding(fn, frequency = 16) {
17 | let yieldCount = 0;
18 | if(fn._yielding) return fn;
19 | let result = function* (...params) {
20 | let result = fn(...params);
21 | if(result && result.then) {
22 | result = yield result
23 | }
24 | if (yieldCount++ % frequency === 0) {
25 | yield;
26 | }
27 | return result;
28 | };
29 | result._yielding = true
30 | return result
31 | }
32 |
33 | /**
34 | * @callback PromiseFn
35 | * @param {...*} [parameters] the parameters for the function
36 | * @return {Promise} a promise for the result of the function
37 | */
38 |
39 | /**
40 | * Returns a function that will execute the passed
41 | * Coroutine and return a Promise for its result. The
42 | * returned function will take any number of parameters
43 | * and pass them on to the coroutine.
44 | *
45 | * @param {Coroutine} coroutine - The coroutine to run
46 | * @returns {PromiseFn|Function} a function that can be called to execute the coroutine
47 | * and return its result on completion
48 | */
49 | export function wrapAsPromise(coroutine) {
50 | const result = function (...params) {
51 | return run(coroutine(...params))
52 | };
53 | result.with = function (...params) {
54 | return call(result, ...params)
55 | }
56 | return result
57 | }
58 |
59 | export function curryRight(fn, supplied, execute) {
60 | if(fn.length > supplied.length) {
61 | return function(...params) {
62 | return curryRight.call(this, fn, [...params, ...supplied], execute)
63 | }
64 | }
65 | return execute.apply(this, supplied)
66 | }
67 |
--------------------------------------------------------------------------------
/src/component/wrappers.js:
--------------------------------------------------------------------------------
1 |
2 |
3 | import run from './run'
4 | import {call} from './call'
5 |
6 | /**
7 | * Wraps a normal function into a generator function
8 | * that yields on a regular basis
9 | * @param {Function} fn - the function to be wrapped
10 | * @param {number} [frequency=8] -
11 | * the number of times the function should be called
12 | * before performing a yield
13 | * @returns {Coroutine} The wrapped yielding
14 | * version of the function passed
15 | */
16 | export function yielding(fn, frequency = 16) {
17 | let yieldCount = 0;
18 | if(fn._yielding) return fn;
19 | let result = function* (...params) {
20 | let result = fn(...params);
21 | if(result && result.then) {
22 | result = yield result
23 | }
24 | if (yieldCount++ % frequency === 0) {
25 | yield;
26 | }
27 | return result;
28 | };
29 | result._yielding = true
30 | return result
31 | }
32 |
33 | /**
34 | * @callback PromiseFn
35 | * @param {...*} [parameters] the parameters for the function
36 | * @return {Promise} a promise for the result of the function
37 | */
38 |
39 | /**
40 | * Returns a function that will execute the passed
41 | * Coroutine and return a Promise for its result. The
42 | * returned function will take any number of parameters
43 | * and pass them on to the coroutine.
44 | *
45 | * @param {Coroutine} coroutine - The coroutine to run
46 | * @returns {PromiseFn|Function} a function that can be called to execute the coroutine
47 | * and return its result on completion
48 | */
49 | export function wrapAsPromise(coroutine) {
50 | const result = function (...params) {
51 | return run(coroutine(...params))
52 | };
53 | result.with = function (...params) {
54 | return call(result, ...params)
55 | }
56 | return result
57 | }
58 |
59 | export function curryRight(fn, supplied, execute) {
60 | if(fn.length > supplied.length) {
61 | return function(...params) {
62 | return curryRight.call(this, fn, [...params, ...supplied], execute)
63 | }
64 | }
65 | return execute.apply(this, supplied)
66 | }
67 |
--------------------------------------------------------------------------------
/dist/unique-by.js:
--------------------------------------------------------------------------------
1 | "use strict";var _regeneratorRuntime2=require("@babel/runtime/regenerator"),_interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:!0}),exports.uniqueBy=uniqueBy;var _regenerator=_interopRequireDefault(require("@babel/runtime/regenerator")),_marked=_regeneratorRuntime2.mark(uniqueBy);function _createForOfIteratorHelper(o,a){var b;if("undefined"==typeof Symbol||null==o[Symbol.iterator]){if(Array.isArray(o)||(b=_unsupportedIterableToArray(o))||a&&o&&"number"==typeof o.length){b&&(o=b);var c=0,d=function(){};return{s:d,n:function n(){return c>=o.length?{done:!0}:{done:!1,value:o[c++]}},e:function e(a){throw a},f:d}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var e,f=!0,g=!1;return{s:function s(){b=o[Symbol.iterator]()},n:function n(){var a=b.next();return f=a.done,a},e:function e(a){g=!0,e=a},f:function f(){try{f||null==b.return||b.return()}finally{if(g)throw e}}}}function _unsupportedIterableToArray(o,a){if(o){if("string"==typeof o)return _arrayLikeToArray(o,a);var n=Object.prototype.toString.call(o).slice(8,-1);return"Object"===n&&o.constructor&&(n=o.constructor.name),"Map"===n||"Set"===n?Array.from(o):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?_arrayLikeToArray(o,a):void 0}}function _arrayLikeToArray(a,b){(null==b||b>a.length)&&(b=a.length);for(var c=0,d=Array(b);cv * 2),
10 | stringifyAsync
11 | )
12 | let result = await process('[1,2,3,4]')
13 | result.should.eq('[2,4,6,8]')
14 | })
15 | it('should be able to run a singleton', async function () {
16 | const job = singleton(test1, 99)
17 | let value = 0
18 | job(21).then(r=>value = r)
19 | let result = await job(20)
20 | result.should.eq(20)
21 | value.should.eq(99)
22 |
23 | function * test1(value) {
24 | yield new Promise(resolve=>setTimeout(resolve, 50))
25 | return value
26 | }
27 | })
28 | it('should be able to repeat a function', async function () {
29 | let current
30 | const process = pipe(
31 | parseAsync,
32 | tap(capture),
33 | repeat(double, 2),
34 | stringifyAsync
35 | )
36 | let result = await process('[1,2,3,4]')
37 | result.should.eq('[4,8,12,16]')
38 | current.should.deep.eq([1, 2, 3, 4])
39 | function double(values) {
40 | return values.map(v=>v*2)
41 | }
42 | function capture(v) {
43 | current = v
44 | }
45 | })
46 | it('should be able to branch', async function () {
47 | let output
48 | const process = pipe(
49 | parseAsync,
50 | branch(pipe(stringifyAsync, tap(capture))),
51 | mapAsync.with(v => v * 2),
52 | stringifyAsync
53 | )
54 | let result = await process('[1,2,3,4]')
55 | result.should.eq('[2,4,6,8]')
56 | output.should.eq('[1,2,3,4]')
57 | function capture(values) {
58 | output = values
59 | }
60 | })
61 | })
62 |
--------------------------------------------------------------------------------
/template/static/styles/prettify-jsdoc.css:
--------------------------------------------------------------------------------
1 | /* JSDoc prettify.js theme */
2 |
3 | /* plain text */
4 | .pln {
5 | color: #000000;
6 | font-weight: normal;
7 | font-style: normal;
8 | }
9 |
10 | /* string content */
11 | .str {
12 | color: hsl(104, 100%, 24%);
13 | font-weight: normal;
14 | font-style: normal;
15 | }
16 |
17 | /* a keyword */
18 | .kwd {
19 | color: #000000;
20 | font-weight: bold;
21 | font-style: normal;
22 | }
23 |
24 | /* a comment */
25 | .com {
26 | font-weight: normal;
27 | font-style: italic;
28 | }
29 |
30 | /* a type name */
31 | .typ {
32 | color: #000000;
33 | font-weight: normal;
34 | font-style: normal;
35 | }
36 |
37 | /* a literal value */
38 | .lit {
39 | color: #006400;
40 | font-weight: normal;
41 | font-style: normal;
42 | }
43 |
44 | /* punctuation */
45 | .pun {
46 | color: #000000;
47 | font-weight: bold;
48 | font-style: normal;
49 | }
50 |
51 | /* lisp open bracket */
52 | .opn {
53 | color: #000000;
54 | font-weight: bold;
55 | font-style: normal;
56 | }
57 |
58 | /* lisp close bracket */
59 | .clo {
60 | color: #000000;
61 | font-weight: bold;
62 | font-style: normal;
63 | }
64 |
65 | /* a markup tag name */
66 | .tag {
67 | color: #006400;
68 | font-weight: normal;
69 | font-style: normal;
70 | }
71 |
72 | /* a markup attribute name */
73 | .atn {
74 | color: #006400;
75 | font-weight: normal;
76 | font-style: normal;
77 | }
78 |
79 | /* a markup attribute value */
80 | .atv {
81 | color: #006400;
82 | font-weight: normal;
83 | font-style: normal;
84 | }
85 |
86 | /* a declaration */
87 | .dec {
88 | color: #000000;
89 | font-weight: bold;
90 | font-style: normal;
91 | }
92 |
93 | /* a variable name */
94 | .var {
95 | color: #000000;
96 | font-weight: normal;
97 | font-style: normal;
98 | }
99 |
100 | /* a function name */
101 | .fun {
102 | color: #000000;
103 | font-weight: bold;
104 | font-style: normal;
105 | }
106 |
107 | /* Specify class=linenums on a pre to get line numbering */
108 | ol.linenums {
109 | margin-top: 0;
110 | margin-bottom: 0;
111 | }
112 |
--------------------------------------------------------------------------------
/dist/update.js:
--------------------------------------------------------------------------------
1 | "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.update=update;function _createForOfIteratorHelper(o,a){var b;if("undefined"==typeof Symbol||null==o[Symbol.iterator]){if(Array.isArray(o)||(b=_unsupportedIterableToArray(o))||a&&o&&"number"==typeof o.length){b&&(o=b);var c=0,d=function(){};return{s:d,n:function n(){return c>=o.length?{done:!0}:{done:!1,value:o[c++]}},e:function e(a){throw a},f:d}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var e,f=!0,g=!1;return{s:function s(){b=o[Symbol.iterator]()},n:function n(){var a=b.next();return f=a.done,a},e:function e(a){g=!0,e=a},f:function f(){try{f||null==b.return||b.return()}finally{if(g)throw e}}}}function _unsupportedIterableToArray(o,a){if(o){if("string"==typeof o)return _arrayLikeToArray(o,a);var n=Object.prototype.toString.call(o).slice(8,-1);return"Object"===n&&o.constructor&&(n=o.constructor.name),"Map"===n||"Set"===n?Array.from(o):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?_arrayLikeToArray(o,a):void 0}}function _arrayLikeToArray(a,b){(null==b||b>a.length)&&(b=a.length);for(var c=0,d=Array(b);c=o.length?{done:!0}:{done:!1,value:o[c++]}},e:function e(a){throw a},f:d}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var e,f=!0,g=!1;return{s:function s(){b=o[Symbol.iterator]()},n:function n(){var a=b.next();return f=a.done,a},e:function e(a){g=!0,e=a},f:function f(){try{f||null==b.return||b.return()}finally{if(g)throw e}}}}function _unsupportedIterableToArray(o,a){if(o){if("string"==typeof o)return _arrayLikeToArray(o,a);var n=Object.prototype.toString.call(o).slice(8,-1);return"Object"===n&&o.constructor&&(n=o.constructor.name),"Map"===n||"Set"===n?Array.from(o):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?_arrayLikeToArray(o,a):void 0}}function _arrayLikeToArray(a,b){(null==b||b>a.length)&&(b=a.length);for(var c=0,d=Array(b);c 10000) animationCallbacks = animationCallbacks.slice(-9000)
12 | }
13 |
14 | function process() {
15 | let callbacks = animationCallbacks
16 | if (callbacks.length) {
17 | requestAnimationFrame(process)
18 | } else {
19 | requested = false
20 | }
21 | animationCallbacks = []
22 | for (let callback of callbacks) {
23 | callback()
24 | }
25 | }
26 |
27 | /**
28 | * Start an animation coroutine, the animation will continue until
29 | * you return and will be broken up between frames by using a
30 | * yield.
31 | *
32 | * @param {AnimationCoroutine|Iterator} coroutine - The animation to run
33 | * @param {...*} [params] - Parameters to be passed to the animation function
34 | * @returns {Promiseupdate has a terminate() method
37 | * that can be used to stop the routine.
38 | */
39 | export function update(coroutine, ...params) {
40 | if (typeof window === 'undefined') throw new Error('Requires a browser to run')
41 | let terminated = false
42 | let resolver = null
43 | const result = new Promise(function (resolve, reject) {
44 | resolver = resolve
45 | const iterator = coroutine.next ? coroutine : coroutine(...params)
46 | nextAnimationFrame(run)
47 |
48 | function run() {
49 | if (terminated) {
50 | iterator.return()
51 | return
52 | }
53 |
54 | try {
55 | const {value, done} = iterator.next()
56 | if (done) {
57 | resolve(value)
58 | return
59 | }
60 | } catch (e) {
61 | reject(e)
62 | return
63 | }
64 |
65 | nextAnimationFrame(run)
66 | }
67 | })
68 | result.terminate = function (result) {
69 | terminated = true
70 | if (resolver) {
71 | resolver(result)
72 | }
73 | }
74 | return result
75 | }
76 |
--------------------------------------------------------------------------------
/src/component/update.js:
--------------------------------------------------------------------------------
1 | let requested = false
2 | let animationCallbacks = []
3 |
4 | function nextAnimationFrame(fn) {
5 | if (typeof window === 'undefined') throw new Error('Cannot run without a browser')
6 | if (animationCallbacks.length === 0 && !requested) {
7 | requested = true
8 | requestAnimationFrame(process)
9 | }
10 | animationCallbacks.push(fn)
11 | if (animationCallbacks.length > 10000) animationCallbacks = animationCallbacks.slice(-9000)
12 | }
13 |
14 | function process() {
15 | let callbacks = animationCallbacks
16 | if (callbacks.length) {
17 | requestAnimationFrame(process)
18 | } else {
19 | requested = false
20 | }
21 | animationCallbacks = []
22 | for (let callback of callbacks) {
23 | callback()
24 | }
25 | }
26 |
27 | /**
28 | * Start an animation coroutine, the animation will continue until
29 | * you return and will be broken up between frames by using a
30 | * yield.
31 | *
32 | * @param {AnimationCoroutine|Iterator} coroutine - The animation to run
33 | * @param {...*} [params] - Parameters to be passed to the animation function
34 | * @returns {Promiseupdate has a terminate() method
37 | * that can be used to stop the routine.
38 | */
39 | export function update(coroutine, ...params) {
40 | if (typeof window === 'undefined') throw new Error('Requires a browser to run')
41 | let terminated = false
42 | let resolver = null
43 | const result = new Promise(function (resolve, reject) {
44 | resolver = resolve
45 | const iterator = coroutine.next ? coroutine : coroutine(...params)
46 | nextAnimationFrame(run)
47 |
48 | function run() {
49 | if (terminated) {
50 | iterator.return()
51 | return
52 | }
53 |
54 | try {
55 | const {value, done} = iterator.next()
56 | if (done) {
57 | resolve(value)
58 | return
59 | }
60 | } catch (e) {
61 | reject(e)
62 | return
63 | }
64 |
65 | nextAnimationFrame(run)
66 | }
67 | })
68 | result.terminate = function (result) {
69 | terminated = true
70 | if (resolver) {
71 | resolver(result)
72 | }
73 | }
74 | return result
75 | }
76 |
--------------------------------------------------------------------------------
/src/logo.svg:
--------------------------------------------------------------------------------
1 |
8 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "js-coroutines",
3 | "sideEffects": [
4 | "./dist/polyfill.js"
5 | ],
6 | "version": "2.4.36",
7 | "private": false,
8 | "files": [
9 | "dist",
10 | "README.md",
11 | "LICENCE.txt"
12 | ],
13 | "repository": "https://github.com/miketalbot/js-coroutines",
14 | "main": "dist/index.js",
15 | "devDependencies": {
16 | "@babel/cli": "^7.13.14",
17 | "@babel/core": "^7.13.14",
18 | "@babel/plugin-proposal-class-properties": "^7.13.0",
19 | "@babel/plugin-transform-runtime": "^7.13.10",
20 | "@babel/polyfill": "^7.10.1",
21 | "@babel/preset-env": "^7.13.12",
22 | "@babel/preset-react": "^7.13.13",
23 | "@babel/register": "^7.13.14",
24 | "@pixi/jsdoc-template": "^2.6.0",
25 | "@testing-library/jest-dom": "^5.11.10",
26 | "@testing-library/react": "^11.2.6",
27 | "@testing-library/user-event": "^13.1.1",
28 | "babel-plugin-minify-mangle-names": "^0.5.0",
29 | "babel-preset-minify": "^0.5.1",
30 | "chai": "^4.3.4",
31 | "docdash": "^1.2.0",
32 | "dts-generator": "^3.0.0",
33 | "express": "^4.17.1",
34 | "jsdoc": "^3.6.6",
35 | "lodash": "^4.17.21",
36 | "mocha": "^8.3.2",
37 | "react": "^17.0.2",
38 | "react-dom": "^17.0.2",
39 | "react-scripts": "^4.0.3",
40 | "showdown": "^1.9.1",
41 | "tern": "^0.24.3",
42 | "tsd-jsdoc": "^2.5.0",
43 | "typescript": "^4.2.3",
44 | "versiony-cli": "^1.3.0"
45 | },
46 | "scripts": {
47 | "start": "PORT=3012 react-scripts start",
48 | "dts": "node ./build-dts.js",
49 | "document": "rm -rf ./docs && jsdoc -c ./doc.conf.json && cp -r ./docs ../js-coroutines-web/public",
50 | "tsd": "jsdoc -t node_modules/tsd-jsdoc/dist -r ./src/component",
51 | "build": "source ./scripts/build.sh",
52 | "push": "node ./node_modules/versiony-cli/bin/cli.js ./package.json --patch && npm run build && npm publish && git add . && git commit -am build && git push",
53 | "watch": "NODE_ENV=production babel src/component --watch --ignore \"__tests__\",\"**/*.spec.js\",\"**/*.test.js\",\"__snapshots__\" --out-dir dist",
54 | "test": "mocha --require @babel/register src/test/**/*.test.js --exit",
55 | "eject": "react-scripts eject",
56 | "test-express": "npm run build && node ./src/test/basic-express.js"
57 | },
58 | "eslintConfig": {
59 | "extends": "react-app"
60 | },
61 | "types": "dist/es6/jscoroutines.d.ts",
62 | "typings": "dist/es6/jscoroutines.d.ts",
63 | "browserslist": {
64 | "production": [
65 | ">0.2%",
66 | "not dead",
67 | "IE 11",
68 | "not op_mini all"
69 | ],
70 | "development": [
71 | "last 1 chrome version",
72 | "last 1 firefox version",
73 | "last 1 safari version"
74 | ]
75 | },
76 | "peerDependencies": {
77 | "@babel/runtime": ">=7.4.8"
78 | }
79 | }
--------------------------------------------------------------------------------
/dist/async-compression-wrappers.js:
--------------------------------------------------------------------------------
1 | "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.base64Decompress=exports.base64decompressFromUTF16Async=exports.decompressAsync=exports.decompressFromEncodedURIComponentAsync=exports.decompressFromUint8ArrayAsync=exports.decompressFromUTF16Async=exports.decompressFromBase64Async=exports.base64Compress=exports.base64CompressToUTF16Async=exports.compressAsync=exports.compressToEncodedURIComponentAsync=exports.compressToUint8ArrayAsync=exports.compressToUTF16Async=exports.compressToBase64Async=void 0;var _wrappers=require("./wrappers"),_base64String=require("./lz-string/base64-string"),_lzString=require("./lz-string/lz-string"),compressToBase64Async=(0,_wrappers.wrapAsPromise)(_lzString.LZStringGenerator.compressToBase64);exports.compressToBase64Async=compressToBase64Async;var compressToUTF16Async=(0,_wrappers.wrapAsPromise)(_lzString.LZStringGenerator.compressToUTF16);exports.compressToUTF16Async=compressToUTF16Async;var compressToUint8ArrayAsync=(0,_wrappers.wrapAsPromise)(_lzString.LZStringGenerator.compressToUint8Array);exports.compressToUint8ArrayAsync=compressToUint8ArrayAsync;var compressToEncodedURIComponentAsync=(0,_wrappers.wrapAsPromise)(_lzString.LZStringGenerator.compressToEncodedURIComponent);exports.compressToEncodedURIComponentAsync=compressToEncodedURIComponentAsync;var compressAsync=(0,_wrappers.wrapAsPromise)(_lzString.LZStringGenerator.compress);exports.compressAsync=compressAsync;var base64CompressToUTF16Async=(0,_wrappers.wrapAsPromise)(_base64String.Base64StringGenerator.compressToUTF16);exports.base64CompressToUTF16Async=base64CompressToUTF16Async;var base64Compress=(0,_wrappers.wrapAsPromise)(_base64String.Base64StringGenerator.compress);exports.base64Compress=base64Compress;var decompressFromBase64Async=(0,_wrappers.wrapAsPromise)(_lzString.LZStringGenerator.decompressFromBase64);exports.decompressFromBase64Async=decompressFromBase64Async;var decompressFromUTF16Async=(0,_wrappers.wrapAsPromise)(_lzString.LZStringGenerator.decompressFromUTF16);exports.decompressFromUTF16Async=decompressFromUTF16Async;var decompressFromUint8ArrayAsync=(0,_wrappers.wrapAsPromise)(_lzString.LZStringGenerator.decompressFromUint8Array);exports.decompressFromUint8ArrayAsync=decompressFromUint8ArrayAsync;var decompressFromEncodedURIComponentAsync=(0,_wrappers.wrapAsPromise)(_lzString.LZStringGenerator.decompressFromURIComponent);exports.decompressFromEncodedURIComponentAsync=decompressFromEncodedURIComponentAsync;var decompressAsync=(0,_wrappers.wrapAsPromise)(_lzString.LZStringGenerator.decompress);exports.decompressAsync=decompressAsync;var base64decompressFromUTF16Async=(0,_wrappers.wrapAsPromise)(_base64String.Base64StringGenerator.decompressFromUTF16);exports.base64decompressFromUTF16Async=base64decompressFromUTF16Async;var base64Decompress=(0,_wrappers.wrapAsPromise)(_base64String.Base64StringGenerator.decompress);exports.base64Decompress=base64Decompress;
--------------------------------------------------------------------------------
/template/static/scripts/pagelocation.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | $(document).ready(function () {
4 | var currentSectionNav, target;
5 |
6 | // If an anchor hash is in the URL highlight the menu item
7 | highlightActiveHash();
8 | // If a specific page section is in the URL highlight the menu item
9 | highlightActiveSection();
10 |
11 | // If a specific page section is in the URL scroll that section up to the top
12 | currentSectionNav = $('#' + getCurrentSectionName() + '-nav');
13 |
14 | if (currentSectionNav.position()) {
15 | $('nav').scrollTop(currentSectionNav.position().top);
16 | }
17 |
18 | // function to scroll to anchor when clicking an anchor linl
19 | $('a[href*="#"]:not([href="#"])').click(function () {
20 | /* eslint-disable no-invalid-this */
21 | if (location.pathname.replace(/^\//, '') === this.pathname.replace(/^\//, '') && location.hostname === this.hostname) {
22 | target = $(this.hash);
23 | target = target.length ? target : $('[name=' + this.hash.slice(1) + ']');
24 | if (target.length) {
25 | $('html, body').animate({
26 | scrollTop: target.offset().top
27 | }, 1000);
28 | }
29 | }
30 | /* eslint-enable no-invalid-this */
31 | });
32 | });
33 |
34 | // If a new anchor section is selected, change the hightlighted menu item
35 | $(window).bind('hashchange', function (event) {
36 | highlightActiveHash(event);
37 | });
38 |
39 | function highlightActiveHash(event) {
40 | var oldUrl, oldSubSectionElement;
41 |
42 | // check for and remove old hash active state
43 | if (event && event.originalEvent.oldURL) {
44 | oldUrl = event.originalEvent.oldURL;
45 |
46 | if (oldUrl.indexOf('#') > -1) {
47 | oldSubSectionElement = $('#' + getCurrentSectionName() + '-' + oldUrl.substring(oldUrl.indexOf('#') + 1) + '-nav');
48 |
49 | if (oldSubSectionElement) {
50 | oldSubSectionElement.removeClass('active');
51 | }
52 | }
53 | }
54 |
55 | if (getCurrentHashName()) {
56 | $('#' + getCurrentSectionName() + '-' + getCurrentHashName() + '-nav').addClass('active');
57 | }
58 | }
59 |
60 | function highlightActiveSection() {
61 | var pageId = getCurrentSectionName();
62 |
63 | $('#' + pageId + '-nav').addClass('active');
64 | }
65 |
66 | function getCurrentSectionName() {
67 | var path = window.location.pathname;
68 | var pageUrl = path.split('/').pop();
69 |
70 | var sectionName = pageUrl.substring(0, pageUrl.indexOf('.'));
71 |
72 | // remove the wodr module- if its in the url
73 | sectionName = sectionName.replace('module-', '');
74 |
75 | return sectionName;
76 | }
77 |
78 | function getCurrentHashName() {
79 | var pageSubSectionId;
80 | var pageSubSectionHash = window.location.hash;
81 |
82 | if (pageSubSectionHash) {
83 | pageSubSectionId = pageSubSectionHash.substring(1).replace('.', '');
84 |
85 | return pageSubSectionId;
86 | }
87 |
88 | return false;
89 | }
90 |
--------------------------------------------------------------------------------
/template/static/styles/prettify-tomorrow.css:
--------------------------------------------------------------------------------
1 | /* Tomorrow Theme */
2 | /* Original theme - https://github.com/chriskempson/tomorrow-theme */
3 | /* Pretty printing styles. Used with prettify.js. */
4 | /* SPAN elements with the classes below are added by prettyprint. */
5 | /* plain text */
6 | .pln {
7 | color: #4d4d4c; }
8 |
9 | @media screen {
10 | /* string content */
11 | .str {
12 | color: hsl(104, 100%, 24%); }
13 |
14 | /* a keyword */
15 | .kwd {
16 | color: hsl(240, 100%, 50%); }
17 |
18 | /* a comment */
19 | .com {
20 | color: hsl(0, 0%, 60%); }
21 |
22 | /* a type name */
23 | .typ {
24 | color: hsl(240, 100%, 32%); }
25 |
26 | /* a literal value */
27 | .lit {
28 | color: hsl(240, 100%, 40%); }
29 |
30 | /* punctuation */
31 | .pun {
32 | color: #000000; }
33 |
34 | /* lisp open bracket */
35 | .opn {
36 | color: #000000; }
37 |
38 | /* lisp close bracket */
39 | .clo {
40 | color: #000000; }
41 |
42 | /* a markup tag name */
43 | .tag {
44 | color: #c82829; }
45 |
46 | /* a markup attribute name */
47 | .atn {
48 | color: #f5871f; }
49 |
50 | /* a markup attribute value */
51 | .atv {
52 | color: #3e999f; }
53 |
54 | /* a declaration */
55 | .dec {
56 | color: #f5871f; }
57 |
58 | /* a variable name */
59 | .var {
60 | color: #c82829; }
61 |
62 | /* a function name */
63 | .fun {
64 | color: #4271ae; } }
65 | /* Use higher contrast and text-weight for printable form. */
66 | @media print, projection {
67 | .str {
68 | color: #060; }
69 |
70 | .kwd {
71 | color: #006;
72 | font-weight: bold; }
73 |
74 | .com {
75 | color: #600;
76 | font-style: italic; }
77 |
78 | .typ {
79 | color: #404;
80 | font-weight: bold; }
81 |
82 | .lit {
83 | color: #044; }
84 |
85 | .pun, .opn, .clo {
86 | color: #440; }
87 |
88 | .tag {
89 | color: #006;
90 | font-weight: bold; }
91 |
92 | .atn {
93 | color: #404; }
94 |
95 | .atv {
96 | color: #060; } }
97 | /* Style */
98 | /*
99 | pre.prettyprint {
100 | background: white;
101 | font-family: Consolas, Monaco, 'Andale Mono', monospace;
102 | font-size: 12px;
103 | line-height: 1.5;
104 | border: 1px solid #ccc;
105 | padding: 10px; }
106 | */
107 |
108 | /* Get LI elements to show when they are in the main article */
109 | article ul li {
110 | list-style-type: circle;
111 | margin-left: 25px;
112 | }
113 |
114 | /* Specify class=linenums on a pre to get line numbering */
115 | ol.linenums {
116 | margin-top: 0;
117 | margin-bottom: 0; }
118 |
119 | /* IE indents via margin-left */
120 | li.L0,
121 | li.L1,
122 | li.L2,
123 | li.L3,
124 | li.L4,
125 | li.L5,
126 | li.L6,
127 | li.L7,
128 | li.L8,
129 | li.L9 {
130 | /* */ }
131 |
132 | /* Alternate shading for lines */
133 | li.L1,
134 | li.L3,
135 | li.L5,
136 | li.L7,
137 | li.L9 {
138 | /* */ }
139 |
--------------------------------------------------------------------------------
/dist/es6/yastjson/lib/parse.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2020 5u9ar (zhuyingda) (c) 2020 Mike Talbot (Generator mods)
3 | *
4 | * The above copyright notice and this permission notice shall be included in all
5 | * copies or substantial portions of the Software.
6 | *
7 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
8 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
9 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
10 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
11 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
12 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
13 | * SOFTWARE.
14 | */
15 | import { Tokenizer } from "./tokenizer";
16 | import { AST } from "./ast";
17 | import { ExprType } from "./expression";
18 | import { TokenType } from "./token";
19 | import { yielder } from "./yielder";
20 |
21 | export class ASTParser {
22 | constructor(ast) {
23 | this.ast = ast;
24 | }
25 |
26 | *getJson() {
27 | return yield* this.handleValue(this.ast);
28 | }
29 |
30 | *handleJson(astNode) {
31 | if (astNode.type !== ExprType.Json) {
32 | throw new Error("[parse AST error] unexpected node type, expect Json");
33 | }
34 |
35 | let output;
36 | let node = astNode.childNodeList[0];
37 | if (node.type === ExprType.Array) {
38 | output = [];
39 | for (let item of node.childNodeList) {
40 | output.push(yield* this.handleValue(item.value));
41 | }
42 | } else if (node.type === ExprType.Object) {
43 | output = {};
44 | for (let item of node.childNodeList) {
45 | output[item.propName] = yield* this.handleValue(
46 | item.childNodeList[0].value
47 | );
48 | }
49 | } else {
50 | throw new Error("[parse AST error] unexpected second node type");
51 | }
52 | return output;
53 | }
54 |
55 | *handleValue(astNode) {
56 | if (yielder()) yield;
57 | let token;
58 | switch (astNode.type) {
59 | case TokenType.Null:
60 | return null;
61 | case TokenType.Boolean:
62 | token = astNode.tokens[0].text;
63 | return token === "true";
64 | case TokenType.Number:
65 | let num = +astNode.tokens[0].text;
66 | return num;
67 | case TokenType.String:
68 | return astNode.tokens[0].text.slice(1, -1);
69 | case ExprType.Json:
70 | return yield* this.handleJson(astNode);
71 | default:
72 | throw new Error(
73 | "[parse AST error] unexpected node type, expect a valid Value node"
74 | );
75 | }
76 | }
77 | }
78 |
79 | export function* parse(jsonString) {
80 | const tokenizer = new Tokenizer();
81 | const tokens = yield* tokenizer.tokenize(jsonString);
82 | const astInst = new AST(tokens);
83 | const ast = yield* astInst.buildTree();
84 | const astParser = new ASTParser(ast);
85 | return yield* astParser.getJson();
86 | }
87 |
--------------------------------------------------------------------------------
/src/component/yastjson/lib/parse.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2020 5u9ar (zhuyingda) (c) 2020 Mike Talbot (Generator mods)
3 | *
4 | * The above copyright notice and this permission notice shall be included in all
5 | * copies or substantial portions of the Software.
6 | *
7 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
8 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
9 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
10 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
11 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
12 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
13 | * SOFTWARE.
14 | */
15 | import { Tokenizer } from "./tokenizer";
16 | import { AST } from "./ast";
17 | import { ExprType } from "./expression";
18 | import { TokenType } from "./token";
19 | import { yielder } from "./yielder";
20 |
21 | export class ASTParser {
22 | constructor(ast) {
23 | this.ast = ast;
24 | }
25 |
26 | *getJson() {
27 | return yield* this.handleValue(this.ast);
28 | }
29 |
30 | *handleJson(astNode) {
31 | if (astNode.type !== ExprType.Json) {
32 | throw new Error("[parse AST error] unexpected node type, expect Json");
33 | }
34 |
35 | let output;
36 | let node = astNode.childNodeList[0];
37 | if (node.type === ExprType.Array) {
38 | output = [];
39 | for (let item of node.childNodeList) {
40 | output.push(yield* this.handleValue(item.value));
41 | }
42 | } else if (node.type === ExprType.Object) {
43 | output = {};
44 | for (let item of node.childNodeList) {
45 | output[item.propName] = yield* this.handleValue(
46 | item.childNodeList[0].value
47 | );
48 | }
49 | } else {
50 | throw new Error("[parse AST error] unexpected second node type");
51 | }
52 | return output;
53 | }
54 |
55 | *handleValue(astNode) {
56 | if (yielder()) yield;
57 | let token;
58 | switch (astNode.type) {
59 | case TokenType.Null:
60 | return null;
61 | case TokenType.Boolean:
62 | token = astNode.tokens[0].text;
63 | return token === "true";
64 | case TokenType.Number:
65 | let num = +astNode.tokens[0].text;
66 | return num;
67 | case TokenType.String:
68 | return astNode.tokens[0].text.slice(1, -1);
69 | case ExprType.Json:
70 | return yield* this.handleJson(astNode);
71 | default:
72 | throw new Error(
73 | "[parse AST error] unexpected node type, expect a valid Value node"
74 | );
75 | }
76 | }
77 | }
78 |
79 | export function* parse(jsonString) {
80 | const tokenizer = new Tokenizer();
81 | const tokens = yield* tokenizer.tokenize(jsonString);
82 | const astInst = new AST(tokens);
83 | const ast = yield* astInst.buildTree();
84 | const astParser = new ASTParser(ast);
85 | return yield* astParser.getJson();
86 | }
87 |
--------------------------------------------------------------------------------
/template/tmpl/properties.tmpl:
--------------------------------------------------------------------------------
1 |
40 |
41 | | Name | 46 | 47 | 48 |Type | 49 | 50 | 51 |Attributes | 52 | 53 | 54 | 55 |Default | 56 | 57 | 58 |Description | 59 |
|---|---|---|---|---|
|
73 |
74 |
75 | 76 | 77 | 78 | 79 | | 80 | 81 | 82 |
83 |
84 | <optional> 85 | 86 | 87 | 88 | <nullable> 89 | 90 | |
91 |
92 |
93 |
94 | 95 | 96 | 97 | 98 | | 99 | 100 | 101 |
102 |
103 |
104 | Properties105 | 106 | |
107 |
| Name | 55 | 56 | 57 |Type | 58 | 59 | 60 |Attributes | 61 | 62 | 63 | 64 |Default | 65 | 66 | 67 |Description | 68 |
|---|---|---|---|---|
|
81 |
82 |
83 | 84 | 85 | 86 | 87 | | 88 | 89 | 90 |
91 |
92 | <optional> 93 | 94 | 95 | 96 | <nullable> 97 | 98 | 99 | 100 | <repeatable> 101 | 102 | |
103 |
104 |
105 |
106 | 107 | 108 | 109 | 110 | | 111 | 112 | 113 |
114 |
115 |
116 | Properties117 | 118 | 119 | |
120 |