https://github.com/egg-/ticket-code
Generate ticket codes library for Node.js
https://github.com/egg-/ticket-code
coupon promotion ticket voucher
Last synced: about 2 months ago
JSON representation
Generate ticket codes library for Node.js
- Host: GitHub
- URL: https://github.com/egg-/ticket-code
- Owner: egg-
- License: mit
- Created: 2017-08-28T05:59:08.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2017-08-28T07:06:14.000Z (about 8 years ago)
- Last Synced: 2025-03-04T09:40:10.905Z (7 months ago)
- Topics: coupon, promotion, ticket, voucher
- Language: JavaScript
- Homepage:
- Size: 3.91 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ticket-code
[](https://www.npmjs.com/package/ticket-code) [](https://www.npmjs.com/package/ticket-code)
[](https://travis-ci.org/egg-/ticket-code)
[](http://standardjs.com/)ticket-code is generate ticket codes library for Node.js
## Installation
```sh
$ npm install ticket-code
```## Usage
A simple checksum code is added to verify the generated code value. For this purpose, it is recommended to specify numerical seed value.
```javascript
var ticketCode = require('ticket-code')
var codeLength = 15 // optional (default 10)
var checksumSeed = 5 // required
var checksumIdx = 7 // optional (default Math.floor(code length / 2))var code = ticketCode.generate(checksumSeed, codeLength, checksumIdx) // NPP3YHPEQMCY75W
// ...ticketCode.validate('NPP3YHPEQMCY75W', checksumSeed, checksumIdx) // true
ticketCode.validate('NPP3YHPEQMCY75A', checksumSeed, checksumIdx) // false
```## Test
Test with mocha
```bash
$ grunt
```like watch
```bash
$ grunt watch
```## Contributing
Bug reports and pull requests are welcome on Github at [https://github.com/egg-/ticket-code](https://github.com/egg-/ticket-code)
1. Fork it
1. Create your feature branch.
1. Commit your changes.
1. Push to the branch.
1. Create a new Pull Request.## License
ticket-code is licensed under the [MIT license](https://github.com/egg-/ticket-code/blob/master/LICENSE).