Comparing version 0.4.0 to 0.4.1
@@ -26,3 +26,3 @@ var ret = require('ret'); | ||
return !this.randInt(0, 1); | ||
}; | ||
} | ||
@@ -41,20 +41,6 @@ | ||
return arr[this.randInt(0, arr.length - 1)]; | ||
}; | ||
} | ||
/** | ||
* Determines if a character code is alphabetic and decide | ||
* to switch case randomly. | ||
* | ||
* @param {Number} code | ||
* @param {Boolean} ignoreCase | ||
* @return {String} | ||
*/ | ||
function char(code, ignoreCase) { | ||
code = ignoreCase && randBool.call(this) ? toOtherCase(code) : code; | ||
return String.fromCharCode(code); | ||
}; | ||
/** | ||
* expands a token to a DiscontinuousRange of characters which has a | ||
@@ -72,3 +58,13 @@ * length and an index function (for random selecting) | ||
for (var i = 0; i < token.set.length; i++) { | ||
drange.add(expand.call(this, token.set[i])); | ||
var subrange = expand.call(this, token.set[i]); | ||
drange.add(subrange); | ||
if (this.ignoreCase) { | ||
for (var j = 0; j < subrange.length; j++) { | ||
var code = subrange.index(j); | ||
var otherCaseCode = toOtherCase(code); | ||
if (code !== otherCaseCode) { | ||
drange.add(otherCaseCode); | ||
} | ||
} | ||
} | ||
} | ||
@@ -82,3 +78,3 @@ if (token.not) { | ||
throw new Error('unexpandable token type: ' + token.type); | ||
}; | ||
} | ||
@@ -161,6 +157,2 @@ | ||
/** | ||
@@ -200,3 +192,4 @@ * Randomly generates and returns a number between a and b (inclusive). | ||
stack = token.options ? randSelect.call(this, token.options) : token.stack; | ||
stack = token.options ? | ||
randSelect.call(this, token.options) : token.stack; | ||
@@ -220,11 +213,7 @@ str = ''; | ||
case types.SET: | ||
var expanded_set = expand.call(this, token); | ||
if (!expanded_set.length) return ''; | ||
return char.call(this, randSelect.call(this, expanded_set), this.ignoreCase); | ||
return String.fromCharCode(randSelect.call(this, expanded_set)); | ||
case types.RANGE: | ||
return char.call(this, this.randInt(token.from, token.to), this.ignoreCase); | ||
case types.REPETITION: | ||
@@ -248,3 +237,5 @@ // Randomly generate number between min and max. | ||
case types.CHAR: | ||
return char.call(this, token.value, this.ignoreCase); | ||
var code = this.ignoreCase && randBool.call(this) ? | ||
toOtherCase(token.value) : token.value; | ||
return String.fromCharCode(code); | ||
} | ||
@@ -251,0 +242,0 @@ } |
{ | ||
"name": "randexp", | ||
"description": "Create random strings that match a given regular expression.", | ||
"keywords": ["regex", "regexp", "regular expression", "random", "test"], | ||
"version": "0.4.0", | ||
"keywords": [ | ||
"regex", | ||
"regexp", | ||
"regular expression", | ||
"random", | ||
"test" | ||
], | ||
"version": "0.4.1", | ||
"homepage": "http://fent.github.io/randexp.js/", | ||
@@ -24,8 +30,17 @@ "repository": { | ||
"devDependencies": { | ||
"mocha": "x" | ||
"browserify": "^11.1.0", | ||
"gulp": "^3.9.0", | ||
"gulp-header": "^1.7.1", | ||
"gulp-insert": "^0.5.0", | ||
"gulp-uglify": "^1.4.1", | ||
"mocha": "x", | ||
"vinyl-buffer": "^1.0.0", | ||
"vinyl-source-stream": "^1.1.0" | ||
}, | ||
"licenses": [ { | ||
"type": "MIT", | ||
"url" : "http://github.com/fent/randexp.js/raw/master/LICENSE" | ||
}] | ||
"licenses": [ | ||
{ | ||
"type": "MIT", | ||
"url": "http://github.com/fent/randexp.js/raw/master/LICENSE" | ||
} | ||
] | ||
} |
@@ -1,7 +0,9 @@ | ||
# randexp.js [![Build Status](https://secure.travis-ci.org/fent/randexp.js.png)](http://travis-ci.org/fent/randexp.js) | ||
# randexp.js | ||
randexp will generate a random string that matches a given RegExp Javascript object. | ||
[![Build Status](https://secure.travis-ci.org/fent/randexp.js.png)](http://travis-ci.org/fent/randexp.js) [![Dependency Status](https://gemnasium.com/fent/randexp.js.svg)](https://gemnasium.com/fent/randexp.js) | ||
# Usage | ||
```js | ||
@@ -49,4 +51,4 @@ var RandExp = require('randexp'); | ||
# Motivation | ||
# Motivation | ||
Regular expressions are used in every language, every programmer is familiar with them. Regex can be used to easily express complex strings. What better way to generate a random string than with a tool you can easily use to express the string any way you want? | ||
@@ -56,4 +58,4 @@ | ||
# Default Range | ||
# Default Range | ||
The default generated character range includes printable ASCII. In order to add or remove characters, | ||
@@ -74,3 +76,2 @@ a `defaultRange` attribute is exposed. you can `subtract(from, to)` and `add(from, to)` | ||
# Infinite Repetitionals | ||
@@ -93,2 +94,3 @@ | ||
# Bad Regular Expressions | ||
There are some regular expressions which can never match any string. | ||
@@ -104,2 +106,3 @@ | ||
# Install | ||
### Node.js | ||
@@ -115,2 +118,3 @@ | ||
# Tests | ||
Tests are written with [mocha](http://visionmedia.github.com/mocha/) | ||
@@ -124,2 +128,3 @@ | ||
# License | ||
MIT |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
22640
12
512
124
8