Giter Site home page Giter Site logo

coupon_code_ex's Introduction

CouponCodeEx

BuildStatusCoverage StatusHex pmGitHub

Generate and verify coupon codes in Elixir.

This library aims to be compatible with Algorithm-CouponCode and its tests including the major features such as:

  • Similar character correction
  • Undersirable code filter for bad and transposable parts
  • Plaintext generation

Installation

Add :coupon_code_ex to your project's mix.exs:

def deps do
  [
    {:coupon_code_ex, "~> 0.1.0"}
  ]
end

Usage

This library is primarily about two functions: CouponCode.generate/1 and CouponCode.validate/2. It is primarily used like this:

# Generate a coupon code
CouponCode.generate()
"207Q-DVTV-K4EW"

CouponCode.generate(parts: 4)
"73F3-LMHT-T9JL-WT8W"

CouponCode.generate(parts: 2, part_length: 5)
"HMUCQ-2U12D"


# Static plaintext codes
CouponCode.generate(plaintext: "1234567890")
"1K7Q-CTFM-LMTC"


# Validate a code
CouponCode.validate("7B5M-LJ4J-D5FN")
{:ok, "7B5M-LJ4J-D5FN"}

CouponCode.validate("7B5X-LJ4X-D5FX")
{:error, :part_invalid, 0}

CouponCode.validate("7B5M-LJ4J-D5FN", parts: 2)
{:error, :parts_invalid, 3}

CouponCode.validate("7B5M-LJ4J-D5FN", parts: 2, part_length: 6)
{:error, :part_invalid, 0}


# Validate similar codes
CouponCode.validate("I9oD-V467-8D52")
{:ok, "190D-V467-8D52"}

CouponCode.validate("i9oD-V467-8Dsz")
{:ok, "190D-V467-8D52"}

CouponCode.validate("i9oDV4678Dsz")
{:ok, "190D-V467-8D52"}

Checkout the HexDocs for a more detailed documentation including the bad word list and default configs.

coupon_code_ex's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

lnr0626

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.