0.1.1 • Published 11 years ago
numgen v0.1.1
numgen
Creates objects that generate number sequences.
Objects are iterable according to ECMAScript 6 (for example, they can be used in for-of loop).
Disclaimer: this package does not have anything common with ECMAScript 6 generators nor with yield operator.
Installation
Node
npm install numgenComponent
component install gamtiq/numgenJam
jam install numgenBower
bower install numgenJSPM
jspm install numgenSPM
spm install numgenAMD, <script>
Use dist/numgen.js or dist/numgen.min.js (minified version).
Usage
Node, Component, JSPM, SPM
var NumGen = require("numgen");Duo
var NumGen = require("gamtiq/numgen");
...Jam
require(["numgen"], function(NumGen) {
...
});JSPM
System.import("numgen").then(function(NumGen) {
...
});AMD
define(["path/to/dist/numgen.js"], function(NumGen) {
...
});Bower, <script>
<!-- Use bower_components/numgen/dist/numgen.js if the library was installed by Bower -->
<script type="text/javascript" src="path/to/dist/numgen.js"></script>
<script type="text/javascript">
// numgen is available via NumGen field of window object
...
</script>Example
var seq = new NumGen({
startValue: 3,
factor: 4,
valueChange: function(data) {
return data.index > 1 ? data.current : data.value;
}
});
console.log("Geometric progression:");
for (var nI = 1; nI < 11; nI++) {
console.log("#", nI, " - ", seq.getNext());
}
console.log("Next: ");
for (var num of seq) {
nI = seq.getIndex();
console.log("#", nI, " - ", num);
if (nI > 19) {
break;
}
}See test/numgen.js for additional examples.
API
See doc folder.
License
MIT

