-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CachedIterable copied from fluent 0.6.4
- Loading branch information
0 parents
commit 05684dc
Showing
16 changed files
with
3,397 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
node_modules | ||
cached-iterable.js | ||
compat.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
test | ||
Makefile | ||
*_config.js | ||
eslint_* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
sudo: false | ||
language: node_js | ||
script: make all | ||
node_js: "8.9" | ||
cache: | ||
directories: node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
export SHELL := /bin/bash | ||
export PATH := $(CURDIR)/node_modules/.bin:$(PATH) | ||
|
||
SOURCES := $(wildcard src/*) | ||
VERSION := $(shell node -pe "require('./package.json').version") | ||
OK := \033[32;01m✓\033[0m | ||
|
||
PACKAGE := cached-iterable | ||
GLOBAL := CachedIterable | ||
|
||
# The default target. | ||
all: lint test build | ||
|
||
lint: | ||
@eslint --config $(CURDIR)/eslint_src.json --max-warnings 0 src/ | ||
@eslint --config $(CURDIR)/eslint_test.json --max-warnings 0 test/ | ||
@echo -e " $(OK) $@" | ||
|
||
.PHONY: test | ||
test: | ||
@mocha --recursive --ui tdd \ | ||
--require mocha_config \ | ||
test/**/*_test.js | ||
|
||
build: $(PACKAGE).js compat.js | ||
|
||
$(PACKAGE).js: $(SOURCES) | ||
@rollup $(CURDIR)/src/index.mjs \ | ||
--config $(CURDIR)/bundle_config.js \ | ||
--banner "/* $(PACKAGE)@$(VERSION) */" \ | ||
--amd.id $(PACKAGE) \ | ||
--name $(GLOBAL) \ | ||
--output.file $@ | ||
@echo -e " $(OK) $@ built" | ||
|
||
compat.js: $(SOURCES) | ||
@rollup $(CURDIR)/src/index.mjs \ | ||
--config $(CURDIR)/compat_config.js \ | ||
--banner "/* $(PACKAGE)@$(VERSION) */" \ | ||
--amd.id $(PACKAGE) \ | ||
--name $(GLOBAL) \ | ||
--output.file $@ | ||
@echo -e " $(OK) $@ built" | ||
|
||
clean: | ||
@rm -f $(PACKAGE).js compat.js | ||
@echo -e " $(OK) clean" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# cached-iterable | ||
|
||
`cached-iterable` exposes the `CachedItearble` class which implements the | ||
[iterable protocol][]. | ||
|
||
You can wrap any iterable in these classes to create a new iterable which | ||
caches the yielded elements. This is useful for iterating over an iterable many | ||
times without depleting it. | ||
|
||
[iterable protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterable_protocol | ||
|
||
## Installation | ||
|
||
`cached-iterable` can be used both on the client-side and the server-side. You | ||
can install it from the npm registry or use it as a standalone script (as the | ||
`CachedIterable` global). | ||
|
||
npm install cached-iterable | ||
|
||
## How to use | ||
|
||
```js | ||
import assert from "assert"; | ||
import {CachedIterable} from "cached-iterable"; | ||
|
||
function * countdown(i) { | ||
while (i--) { | ||
yield i; | ||
} | ||
} | ||
|
||
let numbers = new CachedIterable(countdown(3)); | ||
|
||
// `numbers` can be iterated over multiple times. | ||
assert.deepEqual([...numbers], [3, 2, 1, 0]); | ||
assert.deepEqual([...numbers], [3, 2, 1, 0]); | ||
``` | ||
|
||
## Compatibility | ||
|
||
For legacy browsers, the `compat` build has been transpiled using Babel's [env | ||
preset][]. It requires the regenerator runtime provided by [babel-polyfill][]. | ||
|
||
```javascript | ||
import {CachedIterable} from 'cached-iterable/compat'; | ||
``` | ||
|
||
[env preset]: https://babeljs.io/docs/plugins/preset-env/ | ||
[babel-polyfill]: https://babeljs.io/docs/usage/polyfill/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
export default { | ||
babelrc: false, | ||
presets: [ | ||
["@babel/preset-env", { | ||
// Cf. https://github.com/rollup/rollup-plugin-babel#modules | ||
modules: false, | ||
targets: { | ||
browsers: [ | ||
">1%", | ||
"last 4 versions", | ||
"Firefox ESR", | ||
"not ie < 9" | ||
] | ||
} | ||
}] | ||
] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export default { | ||
output: { | ||
format: 'umd', | ||
}, | ||
acorn: { | ||
ecmaVersion: 9, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import babel from 'rollup-plugin-babel'; | ||
import babelConfig from './babel_config'; | ||
|
||
export default { | ||
output: { | ||
format: 'umd' | ||
}, | ||
plugins: [ | ||
babel(babelConfig), | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
{ | ||
"parser": "babel-eslint", | ||
"parserOptions": { | ||
"ecmaVersion": 9, | ||
"sourceType": "module" | ||
}, | ||
"env": { | ||
"es6": true | ||
}, | ||
"rules": { | ||
"valid-typeof": 2, | ||
"no-console": 1, | ||
"no-dupe-args": 2, | ||
"no-dupe-keys": 2, | ||
"no-duplicate-case": 2, | ||
"no-extra-semi": 1, | ||
"no-func-assign": 2, | ||
"func-call-spacing": [ | ||
2, | ||
"never" | ||
], | ||
"no-unreachable": 1, | ||
"no-unexpected-multiline": 2, | ||
"no-sparse-arrays": 2, | ||
"complexity": [ | ||
1, | ||
18 | ||
], | ||
"dot-location": [ | ||
2, | ||
"property" | ||
], | ||
"no-implied-eval": 2, | ||
"no-loop-func": 2, | ||
"no-magic-numbers": [ | ||
1, | ||
{ | ||
"ignore": [ | ||
-1, | ||
0, | ||
1, | ||
2 | ||
] | ||
} | ||
], | ||
"no-useless-call": 2, | ||
"no-useless-concat": 2, | ||
"no-delete-var": 2, | ||
"no-shadow": 2, | ||
"no-undef": 2, | ||
"no-undef-init": 2, | ||
"no-unused-vars": 1, | ||
"consistent-return": 1, | ||
"curly": [ | ||
2, | ||
"multi-line" | ||
], | ||
"eqeqeq": 2, | ||
"no-extend-native": 2, | ||
"no-global-assign": 2, | ||
"no-extra-bind": 2, | ||
"no-redeclare": 2, | ||
"array-bracket-spacing": 2, | ||
"brace-style": [ | ||
1, | ||
"1tbs" | ||
], | ||
"no-mixed-spaces-and-tabs": 2, | ||
"no-tabs": 2, | ||
"prefer-arrow-callback": 1, | ||
"prefer-const": 2, | ||
"prefer-template": 2, | ||
"prefer-spread": 2, | ||
"quotes": [ | ||
2, | ||
"double", | ||
{ | ||
"avoidEscape": true | ||
} | ||
], | ||
"max-depth": [ | ||
2, | ||
6 | ||
], | ||
"max-len": [ | ||
2, | ||
80 | ||
], | ||
"no-nested-ternary": 2, | ||
"no-unneeded-ternary": 2, | ||
"strict": [ | ||
2, | ||
"global" | ||
], | ||
"indent": [ | ||
2, | ||
4, | ||
{ | ||
"SwitchCase": 1 | ||
} | ||
], | ||
"no-useless-escape": 2, | ||
"no-duplicate-imports": 2, | ||
"no-unsafe-negation": 2, | ||
"no-use-before-define": [ | ||
2, | ||
{ | ||
"functions": false, | ||
"classes": false | ||
} | ||
], | ||
"space-infix-ops": 2, | ||
"no-constant-condition": [ | ||
1, | ||
{ | ||
"checkLoops": false | ||
} | ||
], | ||
"no-empty": 1, | ||
"use-isnan": 2, | ||
"dot-notation": 2, | ||
"no-caller": 2, | ||
"no-else-return": 2, | ||
"no-eval": 2, | ||
"no-implicit-globals": 2, | ||
"no-iterator": 2, | ||
"no-multi-spaces": 2, | ||
"no-multi-str": 2, | ||
"no-octal": 2, | ||
"no-proto": 2, | ||
"no-sequences": 2, | ||
"block-spacing": 2, | ||
"eol-last": 2, | ||
"key-spacing": 2, | ||
"no-trailing-spaces": 2, | ||
"prefer-rest-params": 2, | ||
"no-cond-assign": 2, | ||
"keyword-spacing": 2, | ||
"arrow-parens": [ | ||
2, | ||
"as-needed" | ||
], | ||
"no-useless-return": 2, | ||
"semi": 2, | ||
"spaced-comment": [ | ||
2, | ||
"always" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"parser": "babel-eslint", | ||
"parserOptions": { | ||
"ecmaVersion": 9, | ||
"sourceType": "module", | ||
"ecmaFeatures": { | ||
"jsx": true | ||
} | ||
}, | ||
"env": { | ||
"es6": true, | ||
"node": true, | ||
"mocha": true | ||
}, | ||
"plugins": [ | ||
"mocha" | ||
], | ||
"rules": { | ||
"mocha/no-exclusive-tests": "error", | ||
"mocha/no-identical-title": "error" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
"use strict"; | ||
|
||
require("@babel/polyfill"); | ||
require("@babel/register")({ | ||
plugins: [ | ||
"@babel/plugin-proposal-async-generator-functions", | ||
"@babel/plugin-transform-modules-commonjs" | ||
] | ||
}); |
Oops, something went wrong.