GithubHelp home page GithubHelp logo

coupon's Introduction

Coupon

NPM

Coupon — discount coupons generator. Coupon is designed to be the simplest way possible to create a discount coupons for e-commerce purposes.

Installation

npm install coupon

Usage:

var coupon = require("coupon");
var myCoupon = coupon("GREAT-30")
	.give("30%")
	.limit(10)
	.person("Mr. Fetus")
	.only("Banana")
	.expire(new Date(2015, 0, 1));
console.log(myCoupon.json());

Examples:

5% discount coupon for anyone

var coupon = require("coupon");
var myCoupon = coupon("HELLO-5").give("5%");
console.log(myCoupon.json());
{
	id: 'W0YEPW913C8M279D0ECV2P5P0C11QAV1',
	name: 'HELLO-5',
	discount: 0.05		
}

20% one-time discount coupon for John

var coupon = require("coupon");
var myCoupon = coupon("HELLO-JOHN").give("20%").person("John").limit(1);
console.log(myCoupon.json());
{
	id: 'K5PL08XU1GG71T9VW00Y4CEUJFVPMM2F',
	name: 'HELLO-JOHN',
	user: 'John',
	countMax: 1,
	discount: 0.2 
}

API

give()

Specifies amount of discount.

coupon().give(10);

or

coupon().give("10%");

You can pass "free" string

coupon().give("free").only("Delivery");

person()

Specifies user

coupon().give("5%").person("John Smith");

limit()

Specifies how many times you can use coupon

coupon().give("5%");

expire()

Specifies expiration date of coupon

coupon().give("10%").expire(new Date(2015, 5, 15));

only()

Specifies the service

coupon().give("5%").only("Banana");

json()

Generate JSON object

coupon().give("5%");

Test

npm test

License

Licensed under the MIT license

Copyright © 2014 Roman Timashev [email protected] (http://roman.tmshv.ru)

coupon's People

Contributors

tmshv avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

coupon's Issues

stringify the coupon and back

great start. But I want to serialize the coupon's json into the user database or elsewhere for retention. Can we get back the coupon from its json?

Then I would use method accessors to make sure the coupon is still valid, it is not expired, and even use the coupon-code validate function on the id (because I want to use the unique id instead of the name, is that weird?).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.