Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump package versions #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "airbnb-base",
"extends": "conversio",
"env": {
"node": true,
"es6": true
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
language: node_js
node_js:
- '12'
- '10'
- '8'
- '6'
script:
- npm run lint
- npm test
Expand Down
8 changes: 7 additions & 1 deletion lib/objectOps.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,10 @@ const move = (obj, ...args) => ObjectOps.prototype.move.apply(obj, args);
const remove = (obj, ...args) => ObjectOps.prototype.remove.apply(obj, args);
const transform = (obj, ...args) => ObjectOps.prototype.transform.apply(obj, args);

module.exports = Object.assign(wrap, { clone, move, remove, transform, ObjectOps });
module.exports = Object.assign(wrap, {
clone,
move,
remove,
transform,
ObjectOps
});
14 changes: 6 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "object-ops",
"version": "1.0.1",
"version": "2.0.0",
"description": "Chainable, path-based modifying operations for JavaScript Objects.",
"main": "index.js",
"scripts": {
"lint": "NODE_ENV=test node_modules/.bin/eslint lib test",
"lint": "node_modules/.bin/eslint lib test",
"test": "NODE_ENV=test node_modules/.bin/ava"
},
"repository": {
Expand All @@ -24,11 +24,9 @@
},
"homepage": "https://github.com/getconversio/object-ops#readme",
"devDependencies": {
"ava": "^0.18.2",
"eslint": "^5",
"eslint-config-airbnb-base": "^11.1.0",
"eslint-plugin-import": "^2.2.0",
"should": "^11.2.0",
"sinon": "^1.17.7"
"ava": "^0.25.0",
"eslint": "^5.9.0",
"eslint-config-conversio": "^5.1.0",
"sinon": "^7.3.2"
}
}
2 changes: 1 addition & 1 deletion test/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const test = require('ava').test,
const { test } = require('ava'),
index = require('../'),
objOps = require('../lib/objectOps');

Expand Down
118 changes: 71 additions & 47 deletions test/lib/objectOps.js
Original file line number Diff line number Diff line change
@@ -1,88 +1,112 @@
'use strict';

const should = require('should'),
sinon = require('sinon'),
test = require('ava').test,
objOps = require('../../lib/objectOps');

const ObjectOps = objOps.ObjectOps;

