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

verbal-expressions

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

verbal-expressions - npm Package Compare versions

Comparing version 0.2.1 to 0.3.0

.editorconfig

340

dist/verbalexpressions.js
/*!
* VerbalExpressions JavaScript Library v0.2.1
* VerbalExpressions JavaScript Library v0.3.0
* https://github.com/VerbalExpressions/JSVerbalExpressions

@@ -8,8 +8,8 @@ *

* http://opensource.org/licenses/MIT
*
* Date: 2013-07-19
*
*/
// Define the collection class.
/**
* Define the VerbalExpression class.
* @class
*/
(function verbalExpressionIIFE(root) {

@@ -19,3 +19,8 @@ // Constants

// I am the constructor function.
/**
* I am the constructor function.
* @constructor
* @alias VerEx
* @return {RegExp} A new instance of RegExp with injected methods
*/
function VerbalExpression() {

@@ -31,3 +36,6 @@ var verbalExpression = new RegExp();

// Define the static methods.
/**
* @param {RegExp} verbalExpression An instance of RegExp on which to add VerbalExpressions methods
* @return {RegExp} A new instance of RegExp with injected methods
*/
VerbalExpression.injectClassMethods = function injectClassMethods(verbalExpression) {

@@ -47,3 +55,5 @@ var method;

// Define the class methods.
/**
* Define the class methods.
*/
VerbalExpression.prototype = {

@@ -57,4 +67,7 @@ // Variables to hold the whole

// Sanitation function for adding
// anything safely to the expression
/**
* Sanitation function for adding anything safely to the expression
* @param {String} value string to sanitize
* @return {String} sanitized value
*/
sanitize: function sanitize(value) {

@@ -79,6 +92,7 @@ var reRegExpEscape;

// Function to add stuff to the
// expression. Also compiles the
// new expression so it's ready to
// be used.
/**
* Function to add stuff to the expression. Also compiles the new expression so it's ready to be used.
* @param {string} value literal expression, not sanitized
* @return {VerbalExpression} Freshly recompiled instance of VerbalExpression
*/
add: function add(value) {

@@ -91,35 +105,39 @@ this._source += value || '';

// Start and end of line functions
/**
* Control start-of-line matching
* @param {Boolean} enable Control start-of-line matching
* @return {VerbalExpression} Same instance of VerbalExpression to allow method chaining
*/
startOfLine: function startOfLine(enable) {
enable = (enable !== false);
this._prefixes = enable ? '^' : '';
this.add();
return this;
return this.add();
},
/**
* Control end-of-line matching
* @param {Boolean} enable Control end-of-line matching
* @return {VerbalExpression} Same instance of VerbalExpression to allow method chaining
*/
endOfLine: function endOfLine(enable) {
enable = (enable !== false);
this._suffixes = enable ? '$' : '';
this.add();
return this;
return this.add();
},
// We try to keep the syntax as
// user-friendly as possible.
// So we can use the "normal"
// behaviour to split the "sentences"
// naturally.
/**
* We try to keep the syntax as user-friendly as possible. So we can use the "normal" behaviour to split the "sentences" naturally.
* @param {String} value value to find
* @return {VerbalExpression} Same instance of VerbalExpression to allow method chaining
*/
then: function then(value) {
value = this.sanitize(value);
this.add('(?:' + value + ')');
return this;
return this.add('(?:' + value + ')');
},
// And because we can't start with
// "then" function, we create an alias
// to be used as the first function
// of the chain.
/**
* And because we can't start with "then" function, we create an alias to be used as the first function of the chain.
* @param {String} value value to find
* @return {VerbalExpression} Same instance of VerbalExpression to allow method chaining
*/
find: function find(value) {

@@ -129,43 +147,55 @@ return this.then(value);

// Maybe is used to add values with ?
/*
* Maybe is used to add values with ?
* @param {String} value value to find
* @return {VerbalExpression} Same instance of VerbalExpression to allow method chaining
*/
maybe: function maybe(value) {
value = this.sanitize(value);
this.add('(?:' + value + ')?');
return this;
return this.add('(?:' + value + ')?');
},
// Any character any number of times
/**
* Any character any number of times
* @param {String} value value to find
* @return {VerbalExpression} Same instance of VerbalExpression to allow method chaining
*/
anything: function anything() {
this.add('(?:.*)');
return this;
return this.add('(?:.*)');
},
// Anything but these characters
/**
* Anything but these characters
* @param {String} value value to find
* @return {VerbalExpression} Same instance of VerbalExpression to allow method chaining
*/
anythingBut: function anythingBut(value) {
value = this.sanitize(value);
this.add('(?:[^' + value + ']*)');
return this;
return this.add('(?:[^' + value + ']*)');
},
// Any character at least one time
/**
* Any character at least one time
* @return {VerbalExpression} Same instance of VerbalExpression to allow method chaining
*/
something: function something() {
this.add('(?:.+)');
return this;
return this.add('(?:.+)');
},
// Any character at least one time except for these characters
/**
* Any character at least one time except for these characters
* @param {String} value value to find
* @return {VerbalExpression} Same instance of VerbalExpression to allow method chaining
*/
somethingBut: function somethingBut(value) {
value = this.sanitize(value);
this.add('(?:[^' + value + ']+)');
return this;
return this.add('(?:[^' + value + ']+)');
},
// Shorthand function for the
// String.replace function to
// give more logical flow if, for
// example, we're doing multiple
// replacements on one regexp.
/**
* Shorthand function for the String.replace function to give more logical flow if, for example, we're doing multiple replacements on one regexp.
* @param {String} source string to search for
* @param {String} value value to replace with
* @return {VerbalExpression} Same instance of VerbalExpression to allow method chaining
*/
replace: function replace(source, value) {

@@ -179,9 +209,14 @@ source = source.toString();

// Line break
/**
* Line break
* @return {VerbalExpression} Same instance of VerbalExpression to allow method chaining
*/
lineBreak: function lineBreak() {
this.add('(?:\\r\\n|\\r|\\n)'); // Unix + Windows CRLF
return this;
return this.add('(?:\\r\\n|\\r|\\n)'); // Unix + Windows CRLF
},
// And a shorthand for html-minded
/**
* And a shorthand for html-minded
* @return {VerbalExpression} Same instance of VerbalExpression to allow method chaining
*/
br: function br() {

@@ -191,29 +226,50 @@ return this.lineBreak();

// Tab (duh?)
/**
* Tab (duh?)
* @return {VerbalExpression} Same instance of VerbalExpression to allow method chaining
*/
tab: function tab() {
this.add('\\t');
return this;
return this.add('\\t');
},
// Any alphanumeric
/**
* Any alphanumeric
* @return {VerbalExpression} Same instance of VerbalExpression to allow method chaining
*/
word: function word() {
this.add('\\w+');
return this.add('\\w+');
},
/**
* Any digit
* @return {VerbalExpression} Same instance of VerbalExpression to allow method chaining
*/
digit: function digit() {
this.add('\\d');
return this;
},
// Any whitespace
/**
* Any whitespace
* @return {VerbalExpression} Same instance of VerbalExpression to allow method chaining
*/
whitespace: function whitespace() {
this.add('\\s');
return this;
return this.add('\\s');
},
// Any given character
/**
* Any given character
* @param {String} value value to find
* @return {VerbalExpression} Same instance of VerbalExpression to allow method chaining
*/
anyOf: function anyOf(value) {
value = this.sanitize(value);
this.add('[' + value + ']');
return this;
return this.add('[' + value + ']');
},
// Shorthand
/**
* Shorthand
* @param {String} value value to find
* @return {VerbalExpression} Same instance of VerbalExpression to allow method chaining
*/
any: function any(value) {

@@ -223,3 +279,6 @@ return this.anyOf(value);

// Usage: .range( from, to [, from, to ... ] )
/**
* Usage: .range( from, to [, from, to ... ] )
* @return {VerbalExpression} Same instance of VerbalExpression to allow method chaining
*/
range: function range() {

@@ -245,5 +304,3 @@ var length = arguments.length;

this.add(buffer.join(''));
return this;
return this.add(buffer.join(''));
},

@@ -253,3 +310,7 @@

// Modifier abstraction
/**
* Modifier abstraction
* @param {String} modifier modifier to add
* @return {VerbalExpression} Same instance of VerbalExpression to allow method chaining
*/
addModifier: function addModifier(modifier) {

@@ -260,58 +321,46 @@ if (this._modifiers.indexOf(modifier) === -1) {

this.add();
return this;
return this.add();
},
/**
* Remove modifier
* @param {String} modifier modifier to remove
* @return {VerbalExpression} Same instance of VerbalExpression to allow method chaining
*/
removeModifier: function removeModifier(modifier) {
this._modifiers = this._modifiers.replace(modifier, '');
this.add();
return this;
return this.add();
},
// Case-insensitivity modifier
/**
* Case-insensitivity modifier
* @param {Boolean} enable Control case-insensitive matching
* @return {VerbalExpression} Same instance of VerbalExpression to allow method chaining
*/
withAnyCase: function withAnyCase(enable) {
if (enable !== false) {
this.addModifier('i');
} else {
this.removeModifier('i');
}
this.add();
return this;
return enable !== false ? this.addModifier('i') : this.removeModifier('i');
},
// Default behaviour is with "g" modifier,
// so we can turn this another way around
// than other modifiers
/**
* Default behaviour is with "g" modifier, so we can turn this another way around than other modifiers
* @param {Boolean} enable Control global matching
* @return {VerbalExpression} Same instance of VerbalExpression to allow method chaining
*/
stopAtFirst: function stopAtFirst(enable) {
if (enable !== false) {
this.removeModifier('g');
} else {
this.addModifier('g');
}
this.add();
return this;
return enable !== false ? this.removeModifier('g') : this.addModifier('g');
},
// Multiline, also reversed
/**
* Multiline, also reversed
* @param {Boolean} enable Control multi-line matching
* @return {VerbalExpression} Same instance of VerbalExpression to allow method chaining
*/
searchOneLine: function searchOneLine(enable) {
if (enable !== false) {
this.removeModifier('m');
} else {
this.addModifier('m');
}
this.add();
return this;
return enable !== false ? this.removeModifier('m') : this.addModifier('m');
},
// Repeats the previous item
// exactly n times or
// between n and m times.
/**
* Repeats the previous item exactly n times or between n and m times.
* @return {VerbalExpression} Same instance of VerbalExpression to allow method chaining
*/
repeatPrevious: function repeatPrevious() {

@@ -337,11 +386,11 @@ var value;

this.add(value);
return (this);
return this.add(value);
},
// Repeats the previous at least once
/**
* Repeats the previous at least once
* @return {VerbalExpression} Same instance of VerbalExpression to allow method chaining
*/
oneOrMore: function oneOrMore() {
this.add('+');
return (this);
return this.add('+');
},

@@ -351,2 +400,7 @@

/**
* Matches the value zero or more times
* @param {String} value value to find
* @return {VerbalExpression} Same instance of VerbalExpression to allow method chaining
*/
multiple: function multiple(value) {

@@ -367,3 +421,7 @@ // Use expression or string

// Adds alternative expressions
/**
* Adds alternative expressions
* @param {String} value value to find
* @return {VerbalExpression} Same instance of VerbalExpression to allow method chaining
*/
or: function or(value) {

@@ -381,27 +439,35 @@ this._prefixes += '(?:';

// Starts a capturing group
/**
* Starts a capturing group
* @return {VerbalExpression} Same instance of VerbalExpression to allow method chaining
*/
beginCapture: function beginCapture() {
// Add the end of the capture group to the suffixes for now so compilation continues to work
this._suffixes += ')';
this.add('(');
return this;
return this.add('(');
},
// Ends a capturing group
/**
* Ends a capturing group
* @return {VerbalExpression} Same instance of VerbalExpression to allow method chaining
*/
endCapture: function endCapture() {
// Remove the last parentheses from the _suffixes and add to the regex itself
this._suffixes = this._suffixes.substring(0, this._suffixes.length - 1);
this.add(')');
return this;
return this.add(')');
},
// Convert to RegExp object
/**
* Convert to RegExp object
* @return {RegExp} Converted RegExp instance
*/
toRegExp: function toRegExp() {
var array = this.toString().match(/\/(.*)\/([gimuy]+)?/);
return new RegExp(array[1], array[2]);
},
}
};
/**
* @return {VerbalExpression} Returns a new instance of VerbalExpressions
*/
function createVerbalExpression() {

@@ -425,2 +491,2 @@ return new VerbalExpression();

}
})(this);
}(this));
/*!
* verbal-expressions JavaScript Library v0.2.1
* verbal-expressions JavaScript Library v0.3.0
* https://github.com/VerbalExpressions/JSVerbalExpressions

@@ -7,9 +7,8 @@ *

* Released under the MIT license
* http://opensource.org/licenses/MIT
*
* Date: 2016-01-22
* Date: 2017-01-14
*
*/
!function(a){function b(){var a=new RegExp;return b.injectClassMethods(a),a}function c(){return new b}var d="VerEx";b.injectClassMethods=function(a){var c;for(c in b.prototype)b.prototype.hasOwnProperty(c)&&(a[c]=b.prototype[c]);return a},b.prototype={_prefixes:"",_source:"",_suffixes:"",_modifiers:"gm",sanitize:function(a){var b;return a.source?a.source:"number"==typeof a?a:(b=/([\].|*?+(){}^$\\:=[])/g,a.replace(b,"\\$&"))},add:function(a){return this._source+=a||"",this.compile(this._prefixes+this._source+this._suffixes,this._modifiers),this},startOfLine:function(a){return a=a!==!1,this._prefixes=a?"^":"",this.add(),this},endOfLine:function(a){return a=a!==!1,this._suffixes=a?"$":"",this.add(),this},then:function(a){return a=this.sanitize(a),this.add("(?:"+a+")"),this},find:function(a){return this.then(a)},maybe:function(a){return a=this.sanitize(a),this.add("(?:"+a+")?"),this},anything:function(){return this.add("(?:.*)"),this},anythingBut:function(a){return a=this.sanitize(a),this.add("(?:[^"+a+"]*)"),this},something:function(){return this.add("(?:.+)"),this},somethingBut:function(a){return a=this.sanitize(a),this.add("(?:[^"+a+"]+)"),this},replace:function(a,b){return a=a.toString(),a.replace(this,b)},lineBreak:function(){return this.add("(?:\\r\\n|\\r|\\n)"),this},br:function(){return this.lineBreak()},tab:function(){return this.add("\\t"),this},word:function(){return this.add("\\w+"),this},whitespace:function(){return this.add("\\s"),this},anyOf:function(a){return a=this.sanitize(a),this.add("["+a+"]"),this},any:function(a){return this.anyOf(a)},range:function(){var a,b,c=arguments.length,d=new Array(c/2),e=0,f=0;for(d[e++]="[";c>f;)a=this.sanitize(arguments[f++]),b=this.sanitize(arguments[f++]),d[e++]=a+"-"+b;return d[e++]="]",this.add(d.join("")),this},addModifier:function(a){return-1===this._modifiers.indexOf(a)&&(this._modifiers+=a),this.add(),this},removeModifier:function(a){return this._modifiers=this._modifiers.replace(a,""),this.add(),this},withAnyCase:function(a){return a!==!1?this.addModifier("i"):this.removeModifier("i"),this.add(),this},stopAtFirst:function(a){return a!==!1?this.removeModifier("g"):this.addModifier("g"),this.add(),this},searchOneLine:function(a){return a!==!1?this.removeModifier("m"):this.addModifier("m"),this.add(),this},repeatPrevious:function(){var a,b=/\d+/,c=arguments.length,d=new Array(c),e=0,f=0;for(e=0;c>e;e++)b.test(arguments[e])&&(d[f++]=arguments[e]);return f>0&&(d.length=f,a="{"+d.join(",")+"}"),this.add(a),this},oneOrMore:function(){return this.add("+"),this},multiple:function(a){return a=a.source||this.sanitize(a),1===arguments.length&&this.add("(?:"+a+")*"),arguments.length>1&&(this.add("(?:"+a+")"),this.add("{"+arguments[1]+"}")),this},or:function(a){return this._prefixes+="(?:",this._suffixes=")"+this._suffixes,this.add(")|(?:"),a&&this.then(a),this},beginCapture:function(){return this._suffixes+=")",this.add("("),this},endCapture:function(){return this._suffixes=this._suffixes.substring(0,this._suffixes.length-1),this.add(")"),this},toRegExp:function(){var a=this.toString().match(/\/(.*)\/([gimuy]+)?/);return new RegExp(a[1],a[2])}},"undefined"!=typeof module&&module.exports?module.exports=c:"function"==typeof define&&define.amd?define(d,[],function(){return b}):a[d]=c}(this);
!function(a){function b(){var a=new RegExp;return b.injectClassMethods(a),a}function c(){return new b}var d="VerEx";b.injectClassMethods=function(a){var c;for(c in b.prototype)b.prototype.hasOwnProperty(c)&&(a[c]=b.prototype[c]);return a},b.prototype={_prefixes:"",_source:"",_suffixes:"",_modifiers:"gm",sanitize:function(a){var b;return a.source?a.source:"number"==typeof a?a:(b=/([\].|*?+(){}^$\\:=[])/g,a.replace(b,"\\$&"))},add:function(a){return this._source+=a||"",this.compile(this._prefixes+this._source+this._suffixes,this._modifiers),this},startOfLine:function(a){return a=a!==!1,this._prefixes=a?"^":"",this.add()},endOfLine:function(a){return a=a!==!1,this._suffixes=a?"$":"",this.add()},then:function(a){return a=this.sanitize(a),this.add("(?:"+a+")")},find:function(a){return this.then(a)},maybe:function(a){return a=this.sanitize(a),this.add("(?:"+a+")?")},anything:function(){return this.add("(?:.*)")},anythingBut:function(a){return a=this.sanitize(a),this.add("(?:[^"+a+"]*)")},something:function(){return this.add("(?:.+)")},somethingBut:function(a){return a=this.sanitize(a),this.add("(?:[^"+a+"]+)")},replace:function(a,b){return a=a.toString(),a.replace(this,b)},lineBreak:function(){return this.add("(?:\\r\\n|\\r|\\n)")},br:function(){return this.lineBreak()},tab:function(){return this.add("\\t")},word:function(){return this.add("\\w+")},digit:function(){return this.add("\\d"),this},whitespace:function(){return this.add("\\s")},anyOf:function(a){return a=this.sanitize(a),this.add("["+a+"]")},any:function(a){return this.anyOf(a)},range:function(){var a,b,c=arguments.length,d=new Array(c/2),e=0,f=0;for(d[e++]="[";f<c;)a=this.sanitize(arguments[f++]),b=this.sanitize(arguments[f++]),d[e++]=a+"-"+b;return d[e++]="]",this.add(d.join(""))},addModifier:function(a){return this._modifiers.indexOf(a)===-1&&(this._modifiers+=a),this.add()},removeModifier:function(a){return this._modifiers=this._modifiers.replace(a,""),this.add()},withAnyCase:function(a){return a!==!1?this.addModifier("i"):this.removeModifier("i")},stopAtFirst:function(a){return a!==!1?this.removeModifier("g"):this.addModifier("g")},searchOneLine:function(a){return a!==!1?this.removeModifier("m"):this.addModifier("m")},repeatPrevious:function(){var a,b=/\d+/,c=arguments.length,d=new Array(c),e=0,f=0;for(e=0;e<c;e++)b.test(arguments[e])&&(d[f++]=arguments[e]);return f>0&&(d.length=f,a="{"+d.join(",")+"}"),this.add(a)},oneOrMore:function(){return this.add("+")},multiple:function(a){return a=a.source||this.sanitize(a),1===arguments.length&&this.add("(?:"+a+")*"),arguments.length>1&&(this.add("(?:"+a+")"),this.add("{"+arguments[1]+"}")),this},or:function(a){return this._prefixes+="(?:",this._suffixes=")"+this._suffixes,this.add(")|(?:"),a&&this.then(a),this},beginCapture:function(){return this._suffixes+=")",this.add("(")},endCapture:function(){return this._suffixes=this._suffixes.substring(0,this._suffixes.length-1),this.add(")")},toRegExp:function(){var a=this.toString().match(/\/(.*)\/([gimuy]+)?/);return new RegExp(a[1],a[2])}},"undefined"!=typeof module&&module.exports?module.exports=c:"function"==typeof define&&define.amd?define(d,[],function(){return b}):a[d]=c}(this);
//# sourceMappingURL=verbalexpressions.min.js.map

@@ -30,4 +30,3 @@ module.exports = function gruntConfig(grunt) {

'*\n' +
'* Released under the <%= pkg.license.type %> license\n' +
'* <%= pkg.license.url %>\n' +
'* Released under the <%= pkg.license %> license\n' +
'*\n' +

@@ -56,2 +55,23 @@ '* Date: <%= grunt.template.today("yyyy-mm-dd") %>\n' +

},
jsdoc: {
options: {
pedantic: true,
verbose: true,
readme: 'README.md',
package: 'package.json',
},
src: {
options: {
destination: 'docs',
},
src: ['VerbalExpressions.js'],
},
dist: {
options: {
destination: 'dist/docs',
},
src: ['dist/verbalexpressions.js'],
},
},
});

@@ -63,2 +83,3 @@

grunt.loadNpmTasks('grunt-eslint');
grunt.loadNpmTasks('grunt-jsdoc');
grunt.loadNpmTasks('grunt-sourcemap-localize');

@@ -68,3 +89,4 @@

grunt.registerTask('default', ['qunit']);
grunt.registerTask('build', ['qunit', 'copy', 'uglify', 'sourcemap_localize']);
grunt.registerTask('build', ['test', 'copy', 'uglify', 'sourcemap_localize', 'jsdoc:dist']);
grunt.registerTask('docs', ['test', 'jsdoc:src']);
};
{
"name": "verbal-expressions",
"description": "JavaScript Regular expressions made easy",
"version": "0.2.1",
"version": "0.3.0",
"keywords": [

@@ -11,9 +11,11 @@ "regular expressions",

"devDependencies": {
"eslint": "^1.10.3",
"eslint-config-airbnb": "^3.1.0",
"eslint": "^2.5.1",
"eslint-config-airbnb": "^6.2.0",
"grunt": "^0.4.2",
"grunt-contrib-copy": "^0.8.2",
"grunt-contrib-qunit": "^0.7.0",
"grunt-contrib-uglify": "^0.11.0",
"grunt-eslint": "^17.3.1",
"grunt-cli": "^1.2.0",
"grunt-contrib-copy": "^1.0.0",
"grunt-contrib-qunit": "^1.0.1",
"grunt-contrib-uglify": "^1.0.1",
"grunt-eslint": "^18.0.0",
"grunt-jsdoc": "^1.1.0",
"grunt-sourcemap-localize": "^0.1.0"

@@ -29,6 +31,11 @@ },

"main": "VerbalExpressions.js",
"license": {
"type": "MIT",
"url": "http://opensource.org/licenses/MIT"
"license": "MIT",
"scripts": {
"grunt": "grunt",
"test": "grunt test",
"test:verbose": "grunt test --verbose",
"build": "grunt build",
"docs": "grunt docs"
},
"types": "./typings/verbalexpression.d.ts",
"engines": {

@@ -35,0 +42,0 @@ "node": ">= 0.8.0"

@@ -1,2 +0,2 @@

VerbalExpressions v0.2.1
VerbalExpressions v0.3.0
=====================

@@ -9,19 +9,2 @@

## Other Implementations
You can see an up to date list of all ports on [VerbalExpressions.github.io](http://VerbalExpressions.github.io).
- [Ruby](https://github.com/ryan-endacott/verbal_expressions)
- [C#](https://github.com/VerbalExpressions/CSharpVerbalExpressions)
- [Python](https://github.com/VerbalExpressions/PythonVerbalExpressions)
- [Java](https://github.com/VerbalExpressions/JavaVerbalExpressions)
- [Groovy](https://github.com/VerbalExpressions/GroovyVerbalExpressions)
- [PHP](https://github.com/VerbalExpressions/PHPVerbalExpressions)
- [Haskell](https://github.com/VerbalExpressions/HaskellVerbalExpressions)
- [Haxe](https://github.com/VerbalExpressions/HaxeVerbalExpressions)
- [C++](https://github.com/VerbalExpressions/CppVerbalExpressions)
- [Objective-C](https://github.com/VerbalExpressions/ObjectiveCVerbalExpressions)
- [Perl](https://github.com/VerbalExpressions/PerlVerbalExpressions)
- [Swift](https://github.com/VerbalExpressions/SwiftVerbalExpressions)
If you would like to contribute another port (which would be awesome!), please open an issue specifying the language. A repo in the [VerbalExpressions organization](https://github.com/VerbalExpressions) will be created for it. Please don't open PRs for other languages against this repo.
## How to get started

@@ -45,5 +28,5 @@ ### In the browser

$ grunt
$ npm run grunt
(or)
$ grunt test
$ npm test

@@ -54,3 +37,3 @@ ## Creating a minified version

$ grunt build
$ npm run build

@@ -137,1 +120,18 @@ A source map will also be created in the same folder, so you can use the original unminified source file (copied to _dist_ as well) for debugging purposes.

[extending]:http://www.bennadel.com/blog/2292-extending-javascript-arrays-while-keeping-native-bracket-notation-functionality.htm
## Other Implementations
You can see an up to date list of all ports on [VerbalExpressions.github.io](http://VerbalExpressions.github.io).
- [Ruby](https://github.com/ryan-endacott/verbal_expressions)
- [C#](https://github.com/VerbalExpressions/CSharpVerbalExpressions)
- [Python](https://github.com/VerbalExpressions/PythonVerbalExpressions)
- [Java](https://github.com/VerbalExpressions/JavaVerbalExpressions)
- [Groovy](https://github.com/VerbalExpressions/GroovyVerbalExpressions)
- [PHP](https://github.com/VerbalExpressions/PHPVerbalExpressions)
- [Haskell](https://github.com/VerbalExpressions/HaskellVerbalExpressions)
- [Haxe](https://github.com/VerbalExpressions/HaxeVerbalExpressions)
- [C++](https://github.com/VerbalExpressions/CppVerbalExpressions)
- [Objective-C](https://github.com/VerbalExpressions/ObjectiveCVerbalExpressions)
- [Perl](https://github.com/VerbalExpressions/PerlVerbalExpressions)
- [Swift](https://github.com/VerbalExpressions/SwiftVerbalExpressions)
If you would like to contribute another port (which would be awesome!), please open an issue specifying the language. A repo in the [VerbalExpressions organization](https://github.com/VerbalExpressions) will be created for it. Please don't open PRs for other languages against this repo.

@@ -220,1 +220,30 @@ /* eslint-disable new-cap */

});
test('word', function multipleTest() {
var testRegex = VerEx().word();
var testString = 'azertyuiopqsdfghjklmwxcvbn0123456789_';
var i;
var len;
ok(testRegex.test(testString), 'Should match word');
testString = '. @[]|,&~-';
for (i = 0, len = testString.length; i < len; i++) {
ok(!testRegex.test(testString[i]), 'Should not match word (' + testString[i] + ')');
}
});
test('digit', function multipleTest() {
var testRegex = VerEx().digit();
var testString = '0123456789';
var i;
var len;
ok(testRegex.test(testString), 'Should match digit');
testString = '-.azertyuiopqsdfghjklmwxcvbn @[]|,_&~';
for (i = 0, len = testString.length; i < len; i++) {
ok(!testRegex.test(testString[i]), 'Should not match digit (' + testString[i] + ')');
}
});
/*!
* VerbalExpressions JavaScript Library v0.2.1
* VerbalExpressions JavaScript Library v0.3.0
* https://github.com/VerbalExpressions/JSVerbalExpressions

@@ -8,8 +8,8 @@ *

* http://opensource.org/licenses/MIT
*
* Date: 2013-07-19
*
*/
// Define the collection class.
/**
* Define the VerbalExpression class.
* @class
*/
(function verbalExpressionIIFE(root) {

@@ -19,3 +19,8 @@ // Constants

// I am the constructor function.
/**
* I am the constructor function.
* @constructor
* @alias VerEx
* @return {RegExp} A new instance of RegExp with injected methods
*/
function VerbalExpression() {

@@ -31,3 +36,6 @@ var verbalExpression = new RegExp();

// Define the static methods.
/**
* @param {RegExp} verbalExpression An instance of RegExp on which to add VerbalExpressions methods
* @return {RegExp} A new instance of RegExp with injected methods
*/
VerbalExpression.injectClassMethods = function injectClassMethods(verbalExpression) {

@@ -47,3 +55,5 @@ var method;

// Define the class methods.
/**
* Define the class methods.
*/
VerbalExpression.prototype = {

@@ -57,4 +67,7 @@ // Variables to hold the whole

// Sanitation function for adding
// anything safely to the expression
/**
* Sanitation function for adding anything safely to the expression
* @param {String} value string to sanitize
* @return {String} sanitized value
*/
sanitize: function sanitize(value) {

@@ -79,6 +92,7 @@ var reRegExpEscape;

// Function to add stuff to the
// expression. Also compiles the
// new expression so it's ready to
// be used.
/**
* Function to add stuff to the expression. Also compiles the new expression so it's ready to be used.
* @param {string} value literal expression, not sanitized
* @return {VerbalExpression} Freshly recompiled instance of VerbalExpression
*/
add: function add(value) {

@@ -91,35 +105,39 @@ this._source += value || '';

// Start and end of line functions
/**
* Control start-of-line matching
* @param {Boolean} enable Control start-of-line matching
* @return {VerbalExpression} Same instance of VerbalExpression to allow method chaining
*/
startOfLine: function startOfLine(enable) {
enable = (enable !== false);
this._prefixes = enable ? '^' : '';
this.add();
return this;
return this.add();
},
/**
* Control end-of-line matching
* @param {Boolean} enable Control end-of-line matching
* @return {VerbalExpression} Same instance of VerbalExpression to allow method chaining
*/
endOfLine: function endOfLine(enable) {
enable = (enable !== false);
this._suffixes = enable ? '$' : '';
this.add();
return this;
return this.add();
},
// We try to keep the syntax as
// user-friendly as possible.
// So we can use the "normal"
// behaviour to split the "sentences"
// naturally.
/**
* We try to keep the syntax as user-friendly as possible. So we can use the "normal" behaviour to split the "sentences" naturally.
* @param {String} value value to find
* @return {VerbalExpression} Same instance of VerbalExpression to allow method chaining
*/
then: function then(value) {
value = this.sanitize(value);
this.add('(?:' + value + ')');
return this;
return this.add('(?:' + value + ')');
},
// And because we can't start with
// "then" function, we create an alias
// to be used as the first function
// of the chain.
/**
* And because we can't start with "then" function, we create an alias to be used as the first function of the chain.
* @param {String} value value to find
* @return {VerbalExpression} Same instance of VerbalExpression to allow method chaining
*/
find: function find(value) {

@@ -129,43 +147,55 @@ return this.then(value);

// Maybe is used to add values with ?
/*
* Maybe is used to add values with ?
* @param {String} value value to find
* @return {VerbalExpression} Same instance of VerbalExpression to allow method chaining
*/
maybe: function maybe(value) {
value = this.sanitize(value);
this.add('(?:' + value + ')?');
return this;
return this.add('(?:' + value + ')?');
},
// Any character any number of times
/**
* Any character any number of times
* @param {String} value value to find
* @return {VerbalExpression} Same instance of VerbalExpression to allow method chaining
*/
anything: function anything() {
this.add('(?:.*)');
return this;
return this.add('(?:.*)');
},
// Anything but these characters
/**
* Anything but these characters
* @param {String} value value to find
* @return {VerbalExpression} Same instance of VerbalExpression to allow method chaining
*/
anythingBut: function anythingBut(value) {
value = this.sanitize(value);
this.add('(?:[^' + value + ']*)');
return this;
return this.add('(?:[^' + value + ']*)');
},
// Any character at least one time
/**
* Any character at least one time
* @return {VerbalExpression} Same instance of VerbalExpression to allow method chaining
*/
something: function something() {
this.add('(?:.+)');
return this;
return this.add('(?:.+)');
},
// Any character at least one time except for these characters
/**
* Any character at least one time except for these characters
* @param {String} value value to find
* @return {VerbalExpression} Same instance of VerbalExpression to allow method chaining
*/
somethingBut: function somethingBut(value) {
value = this.sanitize(value);
this.add('(?:[^' + value + ']+)');
return this;
return this.add('(?:[^' + value + ']+)');
},
// Shorthand function for the
// String.replace function to
// give more logical flow if, for
// example, we're doing multiple
// replacements on one regexp.
/**
* Shorthand function for the String.replace function to give more logical flow if, for example, we're doing multiple replacements on one regexp.
* @param {String} source string to search for
* @param {String} value value to replace with
* @return {VerbalExpression} Same instance of VerbalExpression to allow method chaining
*/
replace: function replace(source, value) {

@@ -179,9 +209,14 @@ source = source.toString();

// Line break
/**
* Line break
* @return {VerbalExpression} Same instance of VerbalExpression to allow method chaining
*/
lineBreak: function lineBreak() {
this.add('(?:\\r\\n|\\r|\\n)'); // Unix + Windows CRLF
return this;
return this.add('(?:\\r\\n|\\r|\\n)'); // Unix + Windows CRLF
},
// And a shorthand for html-minded
/**
* And a shorthand for html-minded
* @return {VerbalExpression} Same instance of VerbalExpression to allow method chaining
*/
br: function br() {

@@ -191,29 +226,50 @@ return this.lineBreak();

// Tab (duh?)
/**
* Tab (duh?)
* @return {VerbalExpression} Same instance of VerbalExpression to allow method chaining
*/
tab: function tab() {
this.add('\\t');
return this;
return this.add('\\t');
},
// Any alphanumeric
/**
* Any alphanumeric
* @return {VerbalExpression} Same instance of VerbalExpression to allow method chaining
*/
word: function word() {
this.add('\\w+');
return this.add('\\w+');
},
/**
* Any digit
* @return {VerbalExpression} Same instance of VerbalExpression to allow method chaining
*/
digit: function digit() {
this.add('\\d');
return this;
},
// Any whitespace
/**
* Any whitespace
* @return {VerbalExpression} Same instance of VerbalExpression to allow method chaining
*/
whitespace: function whitespace() {
this.add('\\s');
return this;
return this.add('\\s');
},
// Any given character
/**
* Any given character
* @param {String} value value to find
* @return {VerbalExpression} Same instance of VerbalExpression to allow method chaining
*/
anyOf: function anyOf(value) {
value = this.sanitize(value);
this.add('[' + value + ']');
return this;
return this.add('[' + value + ']');
},
// Shorthand
/**
* Shorthand
* @param {String} value value to find
* @return {VerbalExpression} Same instance of VerbalExpression to allow method chaining
*/
any: function any(value) {

@@ -223,3 +279,6 @@ return this.anyOf(value);

// Usage: .range( from, to [, from, to ... ] )
/**
* Usage: .range( from, to [, from, to ... ] )
* @return {VerbalExpression} Same instance of VerbalExpression to allow method chaining
*/
range: function range() {

@@ -245,5 +304,3 @@ var length = arguments.length;

this.add(buffer.join(''));
return this;
return this.add(buffer.join(''));
},

@@ -253,3 +310,7 @@

// Modifier abstraction
/**
* Modifier abstraction
* @param {String} modifier modifier to add
* @return {VerbalExpression} Same instance of VerbalExpression to allow method chaining
*/
addModifier: function addModifier(modifier) {

@@ -260,58 +321,46 @@ if (this._modifiers.indexOf(modifier) === -1) {

this.add();
return this;
return this.add();
},
/**
* Remove modifier
* @param {String} modifier modifier to remove
* @return {VerbalExpression} Same instance of VerbalExpression to allow method chaining
*/
removeModifier: function removeModifier(modifier) {
this._modifiers = this._modifiers.replace(modifier, '');
this.add();
return this;
return this.add();
},
// Case-insensitivity modifier
/**
* Case-insensitivity modifier
* @param {Boolean} enable Control case-insensitive matching
* @return {VerbalExpression} Same instance of VerbalExpression to allow method chaining
*/
withAnyCase: function withAnyCase(enable) {
if (enable !== false) {
this.addModifier('i');
} else {
this.removeModifier('i');
}
this.add();
return this;
return enable !== false ? this.addModifier('i') : this.removeModifier('i');
},
// Default behaviour is with "g" modifier,
// so we can turn this another way around
// than other modifiers
/**
* Default behaviour is with "g" modifier, so we can turn this another way around than other modifiers
* @param {Boolean} enable Control global matching
* @return {VerbalExpression} Same instance of VerbalExpression to allow method chaining
*/
stopAtFirst: function stopAtFirst(enable) {
if (enable !== false) {
this.removeModifier('g');
} else {
this.addModifier('g');
}
this.add();
return this;
return enable !== false ? this.removeModifier('g') : this.addModifier('g');
},
// Multiline, also reversed
/**
* Multiline, also reversed
* @param {Boolean} enable Control multi-line matching
* @return {VerbalExpression} Same instance of VerbalExpression to allow method chaining
*/
searchOneLine: function searchOneLine(enable) {
if (enable !== false) {
this.removeModifier('m');
} else {
this.addModifier('m');
}
this.add();
return this;
return enable !== false ? this.removeModifier('m') : this.addModifier('m');
},
// Repeats the previous item
// exactly n times or
// between n and m times.
/**
* Repeats the previous item exactly n times or between n and m times.
* @return {VerbalExpression} Same instance of VerbalExpression to allow method chaining
*/
repeatPrevious: function repeatPrevious() {

@@ -337,11 +386,11 @@ var value;

this.add(value);
return (this);
return this.add(value);
},
// Repeats the previous at least once
/**
* Repeats the previous at least once
* @return {VerbalExpression} Same instance of VerbalExpression to allow method chaining
*/
oneOrMore: function oneOrMore() {
this.add('+');
return (this);
return this.add('+');
},

@@ -351,2 +400,7 @@

/**
* Matches the value zero or more times
* @param {String} value value to find
* @return {VerbalExpression} Same instance of VerbalExpression to allow method chaining
*/
multiple: function multiple(value) {

@@ -367,3 +421,7 @@ // Use expression or string

// Adds alternative expressions
/**
* Adds alternative expressions
* @param {String} value value to find
* @return {VerbalExpression} Same instance of VerbalExpression to allow method chaining
*/
or: function or(value) {

@@ -381,27 +439,35 @@ this._prefixes += '(?:';

// Starts a capturing group
/**
* Starts a capturing group
* @return {VerbalExpression} Same instance of VerbalExpression to allow method chaining
*/
beginCapture: function beginCapture() {
// Add the end of the capture group to the suffixes for now so compilation continues to work
this._suffixes += ')';
this.add('(');
return this;
return this.add('(');
},
// Ends a capturing group
/**
* Ends a capturing group
* @return {VerbalExpression} Same instance of VerbalExpression to allow method chaining
*/
endCapture: function endCapture() {
// Remove the last parentheses from the _suffixes and add to the regex itself
this._suffixes = this._suffixes.substring(0, this._suffixes.length - 1);
this.add(')');
return this;
return this.add(')');
},
// Convert to RegExp object
/**
* Convert to RegExp object
* @return {RegExp} Converted RegExp instance
*/
toRegExp: function toRegExp() {
var array = this.toString().match(/\/(.*)\/([gimuy]+)?/);
return new RegExp(array[1], array[2]);
},
}
};
/**
* @return {VerbalExpression} Returns a new instance of VerbalExpressions
*/
function createVerbalExpression() {

@@ -425,2 +491,2 @@ return new VerbalExpression();

}
})(this);
}(this));

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

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