Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 39ab80f

Browse files
Merge remote-tracking branch 'upstream/main' into remove-spread-op
2 parents 3c6c607 + 8c09976 commit 39ab80f

23 files changed

+3240
-3862
lines changed

‎.eslintrc.json‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"env": {
3+
"browser": true,
4+
"es2021": true,
5+
"node": true,
6+
"jest": true
7+
},
8+
"extends": "eslint:recommended",
9+
"parserOptions": {
10+
"ecmaVersion": 12,
11+
"sourceType": "module"
12+
},
13+
"rules": {
14+
}
15+
}

‎.github/workflows/ci.yaml‎

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: 'GitHub CI'
2+
on:
3+
push:
4+
branches:
5+
- main
6+
pull_request:
7+
branches:
8+
- main
9+
10+
jobs:
11+
test-node:
12+
name: Test on Node.js v${{ matrix.node-version }}
13+
strategy:
14+
fail-fast: false
15+
matrix:
16+
node-version: [12.x, 14.x, 16.x]
17+
runs-on: ubuntu-latest
18+
steps:
19+
- uses: actions/checkout@v2
20+
- name: Use Node.js ${{ matrix.node-version }}
21+
uses: actions/setup-node@v2
22+
with:
23+
node-version: ${{ matrix.node-version }}
24+
cache: yarn
25+
- run: yarn install
26+
- run: yarn test:coverage
27+
- uses: codecov/codecov-action@v2
28+
29+
test-os:
30+
name: Test on ${{ matrix.os }} using Node.js LTS
31+
strategy:
32+
fail-fast: false
33+
matrix:
34+
os: [ubuntu-latest, windows-latest, macOS-latest]
35+
runs-on: ${{ matrix.os }}
36+
37+
steps:
38+
- uses: actions/checkout@v2
39+
- uses: actions/setup-node@v2
40+
with:
41+
node-version: 16.x
42+
cache: yarn
43+
- run: yarn install
44+
- run: yarn test:coverage
45+
- uses: codecov/codecov-action@v2
46+
47+
lint:
48+
name: Run ESLint
49+
runs-on: ubuntu-latest
50+
steps:
51+
- uses: actions/checkout@v2
52+
- uses: actions/setup-node@v2
53+
with:
54+
node-version: 16.x
55+
cache: yarn
56+
- run: yarn install
57+
- run: yarn lint

‎.gitignore‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ node_modules/
22
dist
33
coverage
44
npm-debug.log
5+
yarn-error.log
6+
dist-es

‎.travis.yml‎

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

‎README.md‎

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
<hr />
1010

