• Stars
    star
    131
  • Rank 275,867 (Top 6 %)
  • Language
    JavaScript
  • License
    Other
  • Created about 13 years ago
  • Updated almost 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Implementation of Perl's Algorithm::CouponCode for NodeJS

An implementation of Perl's Algorithm::CouponCode for NodeJS. Thanks to Grant for the inspiration. :)

Note: this package is considered stable, hence it seems not much is happening, however all bugs get fixed and currently no new features are planned. It is done.

Synopsis

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'

// generate a code with partLen of 6
cc.generate({ partLen : 6 });
=> WYLKQM-U35V40-9N84DA

Now, when someone types their code in, you can check that it is valid. This means that letters like O are converted to 0 prior to checking.

// 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');
=> ''

// validate a code with 4 parts
cc.validate('U5H9-HKDH-8RNX-1EX7', { parts : 4 });
=> U5H9-HKDH-8RNX-1EX7

// validate a code with partLen of 6
cc.validate('WYLKQM-U35V40-9N84DA', { partLen : 6 });
=> WYLKQM-U35V40-9N84DA

The first thing we do to each code is uppercase it. Then we convert the following letters to numbers:

  • O -> 0
  • I -> 1
  • Z -> 2
  • S -> 5

This means [oizs], [OIZS] and [0125] are considered the same code.

Example

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 code = 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.

Installation

The easiest way to get it is via npm:

$ npm install coupon-code

Tests

To run the tests, use npm:

$ npm test

Author

Inspired By

Grant McLean's Algorithm::CouponCode - with thanks. :)

License

MIT.

See LICENSE for more details.

More Repositories

1

awssum

(deprecated: use aws-sdk) Node.js modules for talking to lots of Web Service APIs.
JavaScript
461
star
2

mongodb-queue

Message queues which uses MongoDB.
JavaScript
208
star
3

cil

DVCS backed issue tracking system
Perl
71
star
4

oibackoff

incremental backoff flow-control for any : fn(function(err, data) { ... });
JavaScript
66
star
5

node-ofx

Parse OFX files into a usable data structure for Node.js.
JavaScript
60
star
6

data2xml

A data to XML converter with a nice interface (for NodeJS).
JavaScript
60
star
7

connect-stream-s3

Streaming connect middleware for uploading files to Amazon S3.
JavaScript
57
star
8

node-date-recur

Create a recurring date and query it to see if it lands on a particular date.
JavaScript
46
star
9

nginx-generator

Generate simple Nginx 'vhosts' with a simple library/cli tool.
JavaScript
42
star
10

nice-route53

A nicer API to Amazon's Route53.
JavaScript
37
star
11

12factor-config

Config which only reads the environment ... as described in http://12factor.net/config
JavaScript
36
star
12

sid

Generate Sortable Identifiers
Go
32
star
13

koa-pg

Koa middleware to get you a Postgres client.
JavaScript
29
star
14

fmt

Command line output formatting.
JavaScript
25
star
15

awssum-amazon-s3

(deprecated: use aws-sdk) NodeJS module to for talking to Amazon S3.
JavaScript
24
star
16

flake

Generate practically unique (approximately sortable) IDs in a distributed environment.
JavaScript
23
star
17

go-readme

An example ReadMe file for Go libraries.
22
star
18

feed2json

Convert RSS/Atom feeds to JSONFeed.
JavaScript
18
star
19

node-awssum-scripts

Examples of non-trivial scripts for node-awssum which can be used standalone
JavaScript
15
star
20

boltdb-dump

Command to dump a human-readable BoltDB to stdout.
Go
13
star
21

lol

Just lol, rofl, wtf, etc !!11!!1!
JavaScript
10
star
22

connect-uuid

Connect middleware to assign a UUID to every request.
JavaScript
8
star
23

connect-pgclient

Connect middleware to manage Postgres connections.
JavaScript
7
star
24

dep-tree

Create and solve a dependency tree.
JavaScript
7
star
25

awssum-amazon-ec2

(deprecated: use aws-sdk) NodeJS module to for talking to Amazon EC2.
JavaScript
6
star
26

mongodb-lock

Locks which uses MongoDB's atomic operations.
JavaScript
6
star
27

