Skip to content

Commit f4fabc3

Browse files
authored
major: refresh project (#6)
* fix: lint * fix: ci * fix: test suite
1 parent 3cde95b commit f4fabc3

File tree

9 files changed

+212
-299
lines changed

9 files changed

+212
-299
lines changed

.circleci/config.yml

Lines changed: 0 additions & 102 deletions
This file was deleted.

.eslintrc

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1 @@
1-
{
2-
"root": true,
3-
"extends": [
4-
"airbnb-base",
5-
"plugin:jest/recommended"
6-
],
7-
"parserOptions": {
8-
"sourceType": "script"
9-
},
10-
"rules": {
11-
"global-require": "warn",
12-
"no-param-reassign": "warn",
13-
"no-use-before-define": "off"
14-
}
15-
}
1+
{"extends": "standard"}

.github/dependabot.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "github-actions"
4+
directory: "/"
5+
schedule:
6+
interval: "monthly"
7+
open-pull-requests-limit: 10
8+
9+
- package-ecosystem: "npm"
10+
directory: "/"
11+
schedule:
12+
interval: "weekly"
13+
open-pull-requests-limit: 10

.github/worflows/ci.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: ci
2+
3+
on:
4+
push:
5+
paths-ignore:
6+
- 'docs/**'
7+
- '*.md'
8+
pull_request:
9+
paths-ignore:
10+
- 'docs/**'
11+
- '*.md'
12+
13+
jobs:
14+
test:
15+
uses: fastify/workflows/.github/workflows/plugins-ci.yml@v3
16+
with:
17+
lint: true

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,5 @@ typings/
5959

6060
*wip.js
6161
.coveralls.yml
62+
package-lock.json
63+
.vscode/

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# lodash-mixin-diff-value
2-
[![npm version](https://badge.fury.io/js/lodash-mixin-diff-value.svg)](https://badge.fury.io/js/lodash-mixin-diff-value) [![Coverage Status](https://coveralls.io/repos/github/Eomm/lodash-mixin-diff-value/badge.svg?branch=master)](https://coveralls.io/github/Eomm/lodash-mixin-diff-value?branch=master) [![CircleCI](https://circleci.com/gh/Eomm/lodash-mixin-diff-value/tree/master.svg?style=svg)](https://circleci.com/gh/Eomm/lodash-mixin-diff-value/tree/master)
2+
3+
[![Build Status](https://github.com/Eomm/lodash-mixin-diff-value/workflows/ci/badge.svg)](https://github.com/Eomm/lodash-mixin-diff-value/actions)
4+
[![npm version](https://badge.fury.io/js/lodash-mixin-diff-value.svg)](https://badge.fury.io/js/lodash-mixin-diff-value)
5+
[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)
36

47
This is a lodash mixin for getting a JSON object that rappresent the value variation of a JSON respect another.
58

mixin.js

Lines changed: 43 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,110 +1,109 @@
1-
'use strict';
1+
'use strict'
22

3-
const moment = require('moment');
3+
const moment = require('moment')
44

55
const _ = {
66
transform: require('lodash.transform'),
77
isObjectLike: require('lodash.isobjectlike'),
88
isArray: require('lodash.isarraylike'),
99
isDate: require('lodash.isdate'),
10-
defaults: require('lodash.defaults'),
11-
};
12-
10+
defaults: require('lodash.defaults')
11+
}
1312

14-
const ignore = Symbol('ignore');
13+
const ignore = Symbol('ignore')
1514

1615
const DEFAULT_OPTIONS = {
1716
extract: 'only-add-change',
1817
dateCheck: true,
1918
dateFormatIn: 'YYYY-MM-DDTHH:mm:ss.sssZ',
20-
dateFormatOut: 'YYYY-MM-DDTHH:mm:ss.sssZ',
21-
};
19+
dateFormatOut: 'YYYY-MM-DDTHH:mm:ss.sssZ'
20+
}
2221

23-
function evaluateDate(value, verifyFormat, formatIn, formatOut) {
22+
function evaluateDate (value, verifyFormat, formatIn, formatOut) {
2423
// TODO: add date comparison only for some keys?
2524
if (_.isDate(value)) {
26-
value = value.toJSON();
25+
value = value.toJSON()
2726
}
2827

2928
if (verifyFormat === true) {
30-
const analize = moment.utc(value, formatIn, true);
29+
const analize = moment.utc(value, formatIn, true)
3130
if (analize.isValid()) {
32-
return analize.format(formatOut);
31+
return analize.format(formatOut)
3332
}
3433
}
35-
return value;
34+
return value
3635
}
3736

38-
function mustAssignValue(value, checkValue, opts) {
39-
value = evaluateDate(value, opts.dateCheck, opts.dateFormatIn, opts.dateFormatOut);
40-
checkValue = evaluateDate(checkValue, opts.dateCheck, opts.dateFormatIn, opts.dateFormatOut);
37+
function mustAssignValue (value, checkValue, opts) {
38+
value = evaluateDate(value, opts.dateCheck, opts.dateFormatIn, opts.dateFormatOut)
39+
checkValue = evaluateDate(checkValue, opts.dateCheck, opts.dateFormatIn, opts.dateFormatOut)
4140

4241
switch (opts.extract) {
4342
case 'only-add':
44-
return checkValue === undefined;
43+
return checkValue === undefined
4544
case 'only-remove':
46-
return checkValue === undefined && value !== undefined;
45+
return checkValue === undefined && value !== undefined
4746
case 'only-changed':
48-
return value !== undefined && checkValue !== undefined && value !== checkValue;
47+
return value !== undefined && checkValue !== undefined && value !== checkValue
4948
case 'only-add-change':
5049
default:
51-
return value !== checkValue;
50+
return value !== checkValue
5251
}
5352
}
5453

55-
function mustAssignObject(object) {
56-
return Object.keys(object).length > 0;
54+
function mustAssignObject (object) {
55+
return Object.keys(object).length > 0
5756
}
5857

59-
function mustAssignArray(array) {
60-
return array.length > 0;
58+
function mustAssignArray (array) {
59+
return array.length > 0
6160
}
6261

63-
function compare(base, comparison, opts) {
62+
function compare (base, comparison, opts) {
6463
if (_.isObjectLike(base) && !_.isDate(base)) {
6564
if (_.isArray(base)) {
66-
const comparisonArray = comparison || [];
65+
const comparisonArray = comparison || []
6766
const newArray = base
6867
.map((e, i) => compare(e, comparisonArray[i], opts))
69-
.filter(e => e !== ignore);
68+
.filter(e => e !== ignore)
7069
if (mustAssignArray(newArray)) {
71-
return newArray;
70+
return newArray
7271
}
7372
} else {
74-
const object = transformObject(base, comparison, opts);
73+
const object = transformObject(base, comparison, opts)
7574
if (mustAssignObject(object)) {
76-
return object;
75+
return object
7776
}
7877
}
7978
} else if (mustAssignValue(base, comparison, opts)) {
80-
return base;
79+
return base
8180
}
82-
return ignore;
81+
return ignore
8382
}
8483

85-
function transformObject(newJson, oldJson, opts) {
84+
function transformObject (newJson, oldJson, opts) {
8685
return _.transform(newJson, (result, value, key) => {
87-
const compareVal = oldJson !== undefined ? oldJson[key] : undefined;
88-
const out = compare(value, compareVal, opts);
86+
const compareVal = oldJson !== undefined ? oldJson[key] : undefined
87+
const out = compare(value, compareVal, opts)
8988
if (out !== ignore) {
9089
// Object.defineProperty(result, key, {
9190
// value: out,
9291
// writable: true,
9392
// enumerable: true,
9493
// configurable: false,
9594
// });
96-
result[key] = out;
95+
result[key] = out
9796
}
98-
}, {});
97+
}, {})
9998
}
10099

101-
module.exports = function differenceValues(newJson, oldJson, opts = {}) {
102-
let out;
103-
_.defaults(opts, DEFAULT_OPTIONS);
100+
module.exports = function differenceValues (newJson, oldJson, opts = {}) {
101+
let out
102+
_.defaults(opts, DEFAULT_OPTIONS)
104103
if (opts.extract === 'only-remove') {
105-
out = transformObject(oldJson, newJson, opts);
104+
out = transformObject(oldJson, newJson, opts)
106105
} else {
107-
out = transformObject(newJson, oldJson, opts);
106+
out = transformObject(newJson, oldJson, opts)
108107
}
109-
return out;
110-
};
108+
return out
109+
}

package.json

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
{
22
"name": "lodash-mixin-diff-value",
33
"version": "1.1.3",
4-
"description": "",
4+
"description": "Lodash mixin to get a JSON object that represent the value variation of an object compared to another",
55
"main": "mixin.js",
66
"scripts": {
7-
"test": "jest --coverage",
8-
"coveralls": "cat ./coverage/lcov.info | node ./node_modules/coveralls/bin/coveralls.js",
9-
"update-modules": "npm update && npm prune --production",
10-
"coverage": "npm test && npm run coveralls"
7+
"lint": "standard --env jest",
8+
"lint:fix": "standard --env jest --fix",
9+
"test": "tap test/**/*.test.js"
1110
},
1211
"keywords": [
1312
"lodash",
@@ -16,6 +15,7 @@
1615
"values"
1716
],
1817
"author": "Manuel Spigolon <behemoth89@gmail.com> (https://github.com/Eomm)",
18+
"funding": "https://github.com/Eomm/lodash-mixin-diff-value?sponsor=1",
1919
"license": "MIT",
2020
"repository": {
2121
"type": "git",
@@ -30,12 +30,8 @@
3030
"moment": "^2.22.2"
3131
},
3232
"devDependencies": {
33-
"coveralls": "^3.0.2",
34-
"eslint": "^4.19.1",
35-
"eslint-config-airbnb-base": "^12.1.0",
36-
"eslint-plugin-import": "^2.14.0",
37-
"eslint-plugin-jest": "^21.26.2",
38-
"jest": "^22.4.4",
39-
"lodash": "^4.17.11"
33+
"lodash": "^4.17.11",
34+
"standard": "^17.0.0",
35+
"tap": "^16.3.0"
4036
}
4137
}

0 commit comments

Comments
 (0)