1.2.4 • Published 1 year ago

voucher-codes-generator v1.2.4

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

VoucherCodeGenerator

Possibly the most easy to use voucher code generator

VoucherCodeGenerator is a simple Typescript library for generating voucher codes with only needing a single string as pattern.

The library works with 3 kinds of CharSets:

  • (N) numbers (0123456789)
  • (L) letters (abcdefghijklmnopqrstuvwxyz)
  • (A) alphanumeric (0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ)

All non-alphanumeric characters in the given pattern parameter will not change when generating a code. All other characters will be replaced by a randomized character of the same CharSet.

Importing the generate method

import { generate } from 'voucher-codes-generator'

Now all you need to do is call the method with your desired pattern, for example:

const code: string = generate("000-AAA-000")

The code above generates a code in the format "NNN-LLL-NNN".

Other examples

Below are some patterns with their possible outputs

Use casePatternPossible output
Serial numbersA0AA-0A0A-A0AA-AAAAN9TT-9G0A-B7FQ-RANC
Giftcard/Voucher codesAa0-aAa-0aAWs2-bHd-9fJ
Giftcard/Voucher codes000-AAA-000543-HRT-876
Letters and digits0aAaA0a0004gRaG6w854
Only UppercaseAAAAAAAAAWKAJSWTDF
Only Lowercaseaaaaaaazazer
With multiple non-alpanumeric characters000-0#AAA$0_AA0654-3#WTE$9_WA0
With multiple non-alpanumeric charactersAA0-00A-#000WQ7-32H-#954

Notes

  • Casing of letters is also checked.
  • It does not matter what characters you use to make your pattern as the same CharSet will be used. (e.g 000-AAA-000 will be processed the same way as 512-WQA-076)

Limitations

  • Every alphanumeric character will always use the same CharSet to randomize (outcomes like N9TT-9G0A-B7FQ-RANC and QK6A-JI6S-7ETR-0A6C are not (yet) possible with the same given pattern)

License

MIT

1.2.4

1 year ago

1.2.3

1 year ago

1.2.2

1 year ago

1.2.1

1 year ago

1.2.0

1 year ago

1.1.9

1 year ago

1.1.8

1 year ago

1.1.7

1 year ago

1.1.6

1 year ago

1.1.5

1 year ago

1.1.4

1 year ago

1.1.3

1 year ago

1.1.2

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago