diff --git a/.eslintrc b/.eslintrc index 9c7ed24..4b42541 100644 --- a/.eslintrc +++ b/.eslintrc @@ -2,9 +2,6 @@ "ecmaFeatures": { "modules": true }, - "env": { - "es6": true - }, "rules": { "strict": [2, "global"], "quotes": [2, "single"], @@ -15,6 +12,7 @@ "space-before-function-paren": [2, {anonymous: "always", named: "never"}] }, "env": { + "es6": true, "node": true, "mocha": true } diff --git a/gulpfile.js b/gulpfile.js index 1a73bd9..4e4a013 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,4 +1,4 @@ -'use strict'; +'use strict'; // eslint-disable-line var path = require('path'); var gulp = require('gulp'); var eslint = require('gulp-eslint'); @@ -19,7 +19,7 @@ gulp.task('static', function () { .pipe(excludeGitignore()) .pipe(eslint()) .pipe(eslint.format()) - .pipe(eslint.failAfterError()) + .pipe(eslint.failAfterError()); }); gulp.task('nsp', function (cb) { @@ -40,10 +40,12 @@ gulp.task('test', ['pre-test'], function (cb) { .pipe(plumber()) .pipe(mocha({reporter: 'spec'})) .on('error', function (err) { + console.log('err', err); mochaErr = err; }) .pipe(istanbul.writeReports()) .on('end', function () { + console.log('end', mochaErr); cb(mochaErr); }); }); diff --git a/lib/index.js b/lib/index.js index 32d34b6..74747d5 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,6 +1,10 @@ -const update = require('app/utils/update/update'); -update.omit = require('app/utils/update/omit'); -update.reject = require('app/utils/update/reject'); -update.withDefault = require('app/utils/update/with_default'); +import update from './update'; +import omit from './omit'; +import reject from './reject'; +import withDefault from './withDefault'; -module.exports = update; +update.omit = omit; +update.reject = reject; +update.withDefault = withDefault; + +export default update; diff --git a/lib/omit.js b/lib/omit.js index 5af40e9..33074e5 100644 --- a/lib/omit.js +++ b/lib/omit.js @@ -1,4 +1,4 @@ -const omit = require('lodash/object/omit'); -const curry = require('lodash/function/curry'); +import omit from 'lodash/object/omit'; +import curry from 'lodash/function/curry'; -module.exports = curry((predicate, collection) => omit(collection, predicate)); +export default curry((predicate, collection) => omit(collection, predicate)); diff --git a/lib/reject.js b/lib/reject.js index 2b8485e..f4e0cf3 100644 --- a/lib/reject.js +++ b/lib/reject.js @@ -1,4 +1,4 @@ -const reject = require('lodash/collection/reject'); -const curry = require('lodash/function/curry'); +import reject from 'lodash/collection/reject'; +import curry from 'lodash/function/curry'; -module.exports = curry((predicate, collection) => reject(collection, predicate)); +export default curry((predicate, collection) => reject(collection, predicate)); diff --git a/lib/update.js b/lib/update.js index 90643fa..3fa7025 100644 --- a/lib/update.js +++ b/lib/update.js @@ -1,6 +1,6 @@ -const reduce = require('lodash/collection/reduce'); -const isEmpty = require('lodash/lang/isEmpty'); -const curry = require('lodash/function/curry'); +import reduce from 'lodash/collection/reduce'; +import isEmpty from 'lodash/lang/isEmpty'; +import curry from 'lodash/function/curry'; function resolveUpdates(updates, obj = {}) { return reduce(updates, (acc, value, key) => { @@ -56,4 +56,4 @@ function update(updates, obj) { return Object.assign({}, obj, resolvedUpdates); } -module.exports = curry(update); +export default curry(update); diff --git a/lib/withDefault.js b/lib/withDefault.js new file mode 100644 index 0000000..aa748a2 --- /dev/null +++ b/lib/withDefault.js @@ -0,0 +1,11 @@ +import update from './update'; + +export default function withDefault(defaultValue, updates) { + return (value) => { + if (typeof value === 'undefined') { + return update(updates, defaultValue); + } + + return update(updates, value); + }; +} diff --git a/lib/with_default.js b/lib/with_default.js deleted file mode 100644 index 1edacb5..0000000 --- a/lib/with_default.js +++ /dev/null @@ -1,11 +0,0 @@ -const update = require('app/utils/update/update'); - -module.exports = function withDefault(defaultValue, updates) { - return (value) => { - if (typeof value === "undefined") { - return update(updates, defaultValue); - } - - return update(updates, value); - }; -}; diff --git a/package.json b/package.json index 1c0d2c4..7a12a50 100644 --- a/package.json +++ b/package.json @@ -27,11 +27,12 @@ "url": "https://github.com/aaronjensen/updeep/issues" }, "peerDependencies": { - "lodash": "^3.10.0" + "lodash": "^3.0.0" }, "devDependencies": { "babel-core": "^5.5.0", "chai": "^3.2.0", + "eslint-config-airbnb": "0.0.7", "gulp": "^3.6.0", "gulp-babel": "^5.1.0", "gulp-coveralls": "^0.1.0", diff --git a/test/index.js b/test/index.js index b23834c..caacc89 100644 --- a/test/index.js +++ b/test/index.js @@ -1,59 +1,57 @@ import { expect } from 'chai'; import updeep from '../lib'; -console.log("testing"); -describe("updeep", () => { - it("does not change anything if no updates are specified", () => { -console.log("testing2"); +describe('updeep', () => { + it('does not change anything if no updates are specified', () => { const obj = { foo: 3, bar: [7, 5] }; const result = updeep({}, obj); expect(result).to.equal(obj); }); - it("can update with fixed values", () => { + it('can update with fixed values', () => { const obj = { foo: 3, bar: [7, 5] }; const result = updeep({ foo: 4 }, obj); expect(result).to.deep.equal({ foo: 4, bar: [7, 5] }); }); - it("returns the same instance if an update doesn't make changes", () => { + it('returns the same instance if an update doesn\'t make changes', () => { const obj = { foo: 3 }; const result = updeep({ foo: 3 }, obj); expect(result).to.equal(obj); }); - it("can update a nested structure", () => { + it('can update a nested structure', () => { const obj = { foo: { bar: 7, bam: 3 }, baz: 32 }; const result = updeep({ foo: { bar: 8 } }, obj); expect(result).to.deep.equal({ foo: { bar: 8, bam: 3 }, baz: 32 }); }); - it("can update arrays", () => { + it('can update arrays', () => { const obj = [1, 2, 3]; const result = updeep({ 1: 7 }, obj); expect(result).to.deep.equal([1, 7, 3]); }); - it("can add an element to an array", () => { + it('can add an element to an array', () => { const obj = []; const result = updeep({ 0: 3 }, obj); expect(result).to.eql([3]); }); - it("can update nested arrays", () => { + it('can update nested arrays', () => { const obj = { foo: [1, 2, 3], bar: 9 }; const result = updeep({ foo: { 1: 7 } }, obj); expect(result).to.deep.equal({ foo: [1, 7, 3], bar: 9 }); }); - it("can use functions to update values", () => { + it('can use functions to update values', () => { const inc = (i) => i + 1; const obj = { foo: 3, bar: 4, baz: 7 }; const result = updeep({ foo: inc, bar: inc }, obj); @@ -61,7 +59,7 @@ console.log("testing2"); expect(result).to.deep.equal({ foo: 4, bar: 5, baz: 7 }); }); - it("is curryable", () => { + it('is curryable', () => { const inc = (i) => i + 1; const obj = { foo: 3 }; const incFoo = updeep({ foo: inc }); @@ -71,17 +69,17 @@ console.log("testing2"); expect(result).to.deep.equal({ foo: 4 }); }); - it("can update if the value is an array", () => { + it('can update if the value is an array', () => { const obj = {}; const result = updeep({ foo: [0, 1] }, obj); expect(result).to.deep.equal({ foo: [0, 1] }); }); - it("can use withDefault to default things", () => { + it('can use withDefault to default things', () => { const obj = {}; const result = updeep({ - foo: update.withDefault([], { + foo: updeep.withDefault([], { 0: 'bar' }) }, obj);