libawssum-perl

Perl Interface to many Web APIs (including AWS, RackSpace, Flickr, PayPal, Google Storage etc)
Perl
6
star
28

modb-dyno-leveldb

An implementation of dyno-abstract for a LevelDB store.
JavaScript
6
star
29

winston-simpledb

A SimpleDB transport for winston.
JavaScript
6
star
30

connect-blog

Blog middleware you can add to your Connect/Express app.
JavaScript
6
star
31

proxie

Proximity is a pluggable and configurable HTTP server.
JavaScript
5
star
32

node-awssum

Placeholder repo - now at http://github.com/awssum/awssum/
5
star
33

awssum-amazon-cloudsearch

(deprecated: use aws-sdk) NodeJS module to talk to Amazon CloudSearch.
JavaScript
5
star
34

sound

Make sure your data is sound! A validation library for Node.js.
JavaScript
5
star
35

awssum-amazon-route53

(deprecated: use aws-sdk) NodeJS module to talk to Amazon Route53.
JavaScript
5
star
36

pushid

Lexicographically ordered string IDs.
JavaScript
5
star
37

zaapt

A CMS written in Perl and using Postgres
Perl
4
star
38

awssum-amazon-dynamodb

(deprecated: use aws-sdk) NodeJS module to talk to Amazon DynamoDB.
JavaScript
4
star
39

awssum-amazon

NodeJS module to aid talking to Amazon Web Services. Requires awssum-amazon-* plugins.
JavaScript
4
star
40

awssum-amazon-sqs

(deprecated: use aws-sdk) NodeJS module to talk to Amazon Simple Queue Service (SQS).
JavaScript
4
star
41

s3tools

Tools for managing your S3 buckets and objects.
JavaScript
4
star
42

awssum-amazon-fps

(deprecated: use aws-sdk) NodeJS module to talk to Amazon Flexible Payments Service (FPS).
JavaScript
4
star
43

jquery.persona-assistant.js

jQuery plugin to help with performing common Persona tasks.
JavaScript
4
star
44

awssum-amazon-redshift

AwsSum plugin for Amazon Redshift.
JavaScript
4
star
45

blogz

Read a directory of files, get a blog data structure.
JavaScript
4
star
46

awssum-amazon-cloudformation

(deprecated: use aws-sdk) NodeJS module to talk to Amazon CloudFormation.
JavaScript
4
star
47

pg-patcher

A Postgres patch helper for node-postgres.
JavaScript
3
star
48

chilts.github.com

chilts.org - Node.js, Web APIs, Perl and other geeky type stuff. :)
HTML
3
star
49

awssum-test

Test repo to try which also acts as examples.
JavaScript
3
star
50

level-timeseries

A pluggable timeseries DB built on top of LevelDB.
JavaScript
3
star
51

connect-error-amazon-ses

Middleware to send errors as email through Amazon SES.
JavaScript
3
star
52

awssum-amazon-ses

(deprecated: use aws-sdk) NodeJS module to talk to Amazon Simple Email Service (SES).
JavaScript
3
star
53

redlock

Distributed locks using Redis. Nice API. Has keep-alive functionality.
JavaScript
3
star
54

awssum-amazon-sns

(deprecated: use aws-sdk) NodeJS module to talk to Amazon Simple Notification Service (SNS).
JavaScript
3
star
55

yid

Simple ID generator. A timestamp plus random digits.
JavaScript
3
star
56

connect-error-irc

Connect middleware to send errors to an IRC server.
3
star
57

awssum-io

The AwsSum docs site.
JavaScript
2
star
58

12factor-log

Logger which outputs to only stdout, as described in http://12factor.net/logs
JavaScript
2
star
59

phliky

A small lightweight and consistent text->html markup language
Perl
2
star
60

sandpeople

GoLang middleware to check the relevant `X-Sandstorm-*` headers.
Go
2
star
61

npxcard

Create a nice display for your 'npx your-name-here' package
JavaScript
2
star
62

feed2summary

An rss/atom to stdout processor.
JavaScript
2
star
63

blort

Perl command line Twitter client which uses OAuth
2
star
64

dropmail