11-
[![Build Status](https://img.shields.io/travis/mattphillips/deep-object-diff/master.svg?style=flat-square)](https://travis-ci.org/mattphillips/deep-object-diff/master)
12-
[![Code Coverage](https://img.shields.io/coveralls/mattphillips/deep-object-diff.svg?style=flat-square)](https://coveralls.io/github/mattphillips/deep-object-diff?branch=master)
11+
[![Build Status](https://github.com/mattphillips/deep-object-diff/actions/workflows/ci.yaml/badge.svg)](https://github.com/mattphillips/deep-object-diff/actions/workflows/ci.yaml)
12+
[![Code coverage](https://codecov.io/gh/mattphillips/deep-object-diff/branch/main/graph/badge.svg?token=EwnXzDGW3x)](https://codecov.io/gh/mattphillips/deep-object-diff)
1313
[![version](https://img.shields.io/npm/v/deep-object-diff.svg?style=flat-square)](https://www.npmjs.com/package/deep-object-diff)
1414
[![downloads](https://img.shields.io/npm/dm/deep-object-diff.svg?style=flat-square)](http://npm-stat.com/charts.html?package=deep-object-diff&from=2016年11月23日)
1515
[![MIT License](https://img.shields.io/npm/l/deep-object-diff.svg?style=flat-square)](https://github.com/mattphillips/deep-object-diff/blob/master/LICENSE)
@@ -40,24 +40,10 @@ A small library that can deep diff two JavaScript Objects, including nested stru
4040

4141
## Importing
4242

43-
ES6 / Babel:
4443
``` js
4544
import { diff, addedDiff, deletedDiff, updatedDiff, detailedDiff } from 'deep-object-diff';
4645
```
4746

48-
ES5:
49-
``` js
50-
const { diff, addedDiff, deletedDiff, detailedDiff, updatedDiff } = require("deep-object-diff");
51-
52-
// OR
53-
54-
const diff = require("deep-object-diff").diff;
55-
const addedDiff = require("deep-object-diff").addedDiff;
56-
const deletedDiff = require("deep-object-diff").deletedDiff;
57-
const detailedDiff = require("deep-object-diff").detailedDiff;
58-
const updatedDiff = require("deep-object-diff").updatedDiff;
59-
```
60-
6147
## Usage:
6248

6349
### `diff`:

‎package.json‎

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,44 @@
11
{
22
"name": "deep-object-diff",
3-
"version": "1.1.0",
3+
"version": "1.1.5",
44
"description": "Deep diffs two objects, including nested structures of arrays and objects, and return the difference.",
5-
"main": "dist/index.js",
5+
"main": "cjs/index.js",
6+
"module": "mjs/index.js",
7+
"exports": {
8+
".": {
9+
"import": "./mjs/index.js",
10+
"require": "./cjs/index.js"
11+
}
12+
},
613
"types": "./index.d.ts",
7-
"files": [
8-
"dist",
9-
"index.d.ts",
10-
"README.md"
11-
],
1214
"scripts": {
13-
"build": "babel src -d dist --ignore *.test.js",
15+
"build": "rm -rf dist && babel src -d dist/cjs && node scripts/build.mjs",
1416
"prepublish": "yarn build",
17+
"lint": "eslint src",
1518
"test": "jest",
16-
"test:coverage": "yarn test -- --coverage",
17-
"test:report": "cat ./coverage/lcov.info | ./node_modules/.bin/coveralls",
19+
"test:coverage": "yarn test --coverage",
1820
"test:watch": "yarn test -- --watch"
1921
},
2022
"author": "Matt Phillips",
2123
"license": "MIT",
2224
"devDependencies": {
23-
"babel-cli": "^6.18.0",
24-
"babel-core": "^6.18.2",
25-
"babel-jest": "^22.0.0",
26-
"babel-jest-assertions": "^0.1.0",
27-
"babel-plugin-add-module-exports": "^0.2.1",
28-
"babel-plugin-gwt": "^1.0.0",
29-
"babel-plugin-transform-es2015-modules-umd": "^6.23.0",
30-
"babel-preset-es2015": "^6.18.0",
31-
"babel-preset-stage-0": "^6.16.0",
32-
"coveralls": "^3.0.0",
33-
"jest": "^23.6.0"
25+
"@babel/cli": "^7.16.8",
26+
"@babel/core": "^7.16.12",
27+
"@babel/preset-env": "^7.16.11",
28+
"babel-jest": "^27.4.6",
29+
"eslint": "^8.7.0",
30+
"jest": "^27.4.7"
3431
},
3532
"babel": {
3633
"presets": [
37-
"es2015",
38-
"stage-0"
39-
],
40-
"plugins": [
41-
"add-module-exports",
42-
"transform-es2015-modules-umd",
43-
"babel-jest-assertions",
44-
"gwt"
34+
[
35+
"@babel/preset-env",
36+
{
37+
"targets": {
38+
"node": "12"
39+
}
40+
}
41+
]
4542
]
4643
},
4744
"repository": {

‎scripts/build.mjs‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import * as path from "path";
2+
import * as fs from "fs";
3+
4+
const DIST = "dist";
5+
const SRC = "src";
6+
const MJS = "mjs";
7+
const CJS = "cjs";
8+
const PKG = "package.json";
9+
const FILES = ["index.d.ts", "README.md", "LICENSE"];
10+
11+
fs.mkdirSync(path.join(DIST, MJS));
12+
fs.readdirSync("./src").forEach((file) => fs.copyFileSync(path.join(SRC, file), path.join(DIST, MJS, file)));
13+
14+
fs.writeFileSync(path.join(DIST, CJS, PKG), JSON.stringify({ type: "commonjs" }, null, 2));
15+
fs.writeFileSync(path.join(DIST, MJS, PKG), JSON.stringify({ type: "module" }, null, 2));
16+
17+
const pkg = fs.readFileSync(PKG, "utf-8");
18+
const json = JSON.parse(pkg);
19+
20+
delete json.scripts;
21+
delete json.devDependencies;
22+
delete json.babel;
23+
24+
fs.writeFileSync(path.join(DIST, PKG), JSON.stringify(json, null, 2));
25+
26+
FILES.forEach((file) => fs.copyFileSync(file, path.join(DIST, file)));

‎src/added/index.js‎ renamed to ‎src/added.js‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import { isEmpty, isObject, properObject } from '../utils';
1+
import { isEmpty, isObject, hasOwnProperty } from './utils';
22

33
const addedDiff = (lhs, rhs) => {
44

55
if (lhs === rhs || !isObject(lhs) || !isObject(rhs)) return {};
66

7-
const l = properObject(lhs);
8-
const r = properObject(rhs);
7+
const l = lhs;
8+
const r = rhs;
99

1010
return Object.keys(r).reduce((acc, key) => {
11-
if (l.hasOwnProperty(key)) {
11+
if (hasOwnProperty(l,key)) {
1212
const difference = addedDiff(l[key], r[key]);
1313

1414
if (isObject(difference) && isEmpty(difference)) return acc;

‎src/arrayDiff/index.js‎ renamed to ‎src/arrayDiff.js‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import { isDate, isEmpty, isObject, properObject } from '../utils';
1+
import { isDate, isEmpty, isObject, hasOwnProperty } from './utils';
22

33
const diff = (lhs, rhs) => {
44
if (lhs === rhs) return {}; // equal return no diff
55

66
if (!isObject(lhs) || !isObject(rhs)) return rhs; // return updated rhs
77

8-
const l = properObject(lhs);
9-
const r = properObject(rhs);
8+
const l = lhs;
9+
const r = rhs;
1010

1111
const deletedValues = Object.keys(l).reduce((acc, key) => {
12-
return r.hasOwnProperty(key) ? acc : { ...acc, [key]: undefined };
12+
return hasOwnProperty(r,key) ? acc : { ...acc, [key]: undefined };
1313
}, {});
1414

1515
if (isDate(l) || isDate(r)) {
@@ -19,11 +19,11 @@ const diff = (lhs, rhs) => {
1919

2020
if (Array.isArray(r) && Array.isArray(l)) {
2121
const deletedValues = l.reduce((acc, item, index) => {
22-
return r.hasOwnProperty(index) ? acc.concat(item) : acc.concat(undefined);
22+
return hasOwnProperty(r,index) ? acc.concat(item) : acc.concat(undefined);
2323
}, []);
2424

2525
return r.reduce((acc, rightItem, index) => {
26-
if (!deletedValues.hasOwnProperty(index)) {
26+
if (!hasOwnProperty(deletedValues,index)) {
2727
return acc.concat(rightItem);
2828
}
2929

@@ -40,7 +40,7 @@ const diff = (lhs, rhs) => {
4040
}
4141

4242
return Object.keys(r).reduce((acc, key) => {
43-
if (!l.hasOwnProperty(key)) return { ...acc, [key]: r[key] }; // return added r key
43+
if (!hasOwnProperty(l,key)) return { ...acc, [key]: r[key] }; // return added r key
4444

4545
const difference = diff(l[key], r[key]);
4646

‎src/deleted/index.js‎ renamed to ‎src/deleted.js‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import { isEmpty, isObject, properObject } from '../utils';
1+
import { isEmpty, isObject, hasOwnProperty } from './utils';
22

33
const deletedDiff = (lhs, rhs) => {
44
if (lhs === rhs || !isObject(lhs) || !isObject(rhs)) return {};
55

6-
const l = properObject(lhs);
7-
const r = properObject(rhs);
6+
const l = lhs;
7+
const r = rhs;
88

99
return Object.keys(l).reduce((acc, key) => {
10-
if (r.hasOwnProperty(key)) {
10+
if (hasOwnProperty(r,key)) {
1111
const difference = deletedDiff(l[key], r[key]);
1212

1313
if (isObject(difference) && isEmpty(difference)) return acc;

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /