commonregex
Advanced tools
Comparing version 0.1.0 to 0.1.1
@@ -1,2 +0,2 @@ | ||
(function(target) { | ||
(function() { | ||
var CommonRegex = function(_text) { | ||
@@ -44,3 +44,4 @@ this.text = _text || ''; | ||
, moneyRegex = /((^|\b)US?)?\$\s?[0-9]{1,3}((,[0-9]{3})+|([0-9]{3})+)?(\.[0-9]{1,2})?\b/gm | ||
, percentageRegex = /(100(\.0+)?|[0-9]{1,2}(\.[0-9]+)?)%/gm; | ||
, percentageRegex = /(100(\.0+)?|[0-9]{1,2}(\.[0-9]+)?)%/gm | ||
, creditCardRegex = /((?:(?:\d{4}[- ]){3}\d{4}|\d{16}))(?![\d])/gm; | ||
@@ -106,2 +107,6 @@ /** | ||
this.getCreditCards = function(_text) { | ||
return getMatches(_text, creditCardRegex); | ||
}; | ||
if(_text !== undefined) { | ||
@@ -119,2 +124,3 @@ this.dates = this.getDates(); | ||
this.percentages = this.getPercentages(); | ||
this.creditCards = this.getCreditCards(); | ||
} | ||
@@ -125,3 +131,3 @@ | ||
//Export as Node.js module | ||
//Export as CommonJS module | ||
if(typeof module !== 'undefined' && module.exports) { | ||
@@ -136,3 +142,3 @@ module.exports = CommonRegex; | ||
} | ||
//Expose CommonRegex as a browser global | ||
else { | ||
@@ -139,0 +145,0 @@ window.CommonRegex = CommonRegex; |
{ | ||
"name": "commonregex", | ||
"description": "Find a lot of kinds of common information in a string.", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"homepage": "https://github.com/talyssonoc/commonregexjs", | ||
@@ -6,0 +6,0 @@ "author": { |
@@ -25,2 +25,6 @@ CommonRegexJS | ||
Or install via NPM with | ||
npm install commonregex | ||
API | ||
@@ -31,3 +35,3 @@ === | ||
Possible fields and its equivalent methods: | ||
Possible properties and its equivalent methods: | ||
@@ -45,2 +49,3 @@ * `dates` or `getDates([text])` | ||
* `percentages` or `getPercentages([text])` (matches percentages between 0.00% and 100.00%) | ||
* `creditCards` or `getCreditCards([text])` | ||
@@ -47,0 +52,0 @@ Examples |
@@ -50,3 +50,3 @@ /* | ||
it('IPv6', function(){ | ||
expect(commonRegex.getIPv6('The IPv6 address for localhost is 0:0:0:0:0:0:0:1, or alternatively, ::1.')) | ||
expect(commonRegex.getIPv6('The IPv6 address for localhost is 0:0:0:0:0:0:0:1, or alternatively ::1, but not :1:.')) | ||
.to.eql(['0:0:0:0:0:0:0:1', '::1']); | ||
@@ -68,6 +68,11 @@ }); | ||
it('percentage', function(){ | ||
it('percentages', function(){ | ||
expect(commonRegex.getPercentages('I\'m 99.9999999% sure that I\'ll get a raise of 5%.')) | ||
.to.eql(['99.9999999%', '5%']); | ||
}); | ||
it('credit cards', function(){ | ||
expect(commonRegex.getCreditCards('His credit card number can be writen as 1234567891011121 or 1234-5678-9101-1121, but not 123-4567891011121.')) | ||
.to.eql(['1234567891011121', '1234-5678-9101-1121']); | ||
}); | ||
}); |
14755
231
86