DropMail is designed to make your life easier when sending emails from your web server or backend cron jobs.
Perl
2
star
65

pluralise

Plurals for the masses. (node.js)
JavaScript
2
star
66

patchy

Easy patching of your Postgres database.
Go
2
star
67

String-Random-NiceURL

Perl Library to create Random ID strings suitable for URLs.
Perl
2
star
68

nodejs-geek-nz

Node.js in New Zealand promotional site.
JavaScript
2
star
69

pollpod

A command line tool which helps you download podcasts
2
star
70

uchi

UCHI - Unified Cache Handling Interface
JavaScript
2
star
71

awssum-amazon-autoscaling

(deprecated: use aws-sdk) NodeJS module to talk to Amazon AutoScaling.
JavaScript
2
star
72

connect-content

Content middleware you can add to your Connect/Express app.
JavaScript
1
star
73

awssum-amazon-elasticache

(deprecated: use aws-sdk) NodeJS module to talk to Amazon ElasiCache.
JavaScript
1
star
74

awssum-amazon-elb

(deprecated: use aws-sdk) NodeJS module to talk to Amazon Elastic Load Balancing (ELB).
JavaScript
1
star
75

awssum-amazon-glacier

(deprecated: use aws-sdk) NodeJS module to talk to Amazon Glacier.
JavaScript
1
star
76

awssum-amazon-iam

(deprecated: use aws-sdk) NodeJS module to talk to Amazon Identity and Access Management (IAM).
JavaScript
1
star
77

awssum-amazon-sts

(deprecated: use aws-sdk) NodeJS module to talk to Amazon Simple Token Service (STS).
JavaScript
1
star
78

pwkeepr

Helps you store and edit your passwords securely. :)
1
star
79

awssum-amazon-imd

(deprecated: use aws-sdk) NodeJS module to talk to Amazon Instance MetaData (IMD).
JavaScript
1
star
80

namez

A name generator, for projects, confirmation codes, or funsies!
JavaScript
1
star
81

trademe

Client for the TradeMe (trademe.co.nz) API
JavaScript
1
star
82

date-slice

Figure out which time slice a date lands in.
JavaScript
1
star
83

awssum-amazon-simpledb

(deprecated: use aws-sdk) NodeJS module to talk to Amazon SimpleDB.
JavaScript
1
star
84

persona-assistant-site

Example site using jquery.persona-assistant.js.
JavaScript
1
star
85

awssum-amazon-cloudfront

(deprecated: use aws-sdk) NodeJS module to talk to Amazon CloudFront.
JavaScript
1
star
86

awssum-amazon-emr

(deprecated: use aws-sdk) NodeJS module to talk to Amazon Elastic MapReduce (EMR).
JavaScript
1
star
87

kiwiwriters

The main website for kiwiwriters.org (no longer exists).
Perl
1
star
88

zproxy

An easily configurable web proxy, redirect, not found and static site server, written in Go.
Go
1
star
89

awssum-amazon-swf

(deprecated: use aws-sdk) NodeJS module to talk to Amazon Simple WorkFlow (SWF).
JavaScript
1
star
90

blat

Static site generation tool.
Perl
1
star
91

dyno

The networked cornerstone of an eventually consistent key/value store.
JavaScript
1
star
92

awssum-amazon-storagegateway

(deprecated: use aws-sdk) NodeJS module to talk to Amazon StorageGateway.
JavaScript
1
star
93

onebyone

Flow control so that only one function executes at any one time.
JavaScript
1
star
94

gocigar

A GoLang program to read stats from your system.
Go
1
star
95

webhook-inspector

App to receive, display, and query GitHub WebHooks.
HTML
1
star
96

nodejs-nz

A site for promoting Node in New Zealand.
JavaScript
1
star
97

conhash

A fast consistent hashing (hashring) implementation.
JavaScript
1
star
98

sensi

A set of tools for Infrastructure as a Service: Queues, Notifications etc
JavaScript
1
star
99

promises101-org

A tutorial site for Promises/A+ in JavaScript.
JavaScript
1
star
100

awssum-amazon-cloudwatch

(deprecated: use aws-sdk) NodeJS module to talk to Amazon CloudWatch.
JavaScript
1
star