Skip to content

Commit

Permalink
Bump package versions and deprecate node 6
Browse files Browse the repository at this point in the history
Signed-off-by: João Ferreira <[email protected]>
  • Loading branch information
jmnsf committed Jul 15, 2019
1 parent e94725f commit 0765120
Show file tree
Hide file tree
Showing 7 changed files with 746 additions and 486 deletions.
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
});
13 changes: 6 additions & 7 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,10 @@
},
"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",
"ava": "^0.25.0",
"eslint": "^5.9.0",
"eslint-config-conversio": "^5.1.0",
"should": "^11.2.0",
"sinon": "^1.17.7"
"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
105 changes: 64 additions & 41 deletions test/lib/objectOps.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,87 +2,110 @@

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

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

test('#constructor can initialize from another object', () => {
should(new ObjectOps({ a: 1, b: { c: 2 } }))
.containEql({ 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

0 comments on commit 0765120

Please sign in to comment.