From dcee2038b6a6bdd9d059b5bbd2db41482e33b11c Mon Sep 17 00:00:00 2001 From: Aaron Jensen Date: Tue, 18 Apr 2017 17:55:46 -0700 Subject: [PATCH] Format code with prettier --- .eslintrc | 17 +++- gulpfile.js | 113 ++++++++++++----------- karma.conf.js | 23 ++--- lib/constant.js | 8 +- lib/freeze.js | 31 ++++--- lib/if.js | 6 +- lib/ifElse.js | 14 ++- lib/index.js | 56 ++++++------ lib/is.js | 20 ++--- lib/map.js | 38 ++++---- lib/omit.js | 8 +- lib/omitBy.js | 8 +- lib/reject.js | 14 ++- lib/update.js | 71 ++++++++------- lib/updateIn.js | 30 +++---- lib/util/curry.js | 112 ++++++++++++----------- lib/util/splitPath.js | 6 +- lib/withDefault.js | 10 +-- lib/wrap.js | 9 +- package.json | 3 + perf/index.js | 98 ++++++++++---------- perf/webpack.config.js | 23 ++--- test/constant-spec.js | 22 ++--- test/freeze-spec.js | 88 +++++++++--------- test/if-spec.js | 61 +++++++------ test/ifElse-spec.js | 59 +++++++------ test/is-spec.js | 74 ++++++++-------- test/map-spec.js | 81 +++++++++-------- test/omit-spec.js | 16 ++-- test/omitBy-spec.js | 21 +++-- test/reject-spec.js | 54 ++++++----- test/updateIn-spec.js | 82 ++++++++--------- test/updeep-spec.js | 172 ++++++++++++++++++------------------ test/util/curry-spec.js | 142 ++++++++++++++--------------- test/util/splitPath-spec.js | 30 +++---- test/withDefault-spec.js | 41 +++++---- webpack.config.js | 6 +- yarn.lock | 117 +++++++++++++++++++++--- 38 files changed, 950 insertions(+), 834 deletions(-) diff --git a/.eslintrc b/.eslintrc index 982da7e..f532699 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,9 +1,24 @@ { - "extends": "airbnb-base", + "extends": [ + "airbnb-base", + "prettier" + ], + "plugins": [ + "prettier" + ], "ecmaFeatures": { "experimentalObjectRestSpread": true }, "rules": { + "prettier/prettier": [ + "error", + { + "bracketSpacing": true, + "semi": false, + "singleQuote": true, + "trailingComma": "es5" + } + ], "no-confusing-arrow": "off", "comma-dangle": ["error", { "arrays": "always-multiline", diff --git a/gulpfile.js b/gulpfile.js index f6a4faf..7c29290 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,88 +1,97 @@ -'use strict'; +'use strict' - /* eslint strict:0, no-var:0, func-names:0 */ -var path = require('path'); -var gulp = require('gulp'); +/* eslint strict:0, no-var:0, func-names:0 */ +var path = require('path') +var gulp = require('gulp') -var babel = require('gulp-babel'); -var eslint = require('gulp-eslint'); -var mocha = require('gulp-mocha'); -var nsp = require('gulp-nsp'); -var rimraf = require('rimraf'); -var webpack = require('webpack-stream'); +var babel = require('gulp-babel') +var eslint = require('gulp-eslint') +var mocha = require('gulp-mocha') +var nsp = require('gulp-nsp') +var rimraf = require('rimraf') +var webpack = require('webpack-stream') -var KarmaServer = require('karma').Server; +var KarmaServer = require('karma').Server -var createWebpackConfig = require('./createWebpackConfig.js'); +var createWebpackConfig = require('./createWebpackConfig.js') // Initialize the babel transpiler so ES2015 files gets compiled // when they're loaded -require('babel-core/register'); +require('babel-core/register') -gulp.task('clean', (cb) => { - rimraf('./dist', cb); -}); +gulp.task('clean', cb => { + rimraf('./dist', cb) +}) -gulp.task('static', () => gulp.src(['*.js', 'lib/**/*.js', 'test/**/*.js']) +gulp.task('static', () => + gulp + .src(['*.js', 'lib/**/*.js', 'test/**/*.js']) .pipe(eslint()) .pipe(eslint.format()) - .pipe(eslint.failAfterError())); + .pipe(eslint.failAfterError()) +) -gulp.task('nsp', (cb) => { - nsp({ package: path.join(__dirname, 'package.json') }, cb); -}); +gulp.task('nsp', cb => { + nsp({ package: path.join(__dirname, 'package.json') }, cb) +}) -gulp.task('test', ['test:karma', 'test:node']); +gulp.task('test', ['test:karma', 'test:node']) -gulp.task('test:node', () => gulp.src('test/**/*.js') - .pipe(mocha({ reporter: 'dot' }))); +gulp.task('test:node', () => + gulp.src('test/**/*.js').pipe(mocha({ reporter: 'dot' })) +) -gulp.task('test:karma', (done) => { - new KarmaServer({ - configFile: path.join(__dirname, 'karma.conf.js'), - singleRun: true, - }, done).start(); -}); +gulp.task('test:karma', done => { + new KarmaServer( + { + configFile: path.join(__dirname, 'karma.conf.js'), + singleRun: true, + }, + done + ).start() +}) -gulp.task('babel', () => gulp.src('lib/**/*.js') - .pipe(babel()) - .pipe(gulp.dest('dist'))); +gulp.task('babel', () => + gulp.src('lib/**/*.js').pipe(babel()).pipe(gulp.dest('dist')) +) gulp.task('watch', () => { - gulp.start(['test:node']); - gulp.watch(['lib/**/*.js', 'test/**/*.js'], ['test:node']); + gulp.start(['test:node']) + gulp.watch(['lib/**/*.js', 'test/**/*.js'], ['test:node']) new KarmaServer({ configFile: path.join(__dirname, 'karma.conf.js'), - }).start(); -}); + }).start() +}) -gulp.task('webpack', ['webpack:standalone', 'webpack:standalone:min']); +gulp.task('webpack', ['webpack:standalone', 'webpack:standalone:min']) gulp.task('webpack:standalone', () => { - var config = createWebpackConfig({ filename: 'updeep-standalone.js' }); + var config = createWebpackConfig({ filename: 'updeep-standalone.js' }) - return gulp.src('lib/index.js') + return gulp + .src('lib/index.js') .pipe(webpack(config)) - .pipe(gulp.dest('dist/umd/')); -}); + .pipe(gulp.dest('dist/umd/')) +}) gulp.task('webpack:standalone:min', () => { var config = createWebpackConfig({ filename: 'updeep-standalone.min.js', minify: true, env: 'production', - }); + }) - return gulp.src('lib/index.js') + return gulp + .src('lib/index.js') .pipe(webpack(config)) - .pipe(gulp.dest('dist/umd/')); -}); + .pipe(gulp.dest('dist/umd/')) +}) -gulp.task('build', ['babel', 'webpack']); +gulp.task('build', ['babel', 'webpack']) -gulp.task('build:clean', ['clean'], (done) => { - gulp.start('build', done); -}); +gulp.task('build:clean', ['clean'], done => { + gulp.start('build', done) +}) -gulp.task('prepublish', ['nsp', 'build:clean']); -gulp.task('default', ['static', 'test']); +gulp.task('prepublish', ['nsp', 'build:clean']) +gulp.task('default', ['static', 'test']) diff --git a/karma.conf.js b/karma.conf.js index b82c639..b5e17a7 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -1,30 +1,25 @@ -'use strict'; +'use strict' - /* eslint strict:0, no-var:0, func-names:0 */ +/* eslint strict:0, no-var:0, func-names:0 */ -var createWebpackConfig = require('./createWebpackConfig'); +var createWebpackConfig = require('./createWebpackConfig') -module.exports = function (config) { +module.exports = function(config) { config.set({ - // base path that will be used to resolve all patterns (eg. files, exclude) basePath: '', - // frameworks to use // available frameworks: https://npmjs.org/browse/keyword/karma-adapter frameworks: ['mocha'], - // list of files / patterns to load in the browser files: [ { pattern: 'test/**/*.js', watched: false, included: true, served: true }, ], // list of files to exclude - exclude: [ - ], - + exclude: [], // preprocess matching files before serving them to the browser // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor @@ -44,15 +39,12 @@ module.exports = function (config) { // available reporters: https://npmjs.org/browse/keyword/karma-reporter reporters: ['dots'], - // web server port port: 9876, - // enable / disable colors in the output (reporters and logs) colors: true, - // level of logging // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || // config.LOG_INFO || config.LOG_DEBUG @@ -62,9 +54,8 @@ module.exports = function (config) { // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher browsers: ['PhantomJS'], - // Continuous Integration mode // if true, Karma captures browsers, runs the tests and exits singleRun: false, - }); -}; + }) +} diff --git a/lib/constant.js b/lib/constant.js index f4e6bec..285c3b0 100644 --- a/lib/constant.js +++ b/lib/constant.js @@ -1,4 +1,4 @@ -import freeze from './freeze'; +import freeze from './freeze' /** * Returns a function that always returns the supplied value. @@ -33,8 +33,8 @@ import freeze from './freeze'; * expect(result).toEqual({ name: 'Mitch', favorites: { band: 'Coldplay' } }); */ function constant(value) { - const frozen = freeze(value); - return () => frozen; + const frozen = freeze(value) + return () => frozen } -export default constant; +export default constant diff --git a/lib/freeze.js b/lib/freeze.js index 24c3f00..28d53b0 100644 --- a/lib/freeze.js +++ b/lib/freeze.js @@ -1,26 +1,25 @@ function isFreezable(object) { - if (object === null) return false; - if (object instanceof RegExp) return false; + if (object === null) return false + if (object instanceof RegExp) return false - return Array.isArray(object) || - typeof object === 'object'; + return Array.isArray(object) || typeof object === 'object' } function needsFreezing(object) { - return isFreezable(object) && !Object.isFrozen(object); + return isFreezable(object) && !Object.isFrozen(object) } function recur(object) { - Object.freeze(object); + Object.freeze(object) - Object.keys(object).forEach((key) => { - const value = object[key]; + Object.keys(object).forEach(key => { + const value = object[key] if (needsFreezing(value)) { - recur(value); + recur(value) } - }); + }) - return object; + return object } /** @@ -39,18 +38,18 @@ function recur(object) { */ function freeze(object) { if (process.env.NODE_ENV === 'production') { - return object; + return object } if (process.env.UPDEEP_MODE === 'dangerously_never_freeze') { - return object; + return object } if (needsFreezing(object)) { - recur(object); + recur(object) } - return object; + return object } -export default freeze; +export default freeze diff --git a/lib/if.js b/lib/if.js index d8b1eac..5310282 100644 --- a/lib/if.js +++ b/lib/if.js @@ -1,6 +1,6 @@ -import ifElse from './ifElse'; -import curry from './util/curry'; +import ifElse from './ifElse' +import curry from './util/curry' export default curry((predicate, trueUpdates, object) => ifElse(predicate, trueUpdates, x => x, object) -); +) diff --git a/lib/ifElse.js b/lib/ifElse.js index e4855fe..5e6c107 100644 --- a/lib/ifElse.js +++ b/lib/ifElse.js @@ -1,14 +1,12 @@ -import update from './update'; -import wrap from './wrap'; +import update from './update' +import wrap from './wrap' function updateIfElse(predicate, trueUpdates, falseUpdates, object) { - const test = typeof predicate === 'function' ? - predicate(object) : - predicate; + const test = typeof predicate === 'function' ? predicate(object) : predicate - const updates = test ? trueUpdates : falseUpdates; + const updates = test ? trueUpdates : falseUpdates - return update(updates, object); + return update(updates, object) } -export default wrap(updateIfElse); +export default wrap(updateIfElse) diff --git a/lib/index.js b/lib/index.js index 5889166..e2a34db 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,31 +1,31 @@ -import constant from './constant'; -import freeze from './freeze'; -import is from './is'; -import _if from './if'; -import ifElse from './ifElse'; -import map from './map'; -import omit from './omit'; -import omitBy from './omitBy'; -import reject from './reject'; -import update from './update'; -import updateIn from './updateIn'; -import withDefault from './withDefault'; -import { _ } from './util/curry'; +import constant from './constant' +import freeze from './freeze' +import is from './is' +import _if from './if' +import ifElse from './ifElse' +import map from './map' +import omit from './omit' +import omitBy from './omitBy' +import reject from './reject' +import update from './update' +import updateIn from './updateIn' +import withDefault from './withDefault' +import { _ } from './util/curry' -const u = update; +const u = update -u._ = _; -u.constant = constant; -u.if = _if; -u.ifElse = ifElse; -u.is = is; -u.freeze = freeze; -u.map = map; -u.omit = omit; -u.omitBy = omitBy; -u.reject = reject; -u.update = update; -u.updateIn = updateIn; -u.withDefault = withDefault; +u._ = _ +u.constant = constant +u.if = _if +u.ifElse = ifElse +u.is = is +u.freeze = freeze +u.map = map +u.omit = omit +u.omitBy = omitBy +u.reject = reject +u.update = update +u.updateIn = updateIn +u.withDefault = withDefault -module.exports = u; +module.exports = u diff --git a/lib/is.js b/lib/is.js index e799955..bde98d5 100644 --- a/lib/is.js +++ b/lib/is.js @@ -1,21 +1,21 @@ -import splitPath from './util/splitPath'; -import curry from './util/curry'; +import splitPath from './util/splitPath' +import curry from './util/curry' function is(path, predicate, object) { - const parts = splitPath(path); + const parts = splitPath(path) - let rest = object; + let rest = object for (let i = 0; i < parts.length; i += 1) { - if (typeof rest === 'undefined') return false; - const part = parts[i]; - rest = rest[part]; + if (typeof rest === 'undefined') return false + const part = parts[i] + rest = rest[part] } if (typeof predicate === 'function') { - return predicate(rest); + return predicate(rest) } - return predicate === rest; + return predicate === rest } -export default curry(is); +export default curry(is) diff --git a/lib/map.js b/lib/map.js index 7938950..cb685b1 100644 --- a/lib/map.js +++ b/lib/map.js @@ -1,39 +1,33 @@ -import forEach from 'lodash/forEach'; -import mapArray from 'lodash/map'; -import mapObject from 'lodash/mapValues'; -import update from './update'; -import wrap from './wrap'; +import forEach from 'lodash/forEach' +import mapArray from 'lodash/map' +import mapObject from 'lodash/mapValues' +import update from './update' +import wrap from './wrap' function shallowEqual(object, otherObject) { - let equal = true; + let equal = true // eslint-disable-next-line consistent-return forEach(otherObject, (value, key) => { if (value !== object[key]) { - equal = false; + equal = false // exit early - return false; + return false } - }); + }) - return equal; + return equal } function map(iteratee, object) { - const updater = typeof iteratee === 'function' ? - iteratee : - update(iteratee); + const updater = typeof iteratee === 'function' ? iteratee : update(iteratee) - const mapper = Array.isArray(object) ? - mapArray : - mapObject; + const mapper = Array.isArray(object) ? mapArray : mapObject - const newObject = mapper(object, updater); - const equal = shallowEqual(object, newObject); + const newObject = mapper(object, updater) + const equal = shallowEqual(object, newObject) - return equal ? - object : - newObject; + return equal ? object : newObject } -export default wrap(map); +export default wrap(map) diff --git a/lib/omit.js b/lib/omit.js index 16ec9ca..93f76d0 100644 --- a/lib/omit.js +++ b/lib/omit.js @@ -1,8 +1,8 @@ -import _omit from 'lodash/omit'; -import wrap from './wrap'; +import _omit from 'lodash/omit' +import wrap from './wrap' function omit(predicate, collection) { - return _omit(collection, predicate); + return _omit(collection, predicate) } -export default wrap(omit); +export default wrap(omit) diff --git a/lib/omitBy.js b/lib/omitBy.js index eccdec2..4eab507 100644 --- a/lib/omitBy.js +++ b/lib/omitBy.js @@ -1,8 +1,8 @@ -import _omitBy from 'lodash/omitBy'; -import wrap from './wrap'; +import _omitBy from 'lodash/omitBy' +import wrap from './wrap' function omitBy(predicate, collection) { - return _omitBy(collection, predicate); + return _omitBy(collection, predicate) } -export default wrap(omitBy); +export default wrap(omitBy) diff --git a/lib/reject.js b/lib/reject.js index 9ec1b74..55046c0 100644 --- a/lib/reject.js +++ b/lib/reject.js @@ -1,13 +1,11 @@ -import _reject from 'lodash/reject'; -import wrap from './wrap'; +import _reject from 'lodash/reject' +import wrap from './wrap' function reject(predicate, collection) { - const result = _reject(collection, predicate); - const equal = collection.length === result.length; + const result = _reject(collection, predicate) + const equal = collection.length === result.length - return equal ? - collection : - result; + return equal ? collection : result } -export default wrap(reject); +export default wrap(reject) diff --git a/lib/update.js b/lib/update.js index ecbd732..3791fdc 100644 --- a/lib/update.js +++ b/lib/update.js @@ -1,40 +1,49 @@ -import isPlainObject from 'lodash/isPlainObject'; -import wrap from './wrap'; +import isPlainObject from 'lodash/isPlainObject' +import wrap from './wrap' function isEmpty(object) { - return !Object.keys(object).length; + return !Object.keys(object).length } function reduce(object, callback, initialValue) { - return Object.keys(object).reduce((acc, key) => callback(acc, object[key], key), initialValue); + return Object.keys(object).reduce( + (acc, key) => callback(acc, object[key], key), + initialValue + ) } function resolveUpdates(updates, object) { - return reduce(updates, (acc, value, key) => { - let updatedValue = value; + return reduce( + updates, + (acc, value, key) => { + let updatedValue = value - if (!Array.isArray(value) && value !== null && typeof value === 'object') { - updatedValue = update(value, object[key]); // eslint-disable-line no-use-before-define - } else if (typeof value === 'function') { - updatedValue = value(object[key]); - } + if ( + !Array.isArray(value) && value !== null && typeof value === 'object' + ) { + updatedValue = update(value, object[key]) // eslint-disable-line no-use-before-define + } else if (typeof value === 'function') { + updatedValue = value(object[key]) + } - if (object[key] !== updatedValue) { - acc[key] = updatedValue; // eslint-disable-line no-param-reassign - } + if (object[key] !== updatedValue) { + acc[key] = updatedValue // eslint-disable-line no-param-reassign + } - return acc; - }, {}); + return acc + }, + {} + ) } function updateArray(updates, object) { - const newArray = [...object]; + const newArray = [...object] - Object.keys(updates).forEach((key) => { - newArray[key] = updates[key]; - }); + Object.keys(updates).forEach(key => { + newArray[key] = updates[key] + }) - return newArray; + return newArray } /** @@ -56,28 +65,28 @@ function updateArray(updates, object) { */ function update(updates, object, ...args) { if (typeof updates === 'function') { - return updates(object, ...args); + return updates(object, ...args) } if (!isPlainObject(updates)) { - return updates; + return updates } - const defaultedObject = (typeof object === 'undefined' || object === null) ? - {} : - object; + const defaultedObject = typeof object === 'undefined' || object === null + ? {} + : object - const resolvedUpdates = resolveUpdates(updates, defaultedObject); + const resolvedUpdates = resolveUpdates(updates, defaultedObject) if (isEmpty(resolvedUpdates)) { - return defaultedObject; + return defaultedObject } if (Array.isArray(defaultedObject)) { - return updateArray(resolvedUpdates, defaultedObject); + return updateArray(resolvedUpdates, defaultedObject) } - return { ...defaultedObject, ...resolvedUpdates }; + return { ...defaultedObject, ...resolvedUpdates } } -export default wrap(update, 2); +export default wrap(update, 2) diff --git a/lib/updateIn.js b/lib/updateIn.js index 8b388c9..468758c 100644 --- a/lib/updateIn.js +++ b/lib/updateIn.js @@ -1,28 +1,28 @@ -import curry from './util/curry'; -import update from './update'; -import map from './map'; -import splitPath from './util/splitPath'; +import curry from './util/curry' +import update from './update' +import map from './map' +import splitPath from './util/splitPath' -const wildcard = '*'; +const wildcard = '*' function reducePath(acc, key) { if (key === wildcard) { return value => - Object.prototype.hasOwnProperty.call(value, wildcard) ? - // If we actually have wildcard as a property, update that - update({ [wildcard]: acc }, value) : - // Otherwise map over all properties - map(acc, value); + (Object.prototype.hasOwnProperty.call(value, wildcard) + ? // If we actually have wildcard as a property, update that + update({ [wildcard]: acc }, value) + : // Otherwise map over all properties + map(acc, value)) } - return { [key]: acc }; + return { [key]: acc } } function updateIn(path, value, object) { - const parts = splitPath(path); - const updates = parts.reduceRight(reducePath, value); + const parts = splitPath(path) + const updates = parts.reduceRight(reducePath, value) - return update(updates, object); + return update(updates, object) } -export default curry(updateIn); +export default curry(updateIn) diff --git a/lib/util/curry.js b/lib/util/curry.js index 1f73505..c650623 100644 --- a/lib/util/curry.js +++ b/lib/util/curry.js @@ -1,128 +1,126 @@ /* eslint no-shadow:0, no-param-reassign:0 prefer-rest-params:0 */ -export const _ = '@@updeep/placeholder'; +export const _ = '@@updeep/placeholder' function countArguments(args, max) { - let n = args.length; - if (n > max) n = max; + let n = args.length + if (n > max) n = max while (args[n - 1] === _) { - n -= 1; + n -= 1 } - return n; + return n } export function curry1(fn) { return function curried(a, ...args) { - const [b, c] = args; - const n = countArguments(arguments); + const [b, c] = args + const n = countArguments(arguments) - if (n >= 1) return fn(a, b, c); - return curried; - }; + if (n >= 1) return fn(a, b, c) + return curried + } } export function curry2(fn) { return function curried(a, b, ...args) { - const [c, d] = args; - const n = countArguments(arguments, 2); + const [c, d] = args + const n = countArguments(arguments, 2) if (b === _ || c === _ || d === _) { - throw new Error('Can only use placeholder on first argument of this function.'); + throw new Error( + 'Can only use placeholder on first argument of this function.' + ) } if (n >= 2) { - if (a === _) return curry1((a, c, d) => fn(a, b, c, d)); - return fn(a, b, c, d); + if (a === _) return curry1((a, c, d) => fn(a, b, c, d)) + return fn(a, b, c, d) } - if (n === 1) return curry1((b, c, d) => fn(a, b, c, d)); - return curried; - }; + if (n === 1) return curry1((b, c, d) => fn(a, b, c, d)) + return curried + } } export function curry3(fn) { return function curried(a, b, c, ...args) { - const [d, e] = args; - const n = countArguments(arguments, 3); + const [d, e] = args + const n = countArguments(arguments, 3) if (c === _ || d === _ || e === _) { - throw new Error('Can only use placeholder on first or second argument of this function.'); + throw new Error( + 'Can only use placeholder on first or second argument of this function.' + ) } if (n >= 3) { if (a === _) { - if (b === _) return curry2((a, b, d, e) => fn(a, b, c, d, e)); - return curry1((a, d, e) => fn(a, b, c, d, e)); + if (b === _) return curry2((a, b, d, e) => fn(a, b, c, d, e)) + return curry1((a, d, e) => fn(a, b, c, d, e)) } - if (b === _) return curry1((b, d, e) => fn(a, b, c, d, e)); - return fn(a, b, c, d, e); + if (b === _) return curry1((b, d, e) => fn(a, b, c, d, e)) + return fn(a, b, c, d, e) } if (n === 2) { - if (a === _) return curry2((a, c, d, e) => fn(a, b, c, d, e)); - return curry1((c, d, e) => fn(a, b, c, d, e)); + if (a === _) return curry2((a, c, d, e) => fn(a, b, c, d, e)) + return curry1((c, d, e) => fn(a, b, c, d, e)) } - if (n === 1) return curry2((b, c, d, e) => fn(a, b, c, d, e)); + if (n === 1) return curry2((b, c, d, e) => fn(a, b, c, d, e)) - return curried; - }; + return curried + } } export function curry4(fn) { return function curried(a, b, c, d, ...args) { - const [e, f] = args; - const n = countArguments(arguments, 4); + const [e, f] = args + const n = countArguments(arguments, 4) if (d === _ || e === _ || f === _) { throw new Error( 'Can only use placeholder on first, second or third argument of this function.' - ); + ) } if (n >= 4) { if (a === _) { if (b === _) { - if (c === _) return curry3((a, b, c, e, f) => fn(a, b, c, d, e, f)); - return curry2((a, b, e, f) => fn(a, b, c, d, e, f)); + if (c === _) return curry3((a, b, c, e, f) => fn(a, b, c, d, e, f)) + return curry2((a, b, e, f) => fn(a, b, c, d, e, f)) } - if (c === _) return curry2((a, c, e, f) => fn(a, b, c, d, e, f)); - return curry1((a, e, f) => fn(a, b, c, d, e, f)); + if (c === _) return curry2((a, c, e, f) => fn(a, b, c, d, e, f)) + return curry1((a, e, f) => fn(a, b, c, d, e, f)) } if (b === _) { - if (c === _) return curry2((b, c, e, f) => fn(a, b, c, d, e, f)); - return curry1((b, e, f) => fn(a, b, c, d, e, f)); + if (c === _) return curry2((b, c, e, f) => fn(a, b, c, d, e, f)) + return curry1((b, e, f) => fn(a, b, c, d, e, f)) } - if (c === _) return curry1((c, e, f) => fn(a, b, c, d, e, f)); - return fn(a, b, c, d, e, f); + if (c === _) return curry1((c, e, f) => fn(a, b, c, d, e, f)) + return fn(a, b, c, d, e, f) } if (n === 3) { if (a === _) { - if (b === _) return curry3((a, b, d, e, f) => fn(a, b, c, d, e, f)); - return curry2((a, d, e, f) => fn(a, b, c, d, e, f)); + if (b === _) return curry3((a, b, d, e, f) => fn(a, b, c, d, e, f)) + return curry2((a, d, e, f) => fn(a, b, c, d, e, f)) } - if (b === _) return curry2((b, d, e, f) => fn(a, b, c, d, e, f)); - return curry1((d, e, f) => fn(a, b, c, d, e, f)); + if (b === _) return curry2((b, d, e, f) => fn(a, b, c, d, e, f)) + return curry1((d, e, f) => fn(a, b, c, d, e, f)) } if (n === 2) { - if (a === _) return curry3((a, c, d, e, f) => fn(a, b, c, d, e, f)); - return curry2((c, d, e, f) => fn(a, b, c, d, e, f)); + if (a === _) return curry3((a, c, d, e, f) => fn(a, b, c, d, e, f)) + return curry2((c, d, e, f) => fn(a, b, c, d, e, f)) } - if (n === 1) return curry3((b, c, d, e, f) => fn(a, b, c, d, e, f)); - return curried; - }; + if (n === 1) return curry3((b, c, d, e, f) => fn(a, b, c, d, e, f)) + return curried + } } export default function curry(fn, length = fn.length) { - return [ - fn, - curry1, - curry2, - curry3, - curry4, - ][length](fn); + return [fn, curry1, curry2, curry3, curry4][length](fn) } diff --git a/lib/util/splitPath.js b/lib/util/splitPath.js index ea89253..a3410fe 100644 --- a/lib/util/splitPath.js +++ b/lib/util/splitPath.js @@ -1,7 +1,5 @@ -import reject from 'lodash/reject'; +import reject from 'lodash/reject' export default function splitPath(path) { - return Array.isArray(path) ? - path : - reject((`${path}`).split('.'), x => !x); + return Array.isArray(path) ? path : reject(`${path}`.split('.'), x => !x) } diff --git a/lib/withDefault.js b/lib/withDefault.js index 3dc1fe1..5e0d54a 100644 --- a/lib/withDefault.js +++ b/lib/withDefault.js @@ -1,12 +1,12 @@ -import update from './update'; -import curry from './util/curry'; +import update from './update' +import curry from './util/curry' function withDefault(defaultValue, updates, object) { if (typeof object === 'undefined') { - return update(updates, defaultValue); + return update(updates, defaultValue) } - return update(updates, object); + return update(updates, object) } -export default curry(withDefault); +export default curry(withDefault) diff --git a/lib/wrap.js b/lib/wrap.js index 918e286..d28215d 100644 --- a/lib/wrap.js +++ b/lib/wrap.js @@ -1,9 +1,6 @@ -import curry from './util/curry'; -import freeze from './freeze'; +import curry from './util/curry' +import freeze from './freeze' export default function wrap(func, length = func.length) { - return curry( - (...args) => freeze(func(...args)), - length - ); + return curry((...args) => freeze(func(...args)), length) } diff --git a/package.json b/package.json index 26651d1..1eb9789 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,9 @@ "chai": "^3.2.0", "eslint": "^3.19.0", "eslint-config-airbnb-base": "^11.1.3", + "eslint-config-prettier": "^1.6.0", "eslint-plugin-import": "^2.2.0", + "eslint-plugin-prettier": "^2.0.1", "exports-loader": "^0.6.2", "gulp": "^3.6.0", "gulp-babel": "^6.1.1", @@ -56,6 +58,7 @@ "karma-webpack": "^1.7.0", "mocha": "^2.2.5", "phantomjs-prebuilt": "^2.1.14", + "prettier": "^1.1.0", "rimraf": "^2.4.2", "webpack": "^1.10.5", "webpack-dev-server": "^1.10.1", diff --git a/perf/index.js b/perf/index.js index 7ab68c7..580a38f 100644 --- a/perf/index.js +++ b/perf/index.js @@ -1,87 +1,87 @@ /* eslint no-console:0, no-unused-vars:0, import/no-extraneous-dependencies:0 */ /* global document */ -const Benchmark = require('benchmark'); +const Benchmark = require('benchmark') -const u = require('../lib'); -const _ = require('lodash'); -const { curry2, curry4 } = require('../lib/util/curry'); +const u = require('../lib') +const _ = require('lodash') +const { curry2, curry4 } = require('../lib/util/curry') -const add4 = (a, b, c, d) => a + b + c + d; -const add2 = (a, b) => a + b; -const fakeCurryAdd = x => y => x + y; -const lodashCurryAdd2 = _.curry(add2); -const updeepCurryAdd2 = curry2(add2); -const lodashCurryAdd4 = _.curry(add4); -const updeepCurryAdd4 = curry4(add4); +const add4 = (a, b, c, d) => a + b + c + d +const add2 = (a, b) => a + b +const fakeCurryAdd = x => y => x + y +const lodashCurryAdd2 = _.curry(add2) +const updeepCurryAdd2 = curry2(add2) +const lodashCurryAdd4 = _.curry(add4) +const updeepCurryAdd4 = curry4(add4) // const updeepCurryBig = curry.curryBig(add); -const array = [0, 1, 2, 3, 4, 5]; +const array = [0, 1, 2, 3, 4, 5] // const doUpdate = u(x => x + 1); function log(str) { if (typeof document !== 'undefined') { - console.log(str); - const el = document.getElementById('perf'); - el.innerHTML += str; + console.log(str) + const el = document.getElementById('perf') + el.innerHTML += str } } function createSuite(suiteName, tests) { - const suite = Benchmark.Suite(); // eslint-disable + const suite = Benchmark.Suite() // eslint-disable return () => { - log(`

${suiteName}

') + }) + .run({ async: true }) + } } - const curryVsLodash = createSuite('Curry', { 'updeep curry': () => { - updeepCurryAdd4(3)(4)(5)(6); - updeepCurryAdd4(3, 4, 5, 6); - updeepCurryAdd4(u._, 4, u._, 6)(3, 4); - updeepCurryAdd2(3)(4); - updeepCurryAdd2(3, 4); + updeepCurryAdd4(3)(4)(5)(6) + updeepCurryAdd4(3, 4, 5, 6) + updeepCurryAdd4(u._, 4, u._, 6)(3, 4) + updeepCurryAdd2(3)(4) + updeepCurryAdd2(3, 4) }, 'lodash curry': () => { - lodashCurryAdd4(3)(4)(5)(6); - lodashCurryAdd4(3, 4, 5, 6); - lodashCurryAdd4(_, 4, _, 6)(3, 4); - lodashCurryAdd2(3)(4); - lodashCurryAdd2(3, 4); + lodashCurryAdd4(3)(4)(5)(6) + lodashCurryAdd4(3, 4, 5, 6) + lodashCurryAdd4(_, 4, _, 6)(3, 4) + lodashCurryAdd2(3)(4) + lodashCurryAdd2(3, 4) }, -}); +}) const mapVsLodash = createSuite('Map', { '_.map': () => _.map(array, fakeCurryAdd(8)), 'u.map': () => u.map(fakeCurryAdd(8), array), -}); +}) -const fn = (a, b, c, d, e) => a + b + c + d + e; -const fnControl = (a, b, c, d, e) => fn(a, b, c, d, e); -const fnApply = (...args) => fn(...args); +const fn = (a, b, c, d, e) => a + b + c + d + e +const fnControl = (a, b, c, d, e) => fn(a, b, c, d, e) +const fnApply = (...args) => fn(...args) const fnDestructure = (...args) => { - const [a, b, c, d, e] = args; - return fn(a, b, c, d, e); -}; + const [a, b, c, d, e] = args + return fn(a, b, c, d, e) +} const applyVsDestructure = createSuite('apply vs destructure', { control: () => fnControl(1, 2, 3, 4, 5), apply: () => fnApply(1, 2, 3, 4, 5), destructure: () => fnDestructure(1, 2, 3, 4, 5), -}); +}) -curryVsLodash(); -mapVsLodash(); +curryVsLodash() +mapVsLodash() // applyVsDestructure(); diff --git a/perf/webpack.config.js b/perf/webpack.config.js index e78facc..07ba36a 100644 --- a/perf/webpack.config.js +++ b/perf/webpack.config.js @@ -1,34 +1,29 @@ -'use strict'; +'use strict' - /* eslint strict:0, no-var:0, func-names:0 */ +/* eslint strict:0, no-var:0, func-names:0 */ -var path = require('path'); +var path = require('path') var config = require('../createWebpackConfig')({ context: __dirname, - entry: [ - 'webpack/hot/dev-server', - './index.js', - ], + entry: ['webpack/hot/dev-server', './index.js'], minify: false, env: 'production', -}); +}) config.output = { path: path.join(__dirname, './build'), publicPath: '/assets/', filename: 'perf.js', -}; +} config.devServer = { contentBase: __dirname, noInfo: true, hot: true, inline: true, -}; +} -config.module.noParse = [ - /benchmark\.js$/, -]; +config.module.noParse = [/benchmark\.js$/] -module.exports = config; +module.exports = config diff --git a/test/constant-spec.js b/test/constant-spec.js index bcf4593..83f7c65 100644 --- a/test/constant-spec.js +++ b/test/constant-spec.js @@ -1,17 +1,17 @@ -import { expect } from 'chai'; -import u from '../lib'; +import { expect } from 'chai' +import u from '../lib' describe('u.constant', () => { it('returns what it is given... constantly', () => { - const func = u.constant(4); + const func = u.constant(4) - expect(func()).to.equal(4); - expect(func('hi')).to.equal(4); - expect(func('hi', 8)).to.equal(4); - expect(func(4)).to.equal(4); - }); + expect(func()).to.equal(4) + expect(func('hi')).to.equal(4) + expect(func('hi', 8)).to.equal(4) + expect(func(4)).to.equal(4) + }) it('freezes the result', () => { - expect(Object.isFrozen(u.constant({})())).to.be.true; - }); -}); + expect(Object.isFrozen(u.constant({})())).to.be.true + }) +}) diff --git a/test/freeze-spec.js b/test/freeze-spec.js index 7fd9bfc..97a4960 100644 --- a/test/freeze-spec.js +++ b/test/freeze-spec.js @@ -1,74 +1,74 @@ -import { expect } from 'chai'; -import u from '../lib'; +import { expect } from 'chai' +import u from '../lib' describe('u.freeze', () => { afterEach(() => { - delete process.env.NODE_ENV; - }); + delete process.env.NODE_ENV + }) it('freezes objects', () => { - const object = {}; - u.freeze(object); + const object = {} + u.freeze(object) - expect(Object.isFrozen(object)).to.be.true; - }); + expect(Object.isFrozen(object)).to.be.true + }) it('freezes nested objects', () => { - const object = { foo: { bar: 3 } }; - u.freeze(object); + const object = { foo: { bar: 3 } } + u.freeze(object) - expect(Object.isFrozen(object.foo)).to.be.true; - }); + expect(Object.isFrozen(object.foo)).to.be.true + }) it('freezes nested arrays', () => { - const object = [[0]]; - u.freeze(object); + const object = [[0]] + u.freeze(object) - expect(Object.isFrozen(object)).to.be.true; - expect(Object.isFrozen(object[0])).to.be.true; - }); + expect(Object.isFrozen(object)).to.be.true + expect(Object.isFrozen(object[0])).to.be.true + }) it('ignores functions', () => { - const object = { foo: () => 1 }; - u.freeze(object); + const object = { foo: () => 1 } + u.freeze(object) - expect(Object.isFrozen(object.foo)).to.be.false; - }); + expect(Object.isFrozen(object.foo)).to.be.false + }) it('ignores regexps', () => { - const object = { foo: /\d/ }; - u.freeze(object); + const object = { foo: /\d/ } + u.freeze(object) - expect(Object.isFrozen(object.foo)).to.be.false; - }); + expect(Object.isFrozen(object.foo)).to.be.false + }) it('does not freeze children if the parent is already frozen', () => { - const object = { foo: {} }; - Object.freeze(object); - u.freeze(object); + const object = { foo: {} } + Object.freeze(object) + u.freeze(object) - expect(Object.isFrozen(object.foo)).to.be.false; - }); + expect(Object.isFrozen(object.foo)).to.be.false + }) if (typeof process !== 'undefined') { it('does not freeze in production', () => { - process.env.NODE_ENV = 'production'; - const object = {}; - u.freeze(object); + process.env.NODE_ENV = 'production' + const object = {} + u.freeze(object) - expect(Object.isFrozen(object)).to.be.false; - }); + expect(Object.isFrozen(object)).to.be.false + }) } it('handles null objects', () => { - const object = { foo: null }; - u.freeze(object); - expect(Object.isFrozen(object)).to.be.true; - }); + const object = { foo: null } + u.freeze(object) + expect(Object.isFrozen(object)).to.be.true + }) it('returns the same object', () => { - const object = {}; - const result = u.freeze(object); - expect(result).to.equal(object); - }); -}); + const object = {} + const result = u.freeze(object) + expect(result).to.equal(object) + }) +}) diff --git a/test/if-spec.js b/test/if-spec.js index 1a9a480..0775e65 100644 --- a/test/if-spec.js +++ b/test/if-spec.js @@ -1,44 +1,47 @@ -import { expect } from 'chai'; -import u from '../lib'; +import { expect } from 'chai' +import u from '../lib' describe('u.if', () => { it('does not update if the predicate is false', () => { - const object = { a: 0 }; - let result = u.if(false, { b: 1 }, object); - expect(result).to.eql(object); + const object = { a: 0 } + let result = u.if(false, { b: 1 }, object) + expect(result).to.eql(object) - result = u({ x: u.if(false, 1) }, {}); - expect(result).to.eql({}); - }); + result = u({ x: u.if(false, 1) }, {}) + expect(result).to.eql({}) + }) it('does update if the predicate is true', () => { - const object = { a: 0 }; - const result = u.if(true, { b: 1 }, object); - expect(result).to.eql({ a: 0, b: 1 }); - }); + const object = { a: 0 } + const result = u.if(true, { b: 1 }, object) + expect(result).to.eql({ a: 0, b: 1 }) + }) it('will use the result of a function passed as a predicate', () => { - const object = { a: 0 }; - const aIsThree = x => x.a === 3; - const result = u.if(aIsThree, { b: 1 }, object); + const object = { a: 0 } + const aIsThree = x => x.a === 3 + const result = u.if(aIsThree, { b: 1 }, object) - expect(result).to.eql({ a: 0 }); - }); + expect(result).to.eql({ a: 0 }) + }) it('can be partially applied', () => { - const object = { a: 2 }; - const isEven = x => x % 2 === 0; - const inc = x => x + 1; + const object = { a: 2 } + const isEven = x => x % 2 === 0 + const inc = x => x + 1 - const result = u({ - a: u.if(isEven, inc), - }, object); + const result = u( + { + a: u.if(isEven, inc), + }, + object + ) - expect(result).to.eql({ a: 3 }); - }); + expect(result).to.eql({ a: 3 }) + }) it('freezes the result', () => { - expect(Object.isFrozen(u.if(true, {}, {}))).to.be.true; - expect(Object.isFrozen(u.if(false, {}, {}))).to.be.true; - }); -}); + expect(Object.isFrozen(u.if(true, {}, {}))).to.be.true + expect(Object.isFrozen(u.if(false, {}, {}))).to.be.true + }) +}) diff --git a/test/ifElse-spec.js b/test/ifElse-spec.js index efed4ca..bf45de4 100644 --- a/test/ifElse-spec.js +++ b/test/ifElse-spec.js @@ -1,42 +1,45 @@ -import { expect } from 'chai'; -import u from '../lib'; +import { expect } from 'chai' +import u from '../lib' describe('u.ifElse', () => { it('does updates with the else if the predicate is false', () => { - const object = { a: 0 }; - const result = u.ifElse(false, { b: 1 }, { b: 2 }, object); - expect(result).to.eql({ a: 0, b: 2 }); - }); + const object = { a: 0 } + const result = u.ifElse(false, { b: 1 }, { b: 2 }, object) + expect(result).to.eql({ a: 0, b: 2 }) + }) it('updates with the true update if the predicate is true', () => { - const object = { a: 0 }; - const result = u.ifElse(true, { b: 1 }, { b: 4 }, object); - expect(result).to.eql({ a: 0, b: 1 }); - }); + const object = { a: 0 } + const result = u.ifElse(true, { b: 1 }, { b: 4 }, object) + expect(result).to.eql({ a: 0, b: 1 }) + }) it('will use the result of a function passed as a predicate', () => { - const object = { a: 0 }; - const aIsThree = x => x.a === 3; - const result = u.ifElse(aIsThree, { b: 1 }, { b: 4 }, object); + const object = { a: 0 } + const aIsThree = x => x.a === 3 + const result = u.ifElse(aIsThree, { b: 1 }, { b: 4 }, object) - expect(result).to.eql({ a: 0, b: 4 }); - }); + expect(result).to.eql({ a: 0, b: 4 }) + }) it('can be partially applied', () => { - const object = { a: 2 }; - const isEven = x => x % 2 === 0; - const inc = x => x + 1; - const dec = x => x - 1; + const object = { a: 2 } + const isEven = x => x % 2 === 0 + const inc = x => x + 1 + const dec = x => x - 1 - const result = u({ - a: u.ifElse(isEven, inc, dec), - }, object); + const result = u( + { + a: u.ifElse(isEven, inc, dec), + }, + object + ) - expect(result).to.eql({ a: 3 }); - }); + expect(result).to.eql({ a: 3 }) + }) it('freezes the result', () => { - expect(Object.isFrozen(u.ifElse(true, {}, {}, {}))).to.be.true; - expect(Object.isFrozen(u.ifElse(false, {}, {}, {}))).to.be.true; - }); -}); + expect(Object.isFrozen(u.ifElse(true, {}, {}, {}))).to.be.true + expect(Object.isFrozen(u.ifElse(false, {}, {}, {}))).to.be.true + }) +}) diff --git a/test/is-spec.js b/test/is-spec.js index f084066..cc9fd53 100644 --- a/test/is-spec.js +++ b/test/is-spec.js @@ -1,59 +1,59 @@ -import { expect } from 'chai'; -import u from '../lib'; +import { expect } from 'chai' +import u from '../lib' describe('u.is', () => { it('returns true if path matches a value predicate', () => { - const result = u.is('a.b', 4, { a: { b: 4 } }); - expect(result).to.be.true; - }); + const result = u.is('a.b', 4, { a: { b: 4 } }) + expect(result).to.be.true + }) it('returns true if path matches a function predicate', () => { - const isEven = x => x % 2 === 0; - const result = u.is('a.b', isEven, { a: { b: 6 } }); - expect(result).to.be.true; - }); + const isEven = x => x % 2 === 0 + const result = u.is('a.b', isEven, { a: { b: 6 } }) + expect(result).to.be.true + }) it('returns false if path matches a value predicate', () => { - const result = u.is('a.b', 4, { a: { b: 5 } }); - expect(result).to.be.false; - }); + const result = u.is('a.b', 4, { a: { b: 5 } }) + expect(result).to.be.false + }) it('returns false if path matches a function predicate', () => { - const isEven = x => x % 2 === 0; - const result = u.is('a.b', isEven, { a: { b: 7 } }); - expect(result).to.be.false; - }); + const isEven = x => x % 2 === 0 + const result = u.is('a.b', isEven, { a: { b: 7 } }) + expect(result).to.be.false + }) it('returns false if the path does not exist', () => { - const result = u.is('a.b.c.d', 4, { a: { b: {} } }); - expect(result).to.be.false; - }); + const result = u.is('a.b.c.d', 4, { a: { b: {} } }) + expect(result).to.be.false + }) it('can test for undefined', () => { - const result = u.is('a.b.c', undefined, { a: { b: {} } }); - expect(result).to.be.true; - }); + const result = u.is('a.b.c', undefined, { a: { b: {} } }) + expect(result).to.be.true + }) it('tests the actual object if a blank path is given', () => { - const result = u.is('', 4, 4); - expect(result).to.be.true; - }); + const result = u.is('', 4, 4) + expect(result).to.be.true + }) it('can use arrays as paths', () => { - const result = u.is(['a', 'b'], 4, { a: { b: 4 } }); - expect(result).to.be.true; - }); + const result = u.is(['a', 'b'], 4, { a: { b: 4 } }) + expect(result).to.be.true + }) it('can include array indexes in paths', () => { - let result = u.is('a.1.b', 4, { a: [{}, { b: 4 }] }); - expect(result).to.be.true; + let result = u.is('a.1.b', 4, { a: [{}, { b: 4 }] }) + expect(result).to.be.true - result = u.is(['a', 1, 'b'], 4, { a: [{}, { b: 4 }] }); - expect(result).to.be.true; - }); + result = u.is(['a', 1, 'b'], 4, { a: [{}, { b: 4 }] }) + expect(result).to.be.true + }) it('can be partially applied', () => { - const result = u.is('a.b')(4)({ a: { b: 4 } }); - expect(result).to.be.true; - }); -}); + const result = u.is('a.b')(4)({ a: { b: 4 } }) + expect(result).to.be.true + }) +}) diff --git a/test/map-spec.js b/test/map-spec.js index eafa004..d51d19b 100644 --- a/test/map-spec.js +++ b/test/map-spec.js @@ -1,72 +1,75 @@ -import { expect } from 'chai'; -import u from '../lib'; +import { expect } from 'chai' +import u from '../lib' describe('u.map', () => { it('applies updates to each item in an array', () => { - const object = [0, 1, 2]; - const inc = x => x + 1; - const result = u.map(inc, object); + const object = [0, 1, 2] + const inc = x => x + 1 + const result = u.map(inc, object) - expect(result).to.eql([1, 2, 3]); - }); + expect(result).to.eql([1, 2, 3]) + }) it('applies updates to each value in an object', () => { - const object = { a: 0, b: 1, c: 2 }; - const inc = x => x + 1; - const result = u.map(inc, object); + const object = { a: 0, b: 1, c: 2 } + const inc = x => x + 1 + const result = u.map(inc, object) - expect(result).to.eql({ a: 1, b: 2, c: 3 }); - }); + expect(result).to.eql({ a: 1, b: 2, c: 3 }) + }) it('can update with a regular updates object', () => { - const object = [{ a: 0 }, { a: 0 }]; - const result = u.map({ a: 1 }, object); + const object = [{ a: 0 }, { a: 0 }] + const result = u.map({ a: 1 }, object) - expect(result).to.eql([{ a: 1 }, { a: 1 }]); - }); + expect(result).to.eql([{ a: 1 }, { a: 1 }]) + }) it('returns the same object if no updates are made', () => { - const array = [0, 1]; - const ident = x => x; - let result = u.map(ident, array); + const array = [0, 1] + const ident = x => x + let result = u.map(ident, array) - expect(result).to.equal(array); + expect(result).to.equal(array) - const object = { a: 0 }; - result = u.map(ident, object); + const object = { a: 0 } + result = u.map(ident, object) - expect(result).to.equal(object); - }); + expect(result).to.equal(object) + }) it('passes the key or index as the second parameter to the iteratee', () => { const object = { a: { x: 0 }, b: [3, 3], - }; - const setToKey = (_, key) => key; - const result = u.map(u.map(setToKey), object); + } + const setToKey = (_, key) => key + const result = u.map(u.map(setToKey), object) expect(result).to.eql({ a: { x: 'x' }, b: [0, 1], - }); - }); + }) + }) it('can be partially applied', () => { const object = { b: [3, 3], - }; - const setToKey = (_, key) => key; - const result = u({ - b: u.map(setToKey), - }, object); + } + const setToKey = (_, key) => key + const result = u( + { + b: u.map(setToKey), + }, + object + ) expect(result).to.eql({ b: [0, 1], - }); - }); + }) + }) it('freezes the result', () => { - expect(Object.isFrozen(u.map({}, {}))).to.be.true; - }); -}); + expect(Object.isFrozen(u.map({}, {}))).to.be.true + }) +}) diff --git a/test/omit-spec.js b/test/omit-spec.js index 175c316..bb645a0 100644 --- a/test/omit-spec.js +++ b/test/omit-spec.js @@ -1,14 +1,14 @@ -import { expect } from 'chai'; -import u from '../lib'; +import { expect } from 'chai' +import u from '../lib' describe('u.omit', () => { it('can omit a key', () => { - const result = u({ foo: u.omit('bar') }, { foo: { bar: 7 } }); + const result = u({ foo: u.omit('bar') }, { foo: { bar: 7 } }) - expect(result).to.eql({ foo: {} }); - }); + expect(result).to.eql({ foo: {} }) + }) it('freezes the result', () => { - expect(Object.isFrozen(u.omit('a', {}))).to.be.true; - }); -}); + expect(Object.isFrozen(u.omit('a', {}))).to.be.true + }) +}) diff --git a/test/omitBy-spec.js b/test/omitBy-spec.js index abfb706..b3260ee 100644 --- a/test/omitBy-spec.js +++ b/test/omitBy-spec.js @@ -1,15 +1,18 @@ -import { expect } from 'chai'; -import u from '../lib'; +import { expect } from 'chai' +import u from '../lib' describe('u.omitBy', () => { it('can omitBy with a function', () => { - const predicate = (value, key) => (value === 7 && key === 'bar'); - const result = u({ foo: u.omitBy(predicate) }, { foo: { bar: 7, baz: 'a' } }); + const predicate = (value, key) => value === 7 && key === 'bar' + const result = u( + { foo: u.omitBy(predicate) }, + { foo: { bar: 7, baz: 'a' } } + ) - expect(result).to.eql({ foo: { baz: 'a' } }); - }); + expect(result).to.eql({ foo: { baz: 'a' } }) + }) it('freezes the result', () => { - expect(Object.isFrozen(u.omit('a', {}))).to.be.true; - }); -}); + expect(Object.isFrozen(u.omit('a', {}))).to.be.true + }) +}) diff --git a/test/reject-spec.js b/test/reject-spec.js index 80edade..cbea0ad 100644 --- a/test/reject-spec.js +++ b/test/reject-spec.js @@ -1,38 +1,44 @@ -import { expect } from 'chai'; -import u from '../lib'; +import { expect } from 'chai' +import u from '../lib' describe('u.reject', () => { it('can reject by index', () => { - const result = u.reject((_, index) => index === 1, [3, 4, 5]); + const result = u.reject((_, index) => index === 1, [3, 4, 5]) - expect(result).to.eql([3, 5]); - }); + expect(result).to.eql([3, 5]) + }) it('can reject with callback shorthand', () => { - const result = u.reject('bad', [{ bad: true }, { bad: false }]); + const result = u.reject('bad', [{ bad: true }, { bad: false }]) - expect(result).to.eql([{ bad: false }]); - }); + expect(result).to.eql([{ bad: false }]) + }) - it('returns the same instance if reject doesn\'t make changes', () => { - const object = { foo: [1, 2, 3] }; - const result = u({ - foo: u.reject(x => x === 'Justin Bieber'), - }, object); + it("returns the same instance if reject doesn't make changes", () => { + const object = { foo: [1, 2, 3] } + const result = u( + { + foo: u.reject(x => x === 'Justin Bieber'), + }, + object + ) - expect(result).to.equal(object); - }); + expect(result).to.equal(object) + }) it('returns a different instance if reject makes changes', () => { - const object = { foo: [1, 2, 3, 4] }; - const result = u({ - foo: u.reject(x => x === 4), - }, object); + const object = { foo: [1, 2, 3, 4] } + const result = u( + { + foo: u.reject(x => x === 4), + }, + object + ) - expect(result).to.not.equal(object); - }); + expect(result).to.not.equal(object) + }) it('freezes the result', () => { - expect(Object.isFrozen(u.reject('a', []))).to.be.true; - }); -}); + expect(Object.isFrozen(u.reject('a', []))).to.be.true + }) +}) diff --git a/test/updateIn-spec.js b/test/updateIn-spec.js index a89ca97..e2effb3 100644 --- a/test/updateIn-spec.js +++ b/test/updateIn-spec.js @@ -1,61 +1,61 @@ -import { expect } from 'chai'; -import u from '../lib'; +import { expect } from 'chai' +import u from '../lib' describe('u.updateIn', () => { it('can update a single path described with a string', () => { - const object = { a: { b: 0 } }; - const result = u.updateIn('a.b', 3, object); - expect(result).to.eql({ a: { b: 3 } }); - }); + const object = { a: { b: 0 } } + const result = u.updateIn('a.b', 3, object) + expect(result).to.eql({ a: { b: 3 } }) + }) it('can update a single path described with a string with a function', () => { - const inc = x => x + 1; - const object = { a: { b: 0 } }; - const result = u.updateIn('a.b', inc, object); - expect(result).to.eql({ a: { b: 1 } }); - }); + const inc = x => x + 1 + const object = { a: { b: 0 } } + const result = u.updateIn('a.b', inc, object) + expect(result).to.eql({ a: { b: 1 } }) + }) it('can update a single path described with an array', () => { - const object = { a: { b: 0 } }; - const result = u.updateIn(['a', 'b'], 3, object); - expect(result).to.eql({ a: { b: 3 } }); - }); + const object = { a: { b: 0 } } + const result = u.updateIn(['a', 'b'], 3, object) + expect(result).to.eql({ a: { b: 3 } }) + }) it('can update arrays', () => { - const object = { a: [0, 0, 0] }; - const result = u.updateIn('a.1', 3, object); - expect(result).to.eql({ a: [0, 3, 0] }); - }); + const object = { a: [0, 0, 0] } + const result = u.updateIn('a.1', 3, object) + expect(result).to.eql({ a: [0, 3, 0] }) + }) it('can be partially applied', () => { - const object = { a: { b: 0 } }; - const result = u.updateIn('a.b')(3)(object); - expect(result).to.eql({ a: { b: 3 } }); - }); + const object = { a: { b: 0 } } + const result = u.updateIn('a.b')(3)(object) + expect(result).to.eql({ a: { b: 3 } }) + }) it('replaces the object outright if the path is empty', () => { - const object = {}; - const result = u.updateIn('', 3, object); - expect(result).to.equal(3); - }); + const object = {} + const result = u.updateIn('', 3, object) + expect(result).to.equal(3) + }) it('freezes the result', () => { - expect(Object.isFrozen(u.updateIn('a', 0, {}))).to.be.true; - }); + expect(Object.isFrozen(u.updateIn('a', 0, {}))).to.be.true + }) it('can multiple elements of an array with *', () => { - let object = { a: [{ b: 0 }, { b: 1 }, { b: 2 }] }; - let result = u.updateIn('a.*.b', x => x + 1, object); - expect(result).to.eql({ a: [{ b: 1 }, { b: 2 }, { b: 3 }] }); + let object = { a: [{ b: 0 }, { b: 1 }, { b: 2 }] } + let result = u.updateIn('a.*.b', x => x + 1, object) + expect(result).to.eql({ a: [{ b: 1 }, { b: 2 }, { b: 3 }] }) - object = { a: [0, 1, 2] }; - result = u.updateIn(['a', '*'], x => x + 1, object); - expect(result).to.eql({ a: [1, 2, 3] }); - }); + object = { a: [0, 1, 2] } + result = u.updateIn(['a', '*'], x => x + 1, object) + expect(result).to.eql({ a: [1, 2, 3] }) + }) it('can update properties named *', () => { - const object = { '*': 1, x: 1 }; - const result = u.updateIn('*', x => x + 1, object); - expect(result).to.eql({ '*': 2, x: 1 }); - }); -}); + const object = { '*': 1, x: 1 } + const result = u.updateIn('*', x => x + 1, object) + expect(result).to.eql({ '*': 2, x: 1 }) + }) +}) diff --git a/test/updeep-spec.js b/test/updeep-spec.js index 3c01cc8..2bab9fb 100644 --- a/test/updeep-spec.js +++ b/test/updeep-spec.js @@ -1,143 +1,145 @@ -import { expect } from 'chai'; -import u from '../lib'; +import { expect } from 'chai' +import u from '../lib' describe('updeep', () => { it('does not change anything if no updates are specified', () => { - const object = { foo: 3, bar: [7, 5] }; - const result = u({}, object); + const object = { foo: 3, bar: [7, 5] } + const result = u({}, object) - expect(result).to.equal(object); - }); + expect(result).to.equal(object) + }) it('can update with fixed values', () => { - const object = { foo: 3, bar: [7, 5] }; - const result = u({ foo: 4 }, object); + const object = { foo: 3, bar: [7, 5] } + const result = u({ foo: 4 }, object) - expect(result).to.deep.equal({ foo: 4, bar: [7, 5] }); - }); + expect(result).to.deep.equal({ foo: 4, bar: [7, 5] }) + }) - it('returns the same instance if an update doesn\'t make changes', () => { - const object = { foo: 3 }; - const result = u({ foo: 3 }, object); + it("returns the same instance if an update doesn't make changes", () => { + const object = { foo: 3 } + const result = u({ foo: 3 }, object) - expect(result).to.equal(object); - }); + expect(result).to.equal(object) + }) it('can update a nested structure', () => { - const object = { foo: { bar: 7, bam: 3 }, baz: 32 }; - const result = u({ foo: { bar: 8 } }, object); + const object = { foo: { bar: 7, bam: 3 }, baz: 32 } + const result = u({ foo: { bar: 8 } }, object) - expect(result).to.deep.equal({ foo: { bar: 8, bam: 3 }, baz: 32 }); - }); + expect(result).to.deep.equal({ foo: { bar: 8, bam: 3 }, baz: 32 }) + }) it('can update arrays', () => { - const object = [1, 2, 3]; - const result = u({ 1: 7 }, object); + const object = [1, 2, 3] + const result = u({ 1: 7 }, object) - expect(result).to.deep.equal([1, 7, 3]); - }); + expect(result).to.deep.equal([1, 7, 3]) + }) it('replaces the object outright if updates are a constant', () => { - expect(u(3, {})).to.equal(3); - expect(u(null, {})).to.be.null; - }); + expect(u(3, {})).to.equal(3) + expect(u(null, {})).to.be.null + }) it('can add an element to an array', () => { - const object = []; - const result = u({ 0: 3 }, object); + const object = [] + const result = u({ 0: 3 }, object) - expect(result).to.eql([3]); - }); + expect(result).to.eql([3]) + }) it('can update nested arrays', () => { - const object = { foo: [1, 2, 3], bar: 9 }; - const result = u({ foo: { 1: 7 } }, object); + const object = { foo: [1, 2, 3], bar: 9 } + const result = u({ foo: { 1: 7 } }, object) - expect(result).to.deep.equal({ foo: [1, 7, 3], bar: 9 }); - }); + expect(result).to.deep.equal({ foo: [1, 7, 3], bar: 9 }) + }) it('can use functions to update values', () => { - const inc = i => i + 1; - const object = { foo: 3, bar: 4, baz: 7 }; - const result = u({ foo: inc, bar: inc }, object); + const inc = i => i + 1 + const object = { foo: 3, bar: 4, baz: 7 } + const result = u({ foo: inc, bar: inc }, object) - expect(result).to.deep.equal({ foo: 4, bar: 5, baz: 7 }); - }); + expect(result).to.deep.equal({ foo: 4, bar: 5, baz: 7 }) + }) it('can be partially applied', () => { - const inc = i => i + 1; - const object = { foo: 3 }; - const incFoo = u({ foo: inc }); + const inc = i => i + 1 + const object = { foo: 3 } + const incFoo = u({ foo: inc }) - const result = incFoo(object); + const result = incFoo(object) - expect(result).to.deep.equal({ foo: 4 }); - }); + expect(result).to.deep.equal({ foo: 4 }) + }) it('passes additional arguments on to updates if it is a function', () => { - const func = (_, x) => x; - const result = u(func, 0, 4); + const func = (_, x) => x + const result = u(func, 0, 4) - expect(result).to.equal(4); - }); + expect(result).to.equal(4) + }) it('can update if the value is an array', () => { - const object = {}; - const result = u({ foo: [0, 1] }, object); + const object = {} + const result = u({ foo: [0, 1] }, object) - expect(result).to.deep.equal({ foo: [0, 1] }); - }); + expect(result).to.deep.equal({ foo: [0, 1] }) + }) it('can update when original object is undefined', () => { - const result = u({ foo: [0, 1] }, undefined); + const result = u({ foo: [0, 1] }, undefined) - expect(result).to.deep.equal({ foo: [0, 1] }); - }); + expect(result).to.deep.equal({ foo: [0, 1] }) + }) it('can take a function as the updater', () => { - const result = u(i => i + 1, 7); + const result = u(i => i + 1, 7) - expect(result).to.eql(8); - }); + expect(result).to.eql(8) + }) it('deeply freezes the result', () => { - const result = u({ foo: { bar: 3 } }, { foo: { bar: 0 } }); + const result = u({ foo: { bar: 3 } }, { foo: { bar: 0 } }) - expect(Object.isFrozen(result)).to.be.true; - expect(Object.isFrozen(result.foo)).to.be.true; - }); + expect(Object.isFrozen(result)).to.be.true + expect(Object.isFrozen(result.foo)).to.be.true + }) it('assigns null values', () => { - expect(u({ isNull: null }, {})).to.eql({ isNull: null }); - }); + expect(u({ isNull: null }, {})).to.eql({ isNull: null }) + }) it('can use a placeholder to partially apply', () => { - function increment(i) { return i + 1; } - const updateJoe = u(u._, { name: 'Joe Merrill', age: 21 }); - const result = updateJoe({ age: increment }); + function increment(i) { + return i + 1 + } + const updateJoe = u(u._, { name: 'Joe Merrill', age: 21 }) + const result = updateJoe({ age: increment }) - expect(result).to.eql({ name: 'Joe Merrill', age: 22 }); - }); + expect(result).to.eql({ name: 'Joe Merrill', age: 22 }) + }) it('defaults to an empty object when null or undefined', () => { - let result = u({ a: { b: 0 } }, { a: null }); - expect(result).to.eql({ a: { b: 0 } }); + let result = u({ a: { b: 0 } }, { a: null }) + expect(result).to.eql({ a: { b: 0 } }) - result = u({ a: { b: 0 } }, { a: undefined }); - expect(result).to.eql({ a: { b: 0 } }); + result = u({ a: { b: 0 } }, { a: undefined }) + expect(result).to.eql({ a: { b: 0 } }) - result = u({ a: { b: 0 } }, { }); - expect(result).to.eql({ a: { b: 0 } }); - }); + result = u({ a: { b: 0 } }, {}) + expect(result).to.eql({ a: { b: 0 } }) + }) it('preserves empty objects when empty updates are specified', () => { - const result = u({ a: {} }, {}); - expect(result).to.eql({ a: {} }); - }); + const result = u({ a: {} }, {}) + expect(result).to.eql({ a: {} }) + }) it('works with date objects', () => { - const date = new Date(); - const result = u({ created: date }, {}); - expect(result).to.eql({ created: date }); - }); -}); + const date = new Date() + const result = u({ created: date }, {}) + expect(result).to.eql({ created: date }) + }) +}) diff --git a/test/util/curry-spec.js b/test/util/curry-spec.js index e24ebb2..8140625 100644 --- a/test/util/curry-spec.js +++ b/test/util/curry-spec.js @@ -1,110 +1,110 @@ -import { expect } from 'chai'; -import { curry1, curry2, curry3, curry4, _ } from '../../lib/util/curry'; +import { expect } from 'chai' +import { curry1, curry2, curry3, curry4, _ } from '../../lib/util/curry' describe('curry1', () => { it('can curry one arguments', () => { - const addOne = curry1(x => x + 1); - expect(addOne(3)).to.equal(4); - expect(addOne()(3)).to.equal(4); - }); + const addOne = curry1(x => x + 1) + expect(addOne(3)).to.equal(4) + expect(addOne()(3)).to.equal(4) + }) it('will take up to two extra arguments', () => { - const curried = curry1((a, b, c) => [a, b, c]); - expect(curried(1, 2, 3, 4)).to.eql([1, 2, 3]); - }); + const curried = curry1((a, b, c) => [a, b, c]) + expect(curried(1, 2, 3, 4)).to.eql([1, 2, 3]) + }) it('returns a fn with arity of 1', () => { - const curried = curry1((a, b, c) => [a, b, c]); - expect(curried).to.have.length(1); - }); -}); + const curried = curry1((a, b, c) => [a, b, c]) + expect(curried).to.have.length(1) + }) +}) describe('curry2', () => { it('can curry two arguments', () => { - const add = curry2((x, y) => x + y); - expect(add(3)(4)).to.equal(7); - expect(add()(3)()(4)).to.equal(7); - expect(add(3, 4)).to.equal(7); - }); + const add = curry2((x, y) => x + y) + expect(add(3)(4)).to.equal(7) + expect(add()(3)()(4)).to.equal(7) + expect(add(3, 4)).to.equal(7) + }) it('will take up to two extra arguments', () => { - const curried = curry2((a, b, c, d) => [a, b, c, d]); - expect(curried(1, 2, 3, 4, 5)).to.eql([1, 2, 3, 4]); - }); + const curried = curry2((a, b, c, d) => [a, b, c, d]) + expect(curried(1, 2, 3, 4, 5)).to.eql([1, 2, 3, 4]) + }) it('can use the placeholder', () => { - const curried = curry2((a, b, c, d) => [a, b, c, d]); - expect(curried(_, 2)(1, 3, 4)).to.eql([1, 2, 3, 4]); - }); + const curried = curry2((a, b, c, d) => [a, b, c, d]) + expect(curried(_, 2)(1, 3, 4)).to.eql([1, 2, 3, 4]) + }) it('returns a fn with arity of 2', () => { - const curried = curry2((a, b, c, d) => [a, b, c, d]); - expect(curried).to.have.length(2); - }); -}); + const curried = curry2((a, b, c, d) => [a, b, c, d]) + expect(curried).to.have.length(2) + }) +}) describe('curry3', () => { it('can curry three arguments', () => { - const add = curry3((x, y, z) => x + y + z); - expect(add(3, _)(4)(5)).to.equal(12); - expect(add()(3)()(4, 5)).to.equal(12); - expect(add(3, 4, 5)).to.equal(12); - }); + const add = curry3((x, y, z) => x + y + z) + expect(add(3, _)(4)(5)).to.equal(12) + expect(add()(3)()(4, 5)).to.equal(12) + expect(add(3, 4, 5)).to.equal(12) + }) it('will take up to two extra arguments', () => { - const curried = curry3((a, b, c, d, e) => [a, b, c, d, e]); - expect(curried(1, 2, 3, 4, 5, 6)).to.eql([1, 2, 3, 4, 5]); - }); + const curried = curry3((a, b, c, d, e) => [a, b, c, d, e]) + expect(curried(1, 2, 3, 4, 5, 6)).to.eql([1, 2, 3, 4, 5]) + }) it('can use the placeholder', () => { - const curried = curry3((a, b, c, d, e) => [a, b, c, d, e]); - expect(curried(_, 2)('a', 3, 4, 5)).to.eql(['a', 2, 3, 4, 5]); - expect(curried('b', _, 3)(2, 4, 5)).to.eql(['b', 2, 3, 4, 5]); - expect(curried(_, 2, 3)('c', 4, 5)).to.eql(['c', 2, 3, 4, 5]); - expect(curried(_, _, 3)('d', 2, 4, 5)).to.eql(['d', 2, 3, 4, 5]); - }); + const curried = curry3((a, b, c, d, e) => [a, b, c, d, e]) + expect(curried(_, 2)('a', 3, 4, 5)).to.eql(['a', 2, 3, 4, 5]) + expect(curried('b', _, 3)(2, 4, 5)).to.eql(['b', 2, 3, 4, 5]) + expect(curried(_, 2, 3)('c', 4, 5)).to.eql(['c', 2, 3, 4, 5]) + expect(curried(_, _, 3)('d', 2, 4, 5)).to.eql(['d', 2, 3, 4, 5]) + }) it('returns a fn with arity of 3', () => { - const curried = curry3((a, b, c, d, e) => [a, b, c, d, e]); - expect(curried).to.have.length(3); - }); -}); + const curried = curry3((a, b, c, d, e) => [a, b, c, d, e]) + expect(curried).to.have.length(3) + }) +}) describe('curry4', () => { it('can curry four arguments', () => { - const add = curry4((x, y, z, u) => x + y + z + u); - expect(add(3, _)(4)(5)(6)).to.equal(18); - expect(add()(3)()(4, 5, 6)).to.equal(18); - expect(add(3, 4, 5, 6)).to.equal(18); - }); + const add = curry4((x, y, z, u) => x + y + z + u) + expect(add(3, _)(4)(5)(6)).to.equal(18) + expect(add()(3)()(4, 5, 6)).to.equal(18) + expect(add(3, 4, 5, 6)).to.equal(18) + }) it('will take up to two extra arguments', () => { - const curried = curry4((a, b, c, d, e, f) => [a, b, c, d, e, f]); - expect(curried(1, 2, 3, 4, 5, 6, 7)).to.eql([1, 2, 3, 4, 5, 6]); - }); + const curried = curry4((a, b, c, d, e, f) => [a, b, c, d, e, f]) + expect(curried(1, 2, 3, 4, 5, 6, 7)).to.eql([1, 2, 3, 4, 5, 6]) + }) it('can use the placeholder', () => { - const curried = curry4((a, b, c, d, e, f) => [a, b, c, d, e, f]); - expect(curried(_, 2)('a', 3, 4, 5, 6)).to.eql(['a', 2, 3, 4, 5, 6]); - expect(curried(_, 2, 3)('b', 4, 5, 6)).to.eql(['b', 2, 3, 4, 5, 6]); - expect(curried(_, 2, 3, 4)('c', 5, 6)).to.eql(['c', 2, 3, 4, 5, 6]); + const curried = curry4((a, b, c, d, e, f) => [a, b, c, d, e, f]) + expect(curried(_, 2)('a', 3, 4, 5, 6)).to.eql(['a', 2, 3, 4, 5, 6]) + expect(curried(_, 2, 3)('b', 4, 5, 6)).to.eql(['b', 2, 3, 4, 5, 6]) + expect(curried(_, 2, 3, 4)('c', 5, 6)).to.eql(['c', 2, 3, 4, 5, 6]) - expect(curried('d', _, 3)(2, 4, 5, 6)).to.eql(['d', 2, 3, 4, 5, 6]); - expect(curried('e', _, 3, 4)(2, 5, 6)).to.eql(['e', 2, 3, 4, 5, 6]); + expect(curried('d', _, 3)(2, 4, 5, 6)).to.eql(['d', 2, 3, 4, 5, 6]) + expect(curried('e', _, 3, 4)(2, 5, 6)).to.eql(['e', 2, 3, 4, 5, 6]) - expect(curried('f', 2, _, 4)(3, 5, 6)).to.eql(['f', 2, 3, 4, 5, 6]); + expect(curried('f', 2, _, 4)(3, 5, 6)).to.eql(['f', 2, 3, 4, 5, 6]) - expect(curried(_, _, 3)('g', 2, 4, 5, 6)).to.eql(['g', 2, 3, 4, 5, 6]); - expect(curried(_, _, 3, 4)('h', 2, 5, 6)).to.eql(['h', 2, 3, 4, 5, 6]); - expect(curried(_, 2, _, 4)('i', 3, 5, 6)).to.eql(['i', 2, 3, 4, 5, 6]); + expect(curried(_, _, 3)('g', 2, 4, 5, 6)).to.eql(['g', 2, 3, 4, 5, 6]) + expect(curried(_, _, 3, 4)('h', 2, 5, 6)).to.eql(['h', 2, 3, 4, 5, 6]) + expect(curried(_, 2, _, 4)('i', 3, 5, 6)).to.eql(['i', 2, 3, 4, 5, 6]) - expect(curried('j', _, _, 4)(2, 3, 5, 6)).to.eql(['j', 2, 3, 4, 5, 6]); + expect(curried('j', _, _, 4)(2, 3, 5, 6)).to.eql(['j', 2, 3, 4, 5, 6]) - expect(curried(_, _, _, 4)('k', 2, 3, 5, 6)).to.eql(['k', 2, 3, 4, 5, 6]); - }); + expect(curried(_, _, _, 4)('k', 2, 3, 5, 6)).to.eql(['k', 2, 3, 4, 5, 6]) + }) it('returns a fn with arity of 4', () => { - const curried = curry4((a, b, c, d, e, f) => [a, b, c, d, e, f]); - expect(curried).to.have.length(4); - }); -}); + const curried = curry4((a, b, c, d, e, f) => [a, b, c, d, e, f]) + expect(curried).to.have.length(4) + }) +}) diff --git a/test/util/splitPath-spec.js b/test/util/splitPath-spec.js index ac95e22..b0d5bd5 100644 --- a/test/util/splitPath-spec.js +++ b/test/util/splitPath-spec.js @@ -1,22 +1,22 @@ -import { expect } from 'chai'; -import splitPath from '../../lib/util/splitPath'; +import { expect } from 'chai' +import splitPath from '../../lib/util/splitPath' describe('splitPath', () => { it('treats a number as a single step path', () => { - const path = 1; - const result = splitPath(path); - expect(result).to.deep.equal(['1']); - }); + const path = 1 + const result = splitPath(path) + expect(result).to.deep.equal(['1']) + }) it('handles arrays', () => { - const path = ['foo', 'bar', 'x']; - const result = splitPath(path); - expect(result).to.equal(path); - }); + const path = ['foo', 'bar', 'x'] + const result = splitPath(path) + expect(result).to.equal(path) + }) it('handles strings separated by dots', () => { - const path = 'bar.0.y'; - const result = splitPath(path); - expect(result).to.deep.equal(['bar', '0', 'y']); - }); -}); + const path = 'bar.0.y' + const result = splitPath(path) + expect(result).to.deep.equal(['bar', '0', 'y']) + }) +}) diff --git a/test/withDefault-spec.js b/test/withDefault-spec.js index 8b8ec25..b8b0651 100644 --- a/test/withDefault-spec.js +++ b/test/withDefault-spec.js @@ -1,31 +1,34 @@ -import { expect } from 'chai'; -import u from '../lib'; +import { expect } from 'chai' +import u from '../lib' describe('u.withDefault', () => { it('uses the default as the basis for the update if the object is undefined', () => { - const inc = x => x + 1; - const result = u.withDefault({ a: 0 }, { a: inc }, undefined); + const inc = x => x + 1 + const result = u.withDefault({ a: 0 }, { a: inc }, undefined) - expect(result).to.eql({ a: 1 }); - }); + expect(result).to.eql({ a: 1 }) + }) it('uses ignores the default if the object is defined', () => { - const inc = x => x + 1; - const result = u.withDefault({ a: 0 }, { a: inc }, { a: 3 }); + const inc = x => x + 1 + const result = u.withDefault({ a: 0 }, { a: inc }, { a: 3 }) - expect(result).to.eql({ a: 4 }); - }); + expect(result).to.eql({ a: 4 }) + }) it('can be partially applied', () => { - const object = {}; - const result = u({ - foo: u.withDefault([], { 0: 'bar' }), - }, object); + const object = {} + const result = u( + { + foo: u.withDefault([], { 0: 'bar' }), + }, + object + ) - expect(result).to.eql({ foo: ['bar'] }); - }); + expect(result).to.eql({ foo: ['bar'] }) + }) it('freezes the result', () => { - expect(Object.isFrozen(u.withDefault({}, { a: 1 })(undefined))).to.be.true; - }); -}); + expect(Object.isFrozen(u.withDefault({}, { a: 1 })(undefined))).to.be.true + }) +}) diff --git a/webpack.config.js b/webpack.config.js index 658bcfe..9c0e44f 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,5 +1,5 @@ -'use strict'; +'use strict' - /* eslint strict:0, no-var:0, func-names:0 */ +/* eslint strict:0, no-var:0, func-names:0 */ -module.exports = require('./createWebpackConfig')(); +module.exports = require('./createWebpackConfig')() diff --git a/yarn.lock b/yarn.lock index 344da91..68ac41e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -73,6 +73,12 @@ ansi-styles@^2.1.0, ansi-styles@^2.2.1: version "2.2.1" resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-2.2.1.tgz#b432dd3358b634cf75e1e4664368240533c1ddbe" +ansi-styles@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-3.0.0.tgz#5404e93a544c4fec7f048262977bebfe3155e0c1" + dependencies: + color-convert "^1.0.0" + anymatch@^1.3.0: version "1.3.0" resolved "https://registry.yarnpkg.com/anymatch/-/anymatch-1.3.0.tgz#a3e52fa39168c825ff57b0248126ce5a8ff95507" @@ -167,6 +173,10 @@ assertion-error@^1.0.1: version "1.0.2" resolved "https://registry.yarnpkg.com/assertion-error/-/assertion-error-1.0.2.tgz#13ca515d86206da0bac66e834dd397d87581094c" +ast-types@0.9.8: + version "0.9.8" + resolved "https://registry.yarnpkg.com/ast-types/-/ast-types-0.9.8.tgz#6cb6a40beba31f49f20928e28439fc14a3dab078" + async-each@^1.0.0: version "1.0.1" resolved "https://registry.yarnpkg.com/async-each/-/async-each-1.0.1.tgz#19d386a1d9edc6e7c1c85d388aedbcc56d33602d" @@ -195,7 +205,7 @@ aws4@^1.2.1: version "1.6.0" resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.6.0.tgz#83ef5ca860b2b32e4a0deedee8c771b9db57471e" -babel-code-frame@^6.16.0, babel-code-frame@^6.22.0: +babel-code-frame@6.22.0, babel-code-frame@^6.16.0, babel-code-frame@^6.22.0: version "6.22.0" resolved "https://registry.yarnpkg.com/babel-code-frame/-/babel-code-frame-6.22.0.tgz#027620bee567a88c32561574e7fd0801d33118e4" dependencies: @@ -742,6 +752,10 @@ babel-types@^6.19.0, babel-types@^6.24.1: lodash "^4.2.0" to-fast-properties "^1.0.1" +babylon@7.0.0-beta.8: + version "7.0.0-beta.8" + resolved "https://registry.yarnpkg.com/babylon/-/babylon-7.0.0-beta.8.tgz#2bdc5ae366041442c27e068cce6f0d7c06ea9949" + babylon@^6.11.0, babylon@^6.15.0: version "6.16.1" resolved "https://registry.yarnpkg.com/babylon/-/babylon-6.16.1.tgz#30c5a22f481978a9e7f8cdfdf496b11d94b404d3" @@ -951,7 +965,7 @@ chalk@1.1.1: strip-ansi "^3.0.0" supports-color "^2.0.0" -chalk@^1.0.0, chalk@^1.1.0, chalk@^1.1.1, chalk@^1.1.3: +chalk@1.1.3, chalk@^1.0.0, chalk@^1.1.0, chalk@^1.1.1, chalk@^1.1.3: version "1.1.3" resolved "https://registry.yarnpkg.com/chalk/-/chalk-1.1.3.tgz#a8115c55e4a702fe4d150abd3872822a7e09fc98" dependencies: @@ -1028,6 +1042,16 @@ code-point-at@^1.0.0: version "1.1.0" resolved "https://registry.yarnpkg.com/code-point-at/-/code-point-at-1.1.0.tgz#0d070b4d043a5bea33a2f1a40e2edb3d9a4ccf77" +color-convert@^1.0.0: + version "1.9.0" + resolved "https://registry.yarnpkg.com/color-convert/-/color-convert-1.9.0.tgz#1accf97dd739b983bf994d56fec8f95853641b7a" + dependencies: + color-name "^1.1.1" + +color-name@^1.1.1: + version "1.1.2" + resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.2.tgz#5c8ab72b64bd2215d617ae9559ebb148475cf98d" + colors@1.0.3: version "1.0.3" resolved "https://registry.yarnpkg.com/colors/-/colors-1.0.3.tgz#0433f44d809680fdeb60ed260f1b0c262e82a40b" @@ -1514,6 +1538,12 @@ eslint-config-airbnb-base@^11.1.3: version "11.1.3" resolved "https://registry.yarnpkg.com/eslint-config-airbnb-base/-/eslint-config-airbnb-base-11.1.3.tgz#0e8db71514fa36b977fbcf977c01edcf863e0cf0" +eslint-config-prettier@^1.6.0: + version "1.6.0" + resolved "https://registry.yarnpkg.com/eslint-config-prettier/-/eslint-config-prettier-1.6.0.tgz#56e53a8eb461c06eced20cec40d765c185100fd5" + dependencies: + get-stdin "^5.0.1" + eslint-import-resolver-node@^0.2.0: version "0.2.3" resolved "https://registry.yarnpkg.com/eslint-import-resolver-node/-/eslint-import-resolver-node-0.2.3.tgz#5add8106e8c928db2cba232bcd9efa846e3da16c" @@ -1544,6 +1574,12 @@ eslint-plugin-import@^2.2.0: minimatch "^3.0.3" pkg-up "^1.0.0" +eslint-plugin-prettier@^2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/eslint-plugin-prettier/-/eslint-plugin-prettier-2.0.1.tgz#2ae1216cf053dd728360ca8560bf1aabc8af3fa9" + dependencies: + requireindex "~1.1.0" + eslint@^3.0.0, eslint@^3.19.0: version "3.19.0" resolved "https://registry.yarnpkg.com/eslint/-/eslint-3.19.0.tgz#c8fc6201c7f40dd08941b87c085767386a679acc" @@ -1616,7 +1652,7 @@ estraverse@~4.1.0: version "4.1.1" resolved "https://registry.yarnpkg.com/estraverse/-/estraverse-4.1.1.tgz#f6caca728933a850ef90661d0e17982ba47111a2" -esutils@^2.0.2: +esutils@2.0.2, esutils@^2.0.2: version "2.0.2" resolved "https://registry.yarnpkg.com/esutils/-/esutils-2.0.2.tgz#0abf4f1caa5bcb1f7a9d8acc6dea4faaa04bac9b" @@ -1871,6 +1907,10 @@ flat-cache@^1.2.1: graceful-fs "^4.1.2" write "^0.2.1" +flow-parser@0.43.0: + version "0.43.0" + resolved "https://registry.yarnpkg.com/flow-parser/-/flow-parser-0.43.0.tgz#e2b8eb1ac83dd53f7b6b04a7c35b6a52c33479b7" + for-in@^1.0.1: version "1.0.2" resolved "https://registry.yarnpkg.com/for-in/-/for-in-1.0.2.tgz#81068d295a8142ec0ac726c6e2200c30fb6d5e80" @@ -1980,6 +2020,10 @@ generate-object-property@^1.1.0: dependencies: is-property "^1.0.0" +get-stdin@5.0.1, get-stdin@^5.0.1: + version "5.0.1" + resolved "https://registry.yarnpkg.com/get-stdin/-/get-stdin-5.0.1.tgz#122e161591e21ff4c52530305693f20e6393a398" + getpass@^0.1.1: version "0.1.6" resolved "https://registry.yarnpkg.com/getpass/-/getpass-0.1.6.tgz#283ffd9fc1256840875311c1b60e8c40187110e6" @@ -2029,16 +2073,7 @@ glob@3.2.11: inherits "2" minimatch "0.3" -glob@^4.3.1: - version "4.5.3" - resolved "https://registry.yarnpkg.com/glob/-/glob-4.5.3.tgz#c6cb73d3226c1efef04de3c56d012f03377ee15f" - dependencies: - inflight "^1.0.4" - inherits "2" - minimatch "^2.0.1" - once "^1.3.0" - -glob@^7.0.0, glob@^7.0.3, glob@^7.0.5: +glob@7.1.1, glob@^7.0.0, glob@^7.0.3, glob@^7.0.5: version "7.1.1" resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.1.tgz#805211df04faaf1c63a3600306cdf5ade50b2ec8" dependencies: @@ -2049,6 +2084,15 @@ glob@^7.0.0, glob@^7.0.3, glob@^7.0.5: once "^1.3.0" path-is-absolute "^1.0.0" +glob@^4.3.1: + version "4.5.3" + resolved "https://registry.yarnpkg.com/glob/-/glob-4.5.3.tgz#c6cb73d3226c1efef04de3c56d012f03377ee15f" + dependencies: + inflight "^1.0.4" + inherits "2" + minimatch "^2.0.1" + once "^1.3.0" + glob@~3.1.21: version "3.1.21" resolved "https://registry.yarnpkg.com/glob/-/glob-3.1.21.tgz#d29e0a055dea5138f4d07ed40e8982e83c2066cd" @@ -2618,6 +2662,22 @@ jade@0.26.3: commander "0.6.1" mkdirp "0.3.0" +jest-matcher-utils@^19.0.0: + version "19.0.0" + resolved "https://registry.yarnpkg.com/jest-matcher-utils/-/jest-matcher-utils-19.0.0.tgz#5ecd9b63565d2b001f61fbf7ec4c7f537964564d" + dependencies: + chalk "^1.1.3" + pretty-format "^19.0.0" + +jest-validate@19.0.0: + version "19.0.0" + resolved "https://registry.yarnpkg.com/jest-validate/-/jest-validate-19.0.0.tgz#8c6318a20ecfeaba0ba5378bfbb8277abded4173" + dependencies: + chalk "^1.1.1" + jest-matcher-utils "^19.0.0" + leven "^2.0.0" + pretty-format "^19.0.0" + jodid25519@^1.0.0: version "1.0.2" resolved "https://registry.yarnpkg.com/jodid25519/-/jodid25519-1.0.2.tgz#06d4912255093419477d425633606e0e90782967" @@ -2790,6 +2850,10 @@ lazy-cache@^1.0.3: version "1.0.4" resolved "https://registry.yarnpkg.com/lazy-cache/-/lazy-cache-1.0.4.tgz#a1d78fc3a50474cb80845d3b3b6e1da49a446e8e" +leven@^2.0.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/leven/-/leven-2.1.0.tgz#c2e7a9f772094dee9d34202ae8acce4687875580" + levn@^0.3.0, levn@~0.3.0: version "0.3.0" resolved "https://registry.yarnpkg.com/levn/-/levn-0.3.0.tgz#3b09924edf9f083c0490fdd4c0bc4421e04764ee" @@ -3110,7 +3174,7 @@ minimist@0.0.8, minimist@~0.0.1: version "0.0.8" resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.8.tgz#857fcabfc3397d2625b8228262e86aa7a011b05d" -minimist@^1.1.0, minimist@^1.2.0: +minimist@1.2.0, minimist@^1.1.0, minimist@^1.2.0: version "1.2.0" resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.0.tgz#a35008b20f41383eec1fb914f4cd5df79a264284" @@ -3544,6 +3608,27 @@ preserve@^0.2.0: version "0.2.0" resolved "https://registry.yarnpkg.com/preserve/-/preserve-0.2.0.tgz#815ed1f6ebc65926f865b310c0713bcb3315ce4b" +prettier@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.1.0.tgz#9d6ad005703efefa66b6999b8916bfc6afeaf9f8" + dependencies: + ast-types "0.9.8" + babel-code-frame "6.22.0" + babylon "7.0.0-beta.8" + chalk "1.1.3" + esutils "2.0.2" + flow-parser "0.43.0" + get-stdin "5.0.1" + glob "7.1.1" + jest-validate "19.0.0" + minimist "1.2.0" + +pretty-format@^19.0.0: + version "19.0.0" + resolved "https://registry.yarnpkg.com/pretty-format/-/pretty-format-19.0.0.tgz#56530d32acb98a3fa4851c4e2b9d37b420684c84" + dependencies: + ansi-styles "^3.0.0" + pretty-hrtime@^1.0.0: version "1.0.3" resolved "https://registry.yarnpkg.com/pretty-hrtime/-/pretty-hrtime-1.0.3.tgz#b7e3ea42435a4c9b2759d99e0f201eb195802ee1" @@ -3827,6 +3912,10 @@ require-uncached@^1.0.2: caller-path "^0.1.0" resolve-from "^1.0.0" +requireindex@~1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/requireindex/-/requireindex-1.1.0.tgz#e5404b81557ef75db6e49c5a72004893fe03e162" + requires-port@1.0.x, requires-port@1.x.x: version "1.0.0" resolved "https://registry.yarnpkg.com/requires-port/-/requires-port-1.0.0.tgz#925d2601d39ac485e091cf0da5c6e694dc3dcaff"