Skip to content

Commit

Permalink
Merge pull request #1 from yusufshakeel/dev
Browse files Browse the repository at this point in the history
v0.1.0
  • Loading branch information
yusufshakeel authored Mar 8, 2020
2 parents 806b21e + 8b4c982 commit 6604d83
Show file tree
Hide file tree
Showing 16 changed files with 5,895 additions and 3 deletions.
33 changes: 33 additions & 0 deletions .eslintrc.json
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"
]
}
}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
node_modules/
.idea/
docs/
coverage/
9 changes: 9 additions & 0 deletions .travis.yml
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
34 changes: 34 additions & 0 deletions NOTE.md
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
```
42 changes: 42 additions & 0 deletions README.md
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)
7 changes: 7 additions & 0 deletions app/constants.js
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'
};
33 changes: 33 additions & 0 deletions app/engine.js
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;
11 changes: 11 additions & 0 deletions app/random-integer.js
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;
20 changes: 20 additions & 0 deletions index.js
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;
19 changes: 19 additions & 0 deletions jest.config.json
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
}
}
}
23 changes: 23 additions & 0 deletions jsdocs.config.json
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
}
}
Loading

0 comments on commit 6604d83

Please sign in to comment.