Skip to content

Commit

Permalink
Merge pull request #29 from yusufshakeel/dev
Browse files Browse the repository at this point in the history
0.8.16
  • Loading branch information
yusufshakeel committed Oct 23, 2020
2 parents 5138cbf + 4e54f80 commit c5a0aef
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -3,7 +3,7 @@
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.8.15-blue.svg)](https://www.npmjs.com/package/couponjs)
[![npm version](https://img.shields.io/badge/npm-0.8.16-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)
[![Coverage Status](https://coveralls.io/repos/github/yusufshakeel/couponjs/badge.svg?branch=master)](https://coveralls.io/github/yusufshakeel/couponjs?branch=master)

Expand Down
18 changes: 17 additions & 1 deletion app/functional/index.js
Expand Up @@ -51,4 +51,20 @@ const omit = (values, valuesToOmit) => values.filter(value => !valuesToOmit.incl
*/
const uniqueCharacters = characters => [...new Set(characters.join(''))];

module.exports = { sumOf, attachPrefix, attachSuffix, pipe, identity, omit, uniqueCharacters };
/**
* Copies all enumerable own properties from one or more objects to a empty target object.
* @param {...object} sourceObjects
* @returns {object}
*/
const shallowMerge = (...sourceObjects) => Object.assign({}, ...sourceObjects);

module.exports = {
sumOf,
attachPrefix,
attachSuffix,
pipe,
identity,
omit,
uniqueCharacters,
shallowMerge
};
6 changes: 3 additions & 3 deletions index.js
Expand Up @@ -5,6 +5,7 @@ const { defaultCouponGenerationOption, defaultCouponEngineOption } = require('./
const randomInteger = require('./app/random-integer.js');
const Performance = require('./app/performance.js');
const { couponConfigValidator } = require('./app/validator/coupon-config-validator.js');
const { shallowMerge } = require('./app/functional');

/**
* The Coupon constructor.
Expand All @@ -13,8 +14,7 @@ const { couponConfigValidator } = require('./app/validator/coupon-config-validat
*/
const Coupon = function (config) {
const performance = new Performance();
const { verbose, logPerformance, maxNumberOfCouponsToGenerate } = Object.assign(
{},
const { verbose, logPerformance, maxNumberOfCouponsToGenerate } = shallowMerge(
defaultCouponEngineOption,
config
);
Expand All @@ -36,7 +36,7 @@ const Coupon = function (config) {
omitCharacters,
format,
characterSet: characterSetOption
} = Object.assign({}, defaultCouponGenerationOption, option);
} = shallowMerge(defaultCouponGenerationOption, option);
try {
const engine = new Engine({
randomInteger,
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "couponjs",
"version": "0.8.15",
"version": "0.8.16",
"description": "This is a simple coupon creation project using NodeJS.",
"main": "index.js",
"scripts": {
Expand Down
22 changes: 21 additions & 1 deletion tests/unit/app/functional/index.unit.test.js
Expand Up @@ -7,7 +7,8 @@ const {
pipe,
identity,
omit,
uniqueCharacters
uniqueCharacters,
shallowMerge
} = require('../../../../app/functional');

test('Should be able to sum up', () => {
Expand Down Expand Up @@ -54,3 +55,22 @@ test('Should be able to get unique characters', () => {
'F'
]);
});

test('Should be able to shallow merge without mutating the source objects', () => {
const obj1 = { a: 1, b: 2, e: { f: [1, 2], g: { h: 10 } } };
const obj2 = { b: 3 };
const obj3 = { c: 4 };
const obj4 = { e: { f: 10 } };
expect(shallowMerge(obj1, obj2, obj3, obj4)).toStrictEqual({
a: 1,
b: 3,
c: 4,
e: {
f: 10
}
});
expect(obj1).toStrictEqual({ a: 1, b: 2, e: { f: [1, 2], g: { h: 10 } } });
expect(obj2).toStrictEqual({ b: 3 });
expect(obj3).toStrictEqual({ c: 4 });
expect(obj4).toStrictEqual({ e: { f: 10 } });
});

0 comments on commit c5a0aef

Please sign in to comment.