coupon-code
Advanced tools
Comparing version 0.3.0 to 0.4.0
@@ -24,3 +24,6 @@ // -------------------------------------------------------------------------------------------------------------------- | ||
// constants | ||
var badWordsList = ('SHPX PHAG JNAX JNAT CVFF PBPX FUVG GJNG GVGF SNEG URYY ZHSS QVPX XABO ' + | ||
'NEFR FUNT GBFF FYHG GHEQ FYNT PENC CBBC OHGG SRPX OBBO WVFZ WVMM CUNG') | ||
.replace(/[a-zA-Z]/g,function(c){return String.fromCharCode((c<="Z"?90:122)>=(c=c.charCodeAt(0)+13)?c:c-26);}) | ||
.split(' '); | ||
var symbolsStr = '0123456789ABCDEFGHJKLMNPQRTUVWXY'; | ||
@@ -56,10 +59,13 @@ var symbolsArr = symbolsStr.split(''); | ||
// default to a random code | ||
for( i = 0; i < opts.parts; i++ ) { | ||
part = ''; | ||
for ( j = 0; j < opts.partLen - 1; j++ ) { | ||
part += randomSymbol(); | ||
do { | ||
parts.length = 0; | ||
for( i = 0; i < opts.parts; i++ ) { | ||
part = ''; | ||
for ( j = 0; j < opts.partLen - 1; j++ ) { | ||
part += randomSymbol(); | ||
} | ||
part = part + checkDigitAlg1(part, i+1); | ||
parts.push(part); | ||
} | ||
part = part + checkDigitAlg1(part, i+1); | ||
parts.push(part); | ||
} | ||
} while (!exports.checkForBadWords(parts.join(''))) | ||
} | ||
@@ -70,2 +76,12 @@ | ||
module.exports.checkForBadWords = function(code) { | ||
var i; | ||
code = code.toUpperCase(); | ||
for( i = 0; i < badWordsList.length; i++ ) { | ||
if (code.indexOf(badWordsList[i]) > -1) | ||
return true; | ||
} | ||
return false; | ||
}; | ||
module.exports.validate = function(code, opts) { | ||
@@ -72,0 +88,0 @@ if ( !code ) { |
{ | ||
"name": "coupon-code", | ||
"description": "An implementation of Perl's Algorithm::CouponCode for NodeJS.", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"author": { | ||
@@ -13,6 +13,6 @@ "name":"Andrew Chilton", | ||
"devDependencies": { | ||
"tape": "~2.3.0" | ||
"tape": "~4.0.0" | ||
}, | ||
"dependencies": { | ||
"xtend": "~2.1.1" | ||
"xtend": "~4.0.0" | ||
}, | ||
@@ -19,0 +19,0 @@ "main": "coupon-code.js", |
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
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
19563
11
291
+ Addedxtend@4.0.2(transitive)
- Removedobject-keys@0.4.0(transitive)
- Removedxtend@2.1.2(transitive)
Updatedxtend@~4.0.0