Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

rangegen

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rangegen - npm Package Compare versions

Comparing version 0.2.6 to 0.2.7

examples/example5.js

29

index.js

@@ -125,2 +125,27 @@ /*

};
RangeGen.CRS = RangeGen.createReadStream = function (from, to, step) {
if (typeof exports !== 'undefined' && this.exports !== exports) {
var Readable = require('stream').Readable,
Stream = new Readable;
try {
var iter = new RangeGen.iter(from, to, step, true);
} catch (error) {
var iter = error;
};
Stream._read = function () {
if (iter.constructor === RangeGen) {
if (iter.hasNext()) {
this.push(String(iter.next()));
} else {
this.push(null);
};
} else {
this.emit('error',iter);
};
};
return Stream;
} else {
RangeGen.handleError(RangeGen.Errors("NodeOnly"),true);
};
};
RangeGen.iter = RangeGen.iterator = function (from, to, step, error) {

@@ -155,2 +180,3 @@ var invalid = RangeGen.validate(from,to);

},
constructor: RangeGen,
};

@@ -177,2 +203,3 @@ return (function(){

"NoSuchElement": {name:"NoSuchElement",message:"No more elements left in the iterator!"},
"NodeOnly": {name:"NodeOnly",message:"This function works with node.js only!"},
"Unknown": {name:"UnknownError",message:"An unknown error has occurred!"}

@@ -190,2 +217,2 @@ };

Setup(RangeGen);
})((typeof exports!=="undefined"?function(fn){module.exports=fn;}:function(fn){this["RangeGen"]=fn;}));
})((typeof exports!=='undefined'&&this.exports!==exports?function(fn){module.exports=fn;}:function(fn){this["RangeGen"]=fn;}));

2

package.json
{
"name": "rangegen",
"version": "0.2.6",
"version": "0.2.7",
"homepage": "https://louist.github.io/RangeGen/",

@@ -5,0 +5,0 @@ "author": {

@@ -1,5 +0,5 @@

RangeGen (v0.2.6)
RangeGen (v0.2.7)
======
Install: npm install rangegen
Install: npm install [rangegen](https://www.npmjs.org/package/rangegen "Title")

@@ -13,4 +13,7 @@ This project is [Unlicensed](http://unlicense.org/ "Title").

Generate a range between two numbers or letters. Examples: 1-100, a-z, A-Z, a-zz or even A-ZZZZZ.
Example: [http://louist.github.io/RangeGen/example.html](http://louist.github.io/RangeGen/example.html "Title")
Online example: [http://louist.github.io/RangeGen/example.html](http://louist.github.io/RangeGen/example.html "Title")
View more examples on [GitHub](https://github.com/LouisT/RangeGen/tree/master/examples "Title").
Usage:

@@ -78,3 +81,14 @@ -------

-- Iterators (See "examples2.js" for usage) --
-- Readable stream. (Node.js ONLY, See examples5.js for usage) --
var stream = RangeGen.createReadStream(<from>,<to>[,<step>]);
RangeGen.CRS(<from>,<to>[,<step>]);
From - The letter or number to start the range at. (Number, Float, Letters)
To - The letter or number to end on/near. (Number, Float, Letters)
Step* - The amount to increment or decrement by. Default, 1. (Boolean, Number, Float)
NOTE: If you use this outside of Node.js it will throw a "NodeOnly" error!
Stream API: http://nodejs.org/api/stream.html#stream_class_stream_readable
-- Iterators. (See "examples2.js" for usage) --
var iterator = RangeGen.iterator(<from>,<to>[,<step>[,<exceptions>]]);

@@ -88,191 +102,1 @@ RangeGen.iter(<from>,<to>[,<step>[,<exceptions>]]);

left - The number of iterations left.
Examples:
-------
```javascript
var RangeGen = require('rangegen');
try {
var a = RangeGen("a","z");
console.log("[a-z] "+a.join(",")+"\n");
var b = RangeGen("z","a");
console.log("[z-a] "+b.join(",")+"\n");
var c = RangeGen("A","ZZ",10);
console.log("[A-ZZ,10] "+c.join(",")+"\n");
var d = RangeGen("ZZ","A",10);
console.log("[ZZ-A,10] "+d.join(",")+"\n");
var e = RangeGen(0,100,10);
console.log("[0-100,10] "+e.join(",")+"\n");
var f = RangeGen(100,0,10);
console.log("[100-0,10] "+f.join(",")+"\n");
var g = RangeGen(0,1,0.1);
console.log("[0-1,0.1] "+g.join(",")+"\n");
var h = RangeGen(1,0,0.1);
console.log("[1-0,0.1] "+h.join(",")+"\n");
console.log("\n --- Floats with `map(function(x) { return x.toPrecision(2); })` ---");
console.log("[0-1,0.1] "+g.map(function(x) { return x.toPrecision(2); }).join(",")+"\n");
console.log("[1-0,0.1] "+h.map(function(x) { return x.toPrecision(2); }).join(',')+"\n");
} catch (e) {
console.log(e);
};
console.log("\n--- Throw errors! ---");
try {
RangeGen("a",100,1,true);
} catch (e) {
console.log("[a-100] "+e+"\n");
};
try {
RangeGen(100,"z",1,true);
} catch (e) {
console.log("[100-a] "+e+"\n");
};
try {
console.log(RangeGen("@","!",1,true));
} catch (e) {
console.log("[@-!] "+e+"\n");
};
try {
console.log(RangeGen("a","!",1,true));
} catch (e) {
console.log("[a-!] "+e+"\n");
};
console.log("\n--- Return empty arrays! ---");
console.log(RangeGen("a","100"));
console.log(RangeGen("100","z"));
console.log(RangeGen("@","!"));
console.log(RangeGen("a","!"));
```
```javascript
var RangeGen = require('rangegen');
try {
var iterator = RangeGen.iter(-30,30,1,true);
console.log("Iterations: "+iterator.length);
var range = [];
while (iterator.hasNext()) {
range.push(iterator.next());
};
console.log(range.join(','));
var iterator = RangeGen.iter(0,1,0.1,true);
console.log("Iterations: "+iterator.length);
var range = [];
while (iterator.hasNext()) {
range.push(iterator.next());
};
console.log(range.join(','));
} catch (e) {
console.log(e);
};
console.log("\n--- Throw errors! ---");
try {
console.log("- Invalid next() call. -");
var iterator = RangeGen.iterator(-30,30,1,true);
console.log("Iterations: "+iterator.length);
var range = [];
while (iterator.hasNext()) {
range.push(iterator.next());
};
iterator.next();
} catch (e) {
console.log(e);
};
try {
console.log("\n- Invalid range. [a-30] -");
var iterator = RangeGen.iterator("a",30,1,true);
} catch (e) {
console.log(e);
};
console.log("\n--- Return false! ---");
try {
var iterator = RangeGen.iterator("a",30,1);
if (!iterator) {
console.log("`iterator` is false!");
}
} catch (e) {
console.log(e);
};
```
```html
<html>
<head>
<title>RangeGen test</title>
<script src="./rangegen.js"></script>
<script>
window.onload = function () {
try {
var a = RangeGen("a","z");
output("[a-z] "+a.join(",")+"\n");
var b = RangeGen("z","a");
output("[z-a] "+b.join(",")+"\n");
var c = RangeGen("A","ZZ",10);
output("[A-ZZ,10] "+c.join(",")+"\n");
var d = RangeGen("ZZ","A",10);
output("[ZZ-A,10] "+d.join(",")+"\n");
var e = RangeGen(0,100,10);
output("[0-100,10] "+e.join(",")+"\n");
var f = RangeGen(100,0,10);
output("[100-0,10] "+f.join(",")+"\n");
var g = RangeGen(0,1,0.1);
output("[0-1,0.1] "+g.join(",")+"\n");
var h = RangeGen(1,0,0.1);
output("[1-0,0.1] "+h.join(",")+"\n");
output("<br /> --- Floats with `map(function(x) { return x.toPrecision(2); })` ---");
output("[0-1,0.1] "+g.map(function(x) { return x.toPrecision(2); }).join(",")+"\n");
output("[1-0,0.1] "+h.map(function(x) { return x.toPrecision(2); }).join(',')+"\n");
} catch (e) {
output(e);
};
try {
var iterator = RangeGen.iter(-30,30,5,true);
output("<br />Iterations: "+iterator.length);
var range = [];
while (iterator.hasNext()) {
range.push(iterator.next());
};
output(range.join(','));
} catch (e) {
output(e);
};
};
function output (x) {
document.getElementById("output").innerHTML += x+"<br />";
};
</script>
</head>
<body>
<div id="output"></div>
</body>
</html>
```
```javascript
var range = require('../');
try {
console.log("--- As a callback ---");
range(1,10,3,null,function (x) { console.log(x.join(',')) });
console.log("\n--- As a filter ---");
console.log(range(1,100,3,null,function (x) { return x.filter(function(y) { return y%4===0; }); }).join(','));
console.log("\n-- inRange examples --");
console.log("[c in a..z] "+range.inRange('c','a','z'));
console.log("[aa in a..z] "+range.inRange('aa','a','z'));
console.log("[ab in a..az] "+range.inRange('ab','a','az'));
console.log("[ab in a..zz, 5] "+range.inRange('ab','a','az',5));
console.log("[cjsr in a..zzzzzzz] "+range.inRange('cjsr','a','zzzzzzz'));
console.log("[zzzzzzz in a..zzzzz] "+range.inRange('zzzzzzz','a','zzzzz'));
console.log("\n-- byIndex examples --");
console.log("[10 in a..z] "+range.byIndex(10,"a","z"));
console.log("[100 in a..zz] "+range.byIndex(100,"a","zz"));
console.log("[26 in a..z] "+range.byIndex(26,"a","z"));
console.log("\n-- byValue examples --");
console.log("[g in a..z] "+range.byValue("g","a","z"));
console.log("[g in a..z, 2] "+range.byValue("g","a","z",2));
console.log("[g in a..z, 5] "+range.byValue("g","a","z",5));
console.log("\n-- String prototype examples --");
range.addPro(); // Inject range();
console.log("[\"a..z\".range()] "+"a..z".range());
console.log("[\"z..a\".range()] "+"z..a".range());
console.log("[\"a..zz\".range(40)] "+"a..zz".range(40));
console.log("[\"0..100\".range(5)] "+"0..100".range(5));
console.log("[\"-30..30\".range()] "+"-30..30".range(5));
} catch (e) {
console.log(e);
};
```
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc