numgen
Advanced tools
Comparing version 0.1.0 to 0.1.1
{ | ||
"name": "numgen", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "Creates objects that generate number sequences", | ||
@@ -5,0 +5,0 @@ "main": [ |
{ | ||
"name": "numgen", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "Creates objects that generate number sequences", | ||
@@ -5,0 +5,0 @@ "repository": "gamtiq/numgen", |
@@ -31,2 +31,4 @@ | ||
* <code>v</code> is variable value that changes depending on generator properties (см. {@link module:numgen~NumberGenerator#_value _value}). | ||
* <br> | ||
* Objects are ES6-iterable. | ||
* | ||
@@ -835,2 +837,15 @@ * @param {Object} [initValue] | ||
if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { | ||
NumberGenerator.prototype[Symbol.iterator] = function() { | ||
return this; | ||
}; | ||
NumberGenerator.prototype.next = function() { | ||
return { | ||
done: false, | ||
value: this.getNext() | ||
}; | ||
}; | ||
} | ||
//Exports | ||
@@ -837,0 +852,0 @@ |
@@ -1,1 +0,1 @@ | ||
!function(a,b){if("object"==typeof exports)module.exports=b(require,exports,module);else if("function"==typeof define&&define.amd)define(["require","exports","module"],b);else{var c=function(b){return a[b]},d=a,e={exports:d};a.NumGen=b(c,d,e)}}(this,function(a,b,c){function d(a){a&&"object"==typeof a&&("factor"in a&&this.setFactor(a.factor),"startValue"in a&&this.setStartValue(a.startValue),"maxValue"in a&&this.setMaxValue(a.maxValue),"resetValueOnMax"in a&&this.setResetValueOnMax(a.resetValueOnMax),"valueChange"in a&&this.setValueChange(a.valueChange),"passToChanger"in a&&this.setPassToChanger(a.passToChanger),"valueChangePeriod"in a&&this.setValueChangePeriod(a.valueChangePeriod),"valueSavePeriod"in a&&this.setValueSavePeriod(a.valueSavePeriod)),this.reset()}return d.prototype._factor=1,d.prototype.getFactor=function(){return this._factor},d.prototype.setFactor=function(a){return this._factor=a,this},d.prototype._value=0,d.prototype.getValue=function(){return this._value},d.prototype._startValue=0,d.prototype.getStartValue=function(){return this._startValue},d.prototype.setStartValue=function(a){return this._startValue=a,this},d.prototype._maxValue=Number.MAX_VALUE,d.prototype.getMaxValue=function(){return this._maxValue},d.prototype.setMaxValue=function(a){return this._maxValue=a,this},d.prototype._resetValueOnMax=!1,d.prototype.isResetValueOnMax=function(){return this._resetValueOnMax},d.prototype.setResetValueOnMax=function(a){return this._resetValueOnMax=a,this},d.prototype._valueChange=1,d.prototype.getValueChange=function(){return this._valueChange},d.prototype.setValueChange=function(a){return this._valueChange=a,this},d.prototype._passToChanger=!1,d.prototype.isPassToChanger=function(){return this._passToChanger},d.prototype.setPassToChanger=function(a){return this._passToChanger=a,this},d.prototype._valueChangePeriod=-1,d.prototype.getValueChangePeriod=function(){return this._valueChangePeriod},d.prototype.setValueChangePeriod=function(a){return this._valueChangePeriod=a,this},d.prototype._valueSavePeriod=-1,d.prototype.getValueSavePeriod=function(){return this._valueSavePeriod},d.prototype.setValueSavePeriod=function(a){return this._valueSavePeriod=a,this},d.prototype._index=0,d.prototype.getIndex=function(){return this._index},d.prototype._prev=void 0,d.prototype.getPrev=function(){return this._prev},d.prototype._current=0,d.prototype.getCurrent=function(){return this._current},d.prototype._lastNumberTime=0,d.prototype._state=null,d.prototype.getNext=function(){var a,b,c,d=this.getFactor(),e=this._lastNumberTime,f=this.getStartValue(),g=this._lastNumberTime=(new Date).getTime(),h=g-e,i=this.getValueSavePeriod();return this._index++,i>=0&&h>i?i=this._value=f:(i=this.getValueChangePeriod())<0||i>=h?(b=this.getMaxValue(),a=this.getValueChange(),"number"==typeof a?this._value+=a:a&&(c={index:this._index,value:this._value,startValue:this.getStartValue(),maxValue:b,factor:d,prev:this._prev,current:this._current,state:this._state||(this._state={})},this.isPassToChanger()&&(c.generator=this),"function"==typeof a?this._value=a(c):"function"==typeof a.execute&&(this._value=a.execute(c))),i=this._value,i>=b&&(i=this._value=b,this.isResetValueOnMax()&&(this._value=f))):i=this._value,this._prev=this._current,this._current=i*d},d.prototype.getNextPart=function(a){for(var b=[];a-->0;)b.push(this.getNext());return b},d.prototype.clone=function(){return new d({factor:this.getFactor(),maxValue:this.getMaxValue(),passToChanger:this.isPassToChanger(),resetValueOnMax:this.isResetValueOnMax(),startValue:this.getStartValue(),valueChange:this.getValueChange(),valueChangePeriod:this.getValueChangePeriod(),valueSavePeriod:this.getValueSavePeriod()})},d.prototype.getPart=function(a,b){"use strict";var c,d,e=[];if(b>=a){for(c=this.clone(),d=0;a>d;)d++,a>d&&c.getNext();for(0===d&&(e.push(c.getCurrent()),d++);d++<=b;)e.push(c.getNext())}return e},d.prototype.toArray=function(a){return this.getPart(1,a)},d.prototype.reset=function(){return this._value=this._startValue,this._current=this.getValue()*this.getFactor(),this._prev=void 0,this._index=0,this._lastNumberTime=(new Date).getTime(),this._state=null,this},d.prototype.dispose=function(){this._state=null},d.prototype.toString=function(){"use strict";var a;return["NumberGenerator: ","factor - ",this.getFactor(),", value - ",this.getValue(),", start value - ",this.getStartValue(),", max value - ",this.getMaxValue(),", value change period - ",(a=this.getValueChangePeriod())<0?"no":a+"ms",", value save period - ",(a=this.getValueSavePeriod())<0?"no":a+"ms",", index - ",this.getIndex(),", previous item - ",this.getPrev(),", current item - ",this.getCurrent()].join("")},c.exports=d,d}); | ||
!function(a,b){if("object"==typeof exports)module.exports=b(require,exports,module);else if("function"==typeof define&&define.amd)define(["require","exports","module"],b);else{var c=function(b){return a[b]},d=a,e={exports:d};a.NumGen=b(c,d,e)}}(this,function(a,b,c){function d(a){a&&"object"==typeof a&&("factor"in a&&this.setFactor(a.factor),"startValue"in a&&this.setStartValue(a.startValue),"maxValue"in a&&this.setMaxValue(a.maxValue),"resetValueOnMax"in a&&this.setResetValueOnMax(a.resetValueOnMax),"valueChange"in a&&this.setValueChange(a.valueChange),"passToChanger"in a&&this.setPassToChanger(a.passToChanger),"valueChangePeriod"in a&&this.setValueChangePeriod(a.valueChangePeriod),"valueSavePeriod"in a&&this.setValueSavePeriod(a.valueSavePeriod)),this.reset()}return d.prototype._factor=1,d.prototype.getFactor=function(){return this._factor},d.prototype.setFactor=function(a){return this._factor=a,this},d.prototype._value=0,d.prototype.getValue=function(){return this._value},d.prototype._startValue=0,d.prototype.getStartValue=function(){return this._startValue},d.prototype.setStartValue=function(a){return this._startValue=a,this},d.prototype._maxValue=Number.MAX_VALUE,d.prototype.getMaxValue=function(){return this._maxValue},d.prototype.setMaxValue=function(a){return this._maxValue=a,this},d.prototype._resetValueOnMax=!1,d.prototype.isResetValueOnMax=function(){return this._resetValueOnMax},d.prototype.setResetValueOnMax=function(a){return this._resetValueOnMax=a,this},d.prototype._valueChange=1,d.prototype.getValueChange=function(){return this._valueChange},d.prototype.setValueChange=function(a){return this._valueChange=a,this},d.prototype._passToChanger=!1,d.prototype.isPassToChanger=function(){return this._passToChanger},d.prototype.setPassToChanger=function(a){return this._passToChanger=a,this},d.prototype._valueChangePeriod=-1,d.prototype.getValueChangePeriod=function(){return this._valueChangePeriod},d.prototype.setValueChangePeriod=function(a){return this._valueChangePeriod=a,this},d.prototype._valueSavePeriod=-1,d.prototype.getValueSavePeriod=function(){return this._valueSavePeriod},d.prototype.setValueSavePeriod=function(a){return this._valueSavePeriod=a,this},d.prototype._index=0,d.prototype.getIndex=function(){return this._index},d.prototype._prev=void 0,d.prototype.getPrev=function(){return this._prev},d.prototype._current=0,d.prototype.getCurrent=function(){return this._current},d.prototype._lastNumberTime=0,d.prototype._state=null,d.prototype.getNext=function(){var a,b,c,d=this.getFactor(),e=this._lastNumberTime,f=this.getStartValue(),g=this._lastNumberTime=(new Date).getTime(),h=g-e,i=this.getValueSavePeriod();return this._index++,i>=0&&h>i?i=this._value=f:(i=this.getValueChangePeriod())<0||i>=h?(b=this.getMaxValue(),a=this.getValueChange(),"number"==typeof a?this._value+=a:a&&(c={index:this._index,value:this._value,startValue:this.getStartValue(),maxValue:b,factor:d,prev:this._prev,current:this._current,state:this._state||(this._state={})},this.isPassToChanger()&&(c.generator=this),"function"==typeof a?this._value=a(c):"function"==typeof a.execute&&(this._value=a.execute(c))),i=this._value,i>=b&&(i=this._value=b,this.isResetValueOnMax()&&(this._value=f))):i=this._value,this._prev=this._current,this._current=i*d},d.prototype.getNextPart=function(a){for(var b=[];a-->0;)b.push(this.getNext());return b},d.prototype.clone=function(){return new d({factor:this.getFactor(),maxValue:this.getMaxValue(),passToChanger:this.isPassToChanger(),resetValueOnMax:this.isResetValueOnMax(),startValue:this.getStartValue(),valueChange:this.getValueChange(),valueChangePeriod:this.getValueChangePeriod(),valueSavePeriod:this.getValueSavePeriod()})},d.prototype.getPart=function(a,b){"use strict";var c,d,e=[];if(b>=a){for(c=this.clone(),d=0;a>d;)d++,a>d&&c.getNext();for(0===d&&(e.push(c.getCurrent()),d++);d++<=b;)e.push(c.getNext())}return e},d.prototype.toArray=function(a){return this.getPart(1,a)},d.prototype.reset=function(){return this._value=this._startValue,this._current=this.getValue()*this.getFactor(),this._prev=void 0,this._index=0,this._lastNumberTime=(new Date).getTime(),this._state=null,this},d.prototype.dispose=function(){this._state=null},d.prototype.toString=function(){"use strict";var a;return["NumberGenerator: ","factor - ",this.getFactor(),", value - ",this.getValue(),", start value - ",this.getStartValue(),", max value - ",this.getMaxValue(),", value change period - ",(a=this.getValueChangePeriod())<0?"no":a+"ms",", value save period - ",(a=this.getValueSavePeriod())<0?"no":a+"ms",", index - ",this.getIndex(),", previous item - ",this.getPrev(),", current item - ",this.getCurrent()].join("")},"function"==typeof Symbol&&"symbol"==typeof Symbol.iterator&&(d.prototype[Symbol.iterator]=function(){return this},d.prototype.next=function(){return{done:!1,value:this.getNext()}}),c.exports=d,d}); |
@@ -0,17 +1,25 @@ | ||
/*global document */ | ||
(function() { | ||
var counter = 0; | ||
var numbered; | ||
var source = document.getElementsByClassName('prettyprint source'); | ||
var source = document.getElementsByClassName('prettyprint source linenums'); | ||
var i = 0; | ||
var lineNumber = 0; | ||
var lineId; | ||
var lines; | ||
var totalLines; | ||
var anchorHash; | ||
if (source && source[0]) { | ||
source = source[0].getElementsByTagName('code')[0]; | ||
anchorHash = document.location.hash.substring(1); | ||
lines = source[0].getElementsByTagName('li'); | ||
totalLines = lines.length; | ||
numbered = source.innerHTML.split('\n'); | ||
numbered = numbered.map(function(item) { | ||
counter++; | ||
return '<span id="line' + counter + '"></span>' + item; | ||
}); | ||
source.innerHTML = numbered.join('\n'); | ||
for (; i < totalLines; i++) { | ||
lineNumber++; | ||
lineId = 'line' + lineNumber; | ||
lines[i].id = lineId; | ||
if (lineId === anchorHash) { | ||
lines[i].className += ' selected'; | ||
} | ||
} | ||
} | ||
})(); |
@@ -0,0 +0,0 @@ |
PR.registerLangHandler(PR.createSimpleLexer([["pln",/^[\t\n\f\r ]+/,null," \t\r\n"]],[["str",/^"(?:[^\n\f\r"\\]|\\(?:\r\n?|\n|\f)|\\[\S\s])*"/,null],["str",/^'(?:[^\n\f\r'\\]|\\(?:\r\n?|\n|\f)|\\[\S\s])*'/,null],["lang-css-str",/^url\(([^"')]*)\)/i],["kwd",/^(?:url|rgb|!important|@import|@page|@media|@charset|inherit)(?=[^\w-]|$)/i,null],["lang-css-kw",/^(-?(?:[_a-z]|\\[\da-f]+ ?)(?:[\w-]|\\\\[\da-f]+ ?)*)\s*:/i],["com",/^\/\*[^*]*\*+(?:[^*/][^*]*\*+)*\//],["com", | ||
/^(?:<\!--|--\>)/],["lit",/^(?:\d+|\d*\.\d+)(?:%|[a-z]+)?/i],["lit",/^#[\da-f]{3,6}/i],["pln",/^-?(?:[_a-z]|\\[\da-f]+ ?)(?:[\w-]|\\\\[\da-f]+ ?)*/i],["pun",/^[^\s\w"']+/]]),["css"]);PR.registerLangHandler(PR.createSimpleLexer([],[["kwd",/^-?(?:[_a-z]|\\[\da-f]+ ?)(?:[\w-]|\\\\[\da-f]+ ?)*/i]]),["css-kw"]);PR.registerLangHandler(PR.createSimpleLexer([],[["str",/^[^"')]+/]]),["css-str"]); |
@@ -0,0 +0,0 @@ var q=null;window.PR_SHOULD_USE_CONTINUATION=!0; |
@@ -30,2 +30,5 @@ module.exports = function(grunt) { | ||
// Relaxing | ||
esnext: true, | ||
// Environment | ||
@@ -32,0 +35,0 @@ node: true |
@@ -0,1 +1,5 @@ | ||
### 0.1.1 / 2015-05-29 | ||
* make objects ES6-iterable (implement ECMAScript 6 iteration protocol) | ||
### 0.1.0 / 2015-01-17 | ||
@@ -2,0 +6,0 @@ |
@@ -16,2 +16,4 @@ /** | ||
* <code>v</code> is variable value that changes depending on generator properties (см. {@link module:numgen~NumberGenerator#_value _value}). | ||
* <br> | ||
* Objects are ES6-iterable. | ||
* | ||
@@ -820,4 +822,17 @@ * @param {Object} [initValue] | ||
if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { | ||
NumberGenerator.prototype[Symbol.iterator] = function() { | ||
return this; | ||
}; | ||
NumberGenerator.prototype.next = function() { | ||
return { | ||
done: false, | ||
value: this.getNext() | ||
}; | ||
}; | ||
} | ||
//Exports | ||
module.exports = NumberGenerator; |
{ | ||
"name": "numgen", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "Creates objects that generate number sequences", | ||
@@ -29,7 +29,7 @@ "main": "numgen.js", | ||
"grunt": "~0.4.2", | ||
"grunt-jsdoc": "~0.4.2", | ||
"grunt-contrib-jshint": "~0.7.2", | ||
"grunt-contrib-uglify": "~0.2.7", | ||
"grunt-jsdoc": "~0.6.7", | ||
"grunt-contrib-jshint": "~0.11.2", | ||
"grunt-contrib-uglify": "~0.9.1", | ||
"grunt-umd": "~1.7.0", | ||
"grunt-mocha-cli": "~1.3.0" | ||
"grunt-mocha-cli": "~1.13.0" | ||
}, | ||
@@ -36,0 +36,0 @@ "jam": { |
@@ -7,2 +7,3 @@ # numgen | ||
Creates objects that generate number sequences. | ||
Objects are iterable according to ECMAScript 6 (for example, they can be used in `for-of` loop). | ||
@@ -29,2 +30,6 @@ **Disclaimer:** this package does not have anything common with ECMAScript 6 generators nor with `yield` operator. | ||
### [JSPM](http://jspm.io) | ||
jspm install numgen | ||
### [SPM](http://spmjs.io) | ||
@@ -40,3 +45,3 @@ | ||
### Node, Component, SPM | ||
### Node, Component, JSPM, SPM | ||
@@ -47,2 +52,9 @@ ```js | ||
### [Duo](http://duojs.org) | ||
```js | ||
var NumGen = require("gamtiq/numgen"); | ||
... | ||
``` | ||
### Jam | ||
@@ -56,2 +68,10 @@ | ||
### JSPM | ||
```js | ||
System.import("numgen").then(function(NumGen) { | ||
... | ||
}); | ||
``` | ||
### AMD | ||
@@ -90,2 +110,11 @@ | ||
} | ||
console.log("Next: "); | ||
for (var num of seq) { | ||
nI = seq.getIndex(); | ||
console.log("#", nI, " - ", num); | ||
if (nI > 19) { | ||
break; | ||
} | ||
} | ||
``` | ||
@@ -92,0 +121,0 @@ |
@@ -409,3 +409,32 @@ /*jshint laxbreak:true*/ | ||
}); | ||
if (typeof NumGen.prototype.next === "function") { | ||
describe("next()", function() { | ||
it("should be iterable", function() { | ||
var ng = new NumGen(); | ||
expect( ng[Symbol.iterator] ) | ||
.be.a("function"); | ||
expect( ng[Symbol.iterator]() ) | ||
.equal(ng); | ||
}); | ||
it("should have iterator", function() { | ||
var ng = new NumGen({ | ||
startValue: -1, | ||
valueChange: 3 | ||
}), | ||
iterator = ng[Symbol.iterator](); | ||
expect(iterator.next()) | ||
.eql({done: false, value: 2}); | ||
expect(iterator.next()) | ||
.eql({done: false, value: 5}); | ||
expect(iterator.next()) | ||
.eql({done: false, value: 8}); | ||
expect(iterator.next()) | ||
.eql({done: false, value: 11}); | ||
}); | ||
}); | ||
} | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
1491039
50
13012
125
13