test('#constructor can initialize from another object', () => {
should(new ObjectOps({ a: 1, b: { c: 2 } }))
.containEql({ a: 1, b: { c: 2 } });
const sinon = require('sinon'),
{ test } = require('ava'),
{ ObjectOps } = require('../../lib/objectOps');

test('#constructor can initialize from another object', t => {
t.deepEqual(
Object.assign({}, new ObjectOps({ a: 1, b: { c: 2 } })),
{ a: 1, b: { c: 2 } }
);
});

test('#clone returns a deep copy of the object', () => {
test('#clone returns a deep copy of the object', t => {
const base = new ObjectOps({ a: 1, b: { c: 2 } });
const clone = base.clone();

should(base).eql(clone);
should(base).not.equal(clone);
should(base.b).not.equal(clone.b);
t.deepEqual(base, clone);
t.not(base, clone);
t.not(base.b, clone.b);
});

test('#move copies the value from one path to another', () => {
should(new ObjectOps({ a: 1, b: { c: 2 } }).move('b.c', 'b.d'))
.eql(new ObjectOps({ a: 1, b: { d: 2 } }));
test('#move copies the value from one path to another', t => {
t.deepEqual(
new ObjectOps({ a: 1, b: { c: 2 } }).move('b.c', 'b.d'),
new ObjectOps({ a: 1, b: { d: 2 } })
);
});

test('#move errors out if source path does not exist', () => {
should(() => new ObjectOps({ a: 1, b: { c: 2 } }).move('c.c', 'b.c'))
.throw(TypeError, { message: 'Path is invalid at depth 0.' });
test('#move errors out if source path does not exist', t => {
t.throws(
() => new ObjectOps({ a: 1, b: { c: 2 } }).move('c.c', 'b.c'),
TypeError,
'Path is invalid at depth 0.'
);
});

test('#move builds the new path as needed', () => {
should(new ObjectOps({ a: 1, b: { c: 2 } }).move('b.c', 'c.b'))
.containEql({ c: { b: 2 } });
test('#move builds the new path as needed', t => {
t.deepEqual(
new ObjectOps({ a: 1, b: { c: 2 } }).move('b.c', 'c.b').c,
{ b: 2 }
);
});

test('#move fails if destination path exists and is not traversable', () => {
should(() => new ObjectOps({ a: 1, b: { c: 2 } }).move('b.c', 'a.b'))
.throw(TypeError, { message: 'Path not traversable on step "a". Expected Object, got "1".' });
test('#move fails if destination path exists and is not traversable', t => {
t.throws(
() => new ObjectOps({ a: 1, b: { c: 2 } }).move('b.c', 'a.b'),
TypeError,
'Path not traversable on step "a". Expected Object, got "1".'
);
});

test('#move removes the source value', () => {
should(new ObjectOps({ a: 1, b: { c: 2 } }).move('b.c', 'c.b'))
.containEql({ b: {} });
test('#move removes the source value', t => {
t.deepEqual(
new ObjectOps({ a: 1, b: { c: 2 } }).move('b.c', 'c.b').b,
{}
);
});

test('#move leaves the object untouched if an error occurs', () => {
test('#move leaves the object untouched if an error occurs', t => {
const obj = new ObjectOps({ a: 1, b: { c: 2 } });

try {
obj.move('b.c', 'a.b');
} catch (err) {
should(obj).eql(new ObjectOps({ a: 1, b: { c: 2 } }));
t.deepEqual(obj, new ObjectOps({ a: 1, b: { c: 2 } }));
}
});

test('#remove removes a path from the object', () => {
should(new ObjectOps({ a: 1, b: { c: 2 } }).remove('b.c'))
.eql(new ObjectOps({ a: 1, b: { } }));
test('#remove removes a path from the object', t => {
t.deepEqual(
new ObjectOps({ a: 1, b: { c: 2 } }).remove('b.c'),
new ObjectOps({ a: 1, b: { } })
);
});

test('#remove errors out if path doesn\'t exist', () => {
should(() => new ObjectOps({ a: 1, b: { c: 2 } }).remove('a.b'))
.throw(TypeError, { message: 'Expected object, got "1".' });
test('#remove errors out if path doesn\'t exist', t => {
t.throws(
() => new ObjectOps({ a: 1, b: { c: 2 } }).remove('a.b'),
TypeError,
'Expected object, got "1".'
);
});

test('#remove takes multiple paths', () => {
should(new ObjectOps({ a: 1, b: { c: 2 } }).remove('a', 'b'))
.eql(new ObjectOps());
test('#remove takes multiple paths', t => {
t.deepEqual(
new ObjectOps({ a: 1, b: { c: 2 } }).remove('a', 'b'),
new ObjectOps()
);
});

test('#transform calls a function with the value at path', () => {
test('#transform calls a function with the value at path', t => {
const spy = sinon.spy(() => {});
new ObjectOps({ a: 1, b: { c: 2 } }).transform('b.c', spy);
sinon.assert.calledWith(spy, 2);
t.pass();
});

test('#transform sets the value returned from the function', () => {
should(new ObjectOps({ a: 1, b: { c: 2 } }).transform('b.c', () => 3))
.eql(new ObjectOps({ a: 1, b: { c: 3 } }));
test('#transform sets the value returned from the function', t => {
t.deepEqual(
new ObjectOps({ a: 1, b: { c: 2 } }).transform('b.c', () => 3),
new ObjectOps({ a: 1, b: { c: 3 } })
);
});

test('#transform errors out if path doesn\'t exist', () => {
should(() => new ObjectOps({ a: 1, b: { c: 2 } }).transform('a.b', () => {}))
.throw(TypeError, { message: 'Path is invalid at depth 0.' });
test('#transform errors out if path doesn\'t exist', t => {
t.throws(
() => new ObjectOps({ a: 1, b: { c: 2 } }).transform('a.b', () => {}),
TypeError,
'Path is invalid at depth 0.'
);
});
Loading