Convert to es6 modules

This commit is contained in:
Aaron Jensen 2015-08-01 08:13:25 -07:00
parent 35fe73e080
commit 743b603216
10 changed files with 50 additions and 47 deletions

View File

@ -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
}

View File

@ -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);
});
});

View File

@ -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;

View File

@ -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));

View File

@ -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));

View File

@ -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);

11
lib/withDefault.js Normal file
View File

@ -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);
};
}

View File

@ -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);
};
};

View File

@ -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",

View File

@ -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);