Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
coupon-code
Advanced tools
An implementation of Perl's Algorithm::CouponCode for NodeJS. Thanks to Grant for the inspiration. :)
var cc = require('coupon-code');
// generate a 3 part code
cc.generate();
=> '55G2-DHM0-50NN'
// generate a 4 part code
cc.generate({ parts : 4 });
=> 'U5H9-HKDH-8RNX-1EX7'
// same code, just lowercased
cc.validate('55g2-dhm0-50nn');
=> '55G2-DHM0-50NN'
// various letters instead of numbers
cc.validate('SSGZ-DHMO-SONN');
=> '55G2-DHM0-50NN'
// wrong last character
cc.validate('55G2-DHM0-50NK');
=> ''
// not enough chars in the 2nd part
cc.validate('55G2-DHM-50NN');
=> ''
Let's say you want a user to verify they got something, whether that is an email, letter, fax or carrier pigeon. To prove they received it, they have to type the code you sent them into a certain page on your website. You create a code which they have to type in:
var cc = require('coupon-code');
var verificationCode = cc.generate();
=> 55G2-DHM0-50NN
Time passes, letters get wet, carrier pigeons go on adventures and faxes are just as bad as they ever were. Now the user has to type their code into your website. The problem is, they can hardly read what the code was. Luckily we're somewhat forgiving since Z's and 2's are considered the same, O's and 0's, I's and 1's and S's and 5's are also mapped to each other. But even more than that, the 4th character of each group is a checkdigit which can determine if the other three in that group are correct. The user types this:
[s5g2-dhmo-50nn]
Because our codes are case insensitive and have good conversions for similar chars, the code is accepted as correct.
Also, since we have a checkdigit, we can use a client-side plugin to highlight to the user any mistake in their code before they submit it. Please see the original project (Algorithm::CouponCode) for more details of client side validation.
The easiest way to get it is via npm:
$ npm install coupon-code
To run the tests, use npm:
$ npm test
Written by Andrew Chilton
Copyright 2011 AppsAttic
Grant McLean's Algorithm::CouponCode - with thanks. :)
MIT.
See LICENSE for more details.
FAQs
An implementation of Perl's Algorithm::CouponCode for NodeJS.
The npm package coupon-code receives a total of 3,422 weekly downloads. As such, coupon-code popularity was classified as popular.
We found that coupon-code demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.