-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from yusufshakeel/dev
v0.1.0
- Loading branch information
Showing
16 changed files
with
5,895 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"env": { | ||
"browser": true, | ||
"commonjs": true, | ||
"es6": true | ||
}, | ||
"extends": "eslint:recommended", | ||
"globals": { | ||
"Atomics": "readonly", | ||
"SharedArrayBuffer": "readonly" | ||
}, | ||
"parserOptions": { | ||
"ecmaVersion": 2018 | ||
}, | ||
"rules": { | ||
"indent": [ | ||
"error", | ||
2 | ||
], | ||
"linebreak-style": [ | ||
"error", | ||
"unix" | ||
], | ||
"quotes": [ | ||
"error", | ||
"single" | ||
], | ||
"semi": [ | ||
"error", | ||
"always" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
node_modules/ | ||
.idea/ | ||
docs/ | ||
coverage/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
language: node_js | ||
node_js: | ||
- 10 | ||
install: npm install | ||
cache: | ||
directories: | ||
- "node_modules" | ||
script: | ||
- npm run test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
### Install | ||
To install all the dependencies and start developing/using run the following command. | ||
``` | ||
> npm install | ||
``` | ||
|
||
### Test | ||
To run the test suite execute the following command. | ||
``` | ||
> npm run test | ||
``` | ||
|
||
### JSDocs | ||
To generate JS Documentation run the following command. | ||
``` | ||
> npm run generate-docs | ||
``` | ||
|
||
### Precommit | ||
Run the following command before making Git Commit. | ||
``` | ||
> npm run precommit | ||
``` | ||
This will generate documentation, run test suites and any other steps that you have configures in the `package.json` file. | ||
|
||
### Update the version in package.json | ||
Run the following command to update the version of the project in `package.json` file. | ||
``` | ||
> npm version VERSION | ||
``` | ||
Example: | ||
``` | ||
> npm version 1.0.0 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,44 @@ | ||
# couponjs | ||
This is a simple coupon creation project using NodeJS. | ||
|
||
[![license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/yusufshakeel/couponjs) | ||
[![npm version](https://img.shields.io/badge/npm-0.1.0-blue.svg)](https://www.npmjs.com/package/couponjs) | ||
[![Build Status](https://travis-ci.com/yusufshakeel/couponjs.svg?branch=master)](https://travis-ci.com/yusufshakeel/couponjs) | ||
|
||
# Getting Started | ||
Add this to your project using npm. | ||
``` | ||
> npm i couponjs | ||
``` | ||
|
||
## Tests | ||
Test code of this project is inside the `tests` directory. | ||
|
||
Using the following for testing: | ||
* Jest | ||
|
||
## Generate coupon | ||
Create an object of Coupon. | ||
```javascript | ||
const coupon = new Coupon(); | ||
``` | ||
|
||
Now, call the `generate` method. | ||
```javascript | ||
const myCoupon = coupon.generate(); | ||
``` | ||
|
||
By default, `generate` will return coupon code of length 6 using uppercase alphabet. | ||
|
||
|
||
## License | ||
It's free :smiley: | ||
|
||
[MIT License](https://github.com/yusufshakeel/couponjs/blob/master/LICENSE) Copyright (c) 2020 Yusuf Shakeel | ||
|
||
### Back this project | ||
|
||
If you find this project useful and interesting then feel free to support it on [Patreon](https://www.patreon.com/yusufshakeel). | ||
|
||
### Donate | ||
Feeling generous :smiley: [Donate via PayPal](https://www.paypal.me/yusufshakeel) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/** | ||
* Constants | ||
* @type {{ALPHABET_UPPERCASE: string, ALPHABET_LOWERCASE: string, DIGIT: string}} | ||
*/ | ||
module.exports = { | ||
ALPHABET_UPPERCASE: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/** | ||
* Engine to produce coupon. | ||
* @param {string} characters This is the set of characters used to generate coupon. | ||
* @param {function} randomInteger This is the function that will generate random integer value. | ||
* @constructor | ||
*/ | ||
const Engine = function (characters, randomInteger) { | ||
|
||
function characterSet() { | ||
return characters.split(''); | ||
} | ||
|
||
function generateCoupon() { | ||
const generatedCouponCharacters = []; | ||
const charSet = characterSet(); | ||
for(let i = 0; i < 6; i++) { | ||
generatedCouponCharacters.push( | ||
charSet[randomInteger(0, 6)] | ||
); | ||
} | ||
return generatedCouponCharacters.join(''); | ||
} | ||
|
||
/** | ||
* This will return coupon. | ||
* @returns {string} | ||
*/ | ||
this.run = function () { | ||
return generateCoupon(); | ||
} | ||
}; | ||
|
||
module.exports = Engine; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/** | ||
* This will return an integer value between min and max both inclusive. | ||
* @param {number} min The starting integer value. | ||
* @param {number} max The ending integer value. | ||
* @returns {number} Random integer value between min and max both inclusive. | ||
*/ | ||
function randomInteger(min, max) { | ||
return Math.floor(Math.random() * (Math.floor(max) - Math.ceil(min) + 1)) + Math.ceil(min); | ||
} | ||
|
||
module.exports = randomInteger; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
const Engine = require('./app/engine.js'); | ||
const { ALPHABET_UPPERCASE } = require('./app/constants.js'); | ||
const randomInteger = require('./app/random-integer.js'); | ||
|
||
/** | ||
* The Coupon constructor. | ||
* @constructor | ||
*/ | ||
const Coupon = function () { | ||
/** | ||
* This will generate coupons. | ||
* @returns {string} | ||
*/ | ||
this.generate = function () { | ||
const engine = new Engine(ALPHABET_UPPERCASE, randomInteger); | ||
return engine.run(); | ||
}; | ||
}; | ||
|
||
module.exports = Coupon; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"verbose": true, | ||
"bail": 1, | ||
"collectCoverage": true, | ||
"collectCoverageFrom": [ | ||
"**/*.{js,jsx}", | ||
"!**/coverage/**", | ||
"!**/docs/**", | ||
"!**/node_modules/**", | ||
"!**/tests/**" | ||
], | ||
"coverageThreshold": { | ||
"global": { | ||
"branches": 80, | ||
"functions": 80, | ||
"lines": 80 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"source": { | ||
"includePattern": ".+\\.js(doc|x)?$", | ||
// Only process file ending in .js, .jsdoc or .jsx | ||
"include": [ | ||
"index.js", | ||
"app/." | ||
], | ||
// Check all folders. | ||
"exclude": [ | ||
"node_modules" | ||
] | ||
// Be gone, node_modules. | ||
}, | ||
"recurseDepth": 10, | ||
// Only go 10 levels deep. | ||
"opts": { | ||
"destination": "./docs/", | ||
// Where I want my docs to be generated. | ||
"recurse": true | ||
// Same as using -r or --recurse | ||
} | ||
} |
Oops, something went wrong.