Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
1 change: 0 additions & 1 deletion .eslintignore

This file was deleted.

72 changes: 0 additions & 72 deletions .eslintrc

This file was deleted.

30 changes: 30 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: CI

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
check:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node-version-file: .node-version
cache: npm

- run: npm ci

- name: Lint
run: npm run lint

- name: Type check
run: npm run check-types

- name: Test
run: npm run test:terse
72 changes: 0 additions & 72 deletions .github/workflows/codeql-analysis.yml

This file was deleted.

18 changes: 0 additions & 18 deletions .github/workflows/node.js.yml

This file was deleted.

73 changes: 73 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: Publish

on:
push:
branches: [ master ]

permissions:
contents: write
id-token: write

jobs:
publish:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: actions/setup-node@v4
with:
node-version-file: .node-version
registry-url: https://registry.npmjs.org
cache: npm

- run: npm ci

- name: Lint
run: npm run lint

- name: Type check
run: npm run check-types

- name: Test
run: npm run test:terse

- name: Build
run: npm run build

- name: Resolve version bump
id: bump
run: |
LAST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
if [ -z "$LAST_TAG" ]; then
RANGE="HEAD"
else
RANGE="${LAST_TAG}..HEAD"
fi

BUMP=""
while IFS= read -r subject; do
[ -z "$subject" ] && continue
if echo "$subject" | grep -qE '^[a-z]+(\(.+\))?!:'; then
BUMP="major"; break
fi
if [ "$BUMP" != "minor" ] && echo "$subject" | grep -qE '^feat(\(.+\))?:'; then
BUMP="minor"
fi
if [ -z "$BUMP" ] && echo "$subject" | grep -qE '^fix(\(.+\))?:'; then
BUMP="patch"
fi
done < <(git log "$RANGE" --format="%s" --no-merges)

echo "type=$BUMP" >> "$GITHUB_OUTPUT"

- name: Publish
if: steps.bump.outputs.type
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
npm version "${{ steps.bump.outputs.type }}" -m "chore(release): %s"
git push --follow-tags
npm publish --provenance --access public
16 changes: 9 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Logs
node_modules/
dist/
*.tsbuildinfo
.vite/
coverage/
.env
.env.*
!.env.example
.DS_Store
*.log

# Editors
.vscode

# Dependency directory
node_modules
1 change: 1 addition & 0 deletions .node-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
22
7 changes: 0 additions & 7 deletions .npmignore

This file was deleted.

4 changes: 0 additions & 4 deletions .travis.yml

This file was deleted.

53 changes: 37 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@

To compare JSON objects containing asset metadata for a digital library. Upon change of any metadata, we'd store these changes as an audit trail and email asset stakeholders for review and approval of the changes.

## Dependencies

diffler is written with Node v12 in mind.
Tests depend on [Mocha](https://mochajs.org/).

## Usage

[![npm version](https://badge.fury.io/js/diffler.png)](https://www.npmjs.com/package/diffler)
Expand All @@ -27,7 +22,7 @@ npm install diffler

### Params

`obj1` and `obj2` are two JSON objects for comparison.
`original` and `updated` are two JSON objects for comparison.

### Return

Expand All @@ -37,23 +32,49 @@ If different: A JSON object with preserved path structure. The resulting values

### Example

```js
const diffler = require("diffler");
#### ESM

const before = { name: "omgaz", location: "London" };
const after = { name: "omgaz", location: "Melbourne" };
```ts
import diffler from 'diffler';

const before = { name: 'omgaz', location: 'London' };
const after = { name: 'omgaz', location: 'Melbourne' };

const difference = diffler(before, after);
console.log(difference); // { location: { from: "London", to: "Melbourne" } }
console.log(difference); // { location: { from: 'London', to: 'Melbourne' } }
```

## Tests
#### CommonJS

[![Build Status](https://travis-ci.org/omgaz/diffler.svg?branch=master)](https://travis-ci.org/omgaz/diffler)
```js
const diffler = require('diffler');

If you'd like to run tests, check out the whole project. You'll need NodeJS installed. Tests use Mocha.
const before = { name: 'omgaz', location: 'London' };
const after = { name: 'omgaz', location: 'Melbourne' };

const difference = diffler(before, after);
console.log(difference); // { location: { from: 'London', to: 'Melbourne' } }
```

## Development

Requires Node 18+.

```bash
npm install
npm test
npm install
npm test
npm run build
```

### Scripts

| Command | Description |
| --------------------- | ----------------------------- |
| `npm test` | Run tests with Vitest |
| `npm run test:terse` | Run tests with minimal output |
| `npm run test:watch` | Run tests in watch mode |
| `npm run lint` | Check with Biome |
| `npm run lint:fix` | Auto-fix with Biome |
| `npm run check-types` | TypeScript type checking |
| `npm run build` | Build with Vite |
| `npm run bench` | Run performance benchmark |
Loading
Loading