Merge pull request #280 from substantial/replace-gulp

Replace Gulp and travisci
This commit is contained in:
Shaun Dern 2020-04-03 18:41:04 +01:00 committed by GitHub
commit ad1a73326e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
40 changed files with 4272 additions and 5730 deletions

View File

@ -1,3 +0,0 @@
{
"presets": ["es2015", "stage-2"]
}

32
.circleci/config.yml Normal file
View File

@ -0,0 +1,32 @@
version: 2.1
orbs:
node: circleci/node@1.1.6
yarn: substantial/yarn@3.10.2
node-build: substantial/node-build@2.3.0
jobs:
build:
executor:
name: node/default
tag: '12.14.1'
steps:
- checkout
- yarn/install:
cache-version: v2
yarn-audit: false
- node-build/eslint
- run:
name: Test
command: |
yarn test
- run:
name: dtslint
command: |
yarn dtslint
- run:
name: build
command: |
yarn build
- node-build/store-results
- node-build/release

View File

@ -1,31 +0,0 @@
{
"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",
"objects": "always-multiline",
"imports": "always-multiline",
"exports": "always-multiline",
"functions": "never"
}]
}
}

81
.eslintrc.js Normal file
View File

@ -0,0 +1,81 @@
const config = {
parserOptions: {
ecmaVersion: 2018,
},
env: {
node: true,
},
"extends": [
"eslint:recommended",
"prettier"
],
"plugins": [
"prettier"
],
"rules": {
"no-confusing-arrow": "off",
"comma-dangle": ["error", {
"arrays": "always-multiline",
"objects": "always-multiline",
"imports": "always-multiline",
"exports": "always-multiline",
"functions": "never"
}]
},
overrides: [
{
files: ['lib/**/*'],
env: {
es6: true,
},
parserOptions: {
sourceType: 'module',
},
},
{
files: ['test/**/*'] ,
env: {
mocha: true
},
parserOptions: {
sourceType: 'module',
},
rules: {
"no-unused-expressions": 'off'
}
},
{
files: ['**/*.@(ts|tsx)'],
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
parserOptions: {
sourceType: 'module',
},
rules: {
'@typescript-eslint/class-name-casing': 'error',
'@typescript-eslint/consistent-type-assertions': 'error',
'@typescript-eslint/no-empty-interface': 'error',
'@typescript-eslint/no-non-null-assertion': 'error',
'@typescript-eslint/type-annotation-spacing': 'error',
'@typescript-eslint/no-unused-vars': [
'error',
{
argsIgnorePattern: '^_',
ignoreRestSiblings: true,
},
],
},
},
{
files: ['**/*.d.ts'],
rules: {
'@typescript-eslint/no-useless-constructor': 'error',
'no-var': 'off',
'no-useless-constructor': 'off',
strict: 'off',
},
},
]
}
module.exports = config

4
.prettierignore Normal file
View File

@ -0,0 +1,4 @@
package.json
node_modules
dist
coverage

View File

@ -1,9 +0,0 @@
sudo: false
language: node_js
node_js:
- '8'
- '10'
notifications:
email:
on_success: change
on_failure: always

View File

@ -7,7 +7,7 @@
[![Join the chat at https://gitter.im/substantial/updeep](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/substantial/updeep?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![Join the chat at https://gitter.im/substantial/updeep](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/substantial/updeep?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![NPM version][npm-image]][npm-url] [![NPM version][npm-image]][npm-url]
[![Build Status][travis-image]][travis-url] [![Build Status][circleci-image]][circleci-url]
[![Code Climate][codeclimate-image]][codeclimate-url] [![Code Climate][codeclimate-image]][codeclimate-url]
[![Dependency Status][daviddm-image]][daviddm-url] [![Dependency Status][daviddm-image]][daviddm-url]
@ -533,10 +533,10 @@ case.
```bash ```bash
$ npm login $ npm login
``` ```
1. Make sure the build passes (best to let it pass on travis, but you can run it locally): 1. Make sure the build passes (best to let it pass on circleci, but you can run it locally):
```bash ```bash
$ gulp $ npm build
``` ```
1. Bump the version: 1. Bump the version:
@ -572,8 +572,8 @@ MIT ©2015 [Substantial](http://substantial.com)
[docset]: https://github.com/yanick/dash-docset-updeep [docset]: https://github.com/yanick/dash-docset-updeep
[npm-image]: https://badge.fury.io/js/updeep.svg [npm-image]: https://badge.fury.io/js/updeep.svg
[npm-url]: https://npmjs.org/package/updeep [npm-url]: https://npmjs.org/package/updeep
[travis-image]: https://travis-ci.org/substantial/updeep.svg?branch=master [circleci-image]: https://circleci.com/gh/substantial/updeep.svg?style=shield
[travis-url]: https://travis-ci.org/substantial/updeep [circleci-url]: https://circleci.com/gh/substantial/updeep
[daviddm-image]: https://david-dm.org/substantial/updeep.svg?theme=shields.io [daviddm-image]: https://david-dm.org/substantial/updeep.svg?theme=shields.io
[daviddm-url]: https://david-dm.org/substantial/updeep [daviddm-url]: https://david-dm.org/substantial/updeep
[daviddm-peer-image]: https://david-dm.org/substantial/updeep/peer-status.svg [daviddm-peer-image]: https://david-dm.org/substantial/updeep/peer-status.svg

17
babel.config.js Normal file
View File

@ -0,0 +1,17 @@
module.exports = (api) => {
api.cache(true)
return {
presets: [
[
'@babel/preset-env',
{
loose: true,
targets: {
browsers: ['last 2 versions', 'IE >= 9'],
},
},
],
'@babel/preset-typescript',
],
}
}

View File

@ -1,61 +0,0 @@
"use strict"; // eslint-disable-line
/* eslint no-var:0, func-names:0, import/no-extraneous-dependencies:0 */
var webpack = require('webpack')
module.exports = function createWebpackConfig(_options) {
var config
var options = _options || {}
var env = options.env || 'development'
config = {
context: options.context,
entry: options.entry,
plugins: [
new webpack.optimize.OccurrenceOrderPlugin(),
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify(env),
},
}),
],
node: {
process: false,
},
module: {
loaders: [
{ test: /\.js$/, loaders: ['babel-loader'], exclude: /node_modules/ },
],
},
output: {
library: 'updeep',
libraryTarget: 'umd',
},
resolve: {
extensions: ['', '.js'],
},
}
config.output.filename = options.filename
if (options.minify) {
config.plugins.push(
new webpack.optimize.UglifyJsPlugin({
compressor: {
pure_getters: true,
unsafe: true,
unsafe_comps: true,
screw_ie8: true,
warnings: false,
},
})
)
}
return config
}

View File

@ -1,95 +0,0 @@
'use strict'
/* 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 rimraf = require('rimraf')
var webpack = require('webpack-stream')
var KarmaServer = require('karma').Server
var createWebpackConfig = require('./createWebpackConfig.js')
// Initialize the babel transpiler so ES2015 files gets compiled
// when they're loaded
require('babel-core/register')
gulp.task('clean', cb => {
rimraf('./dist', cb)
})
gulp.task('static', () =>
gulp
.src(['*.js', 'lib/**/*.js', 'test/**/*.js'])
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError())
)
gulp.task('test', ['test:karma', 'test:node'])
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('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'])
new KarmaServer({
configFile: path.join(__dirname, 'karma.conf.js'),
}).start()
})
gulp.task('webpack', ['webpack:standalone', 'webpack:standalone:min'])
gulp.task('webpack:standalone', () => {
var config = createWebpackConfig({ filename: 'updeep-standalone.js' })
return gulp
.src('lib/index.js')
.pipe(webpack(config))
.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')
.pipe(webpack(config))
.pipe(gulp.dest('dist/umd/'))
})
gulp.task('build', ['babel', 'webpack'])
gulp.task('build:clean', ['clean'], done => {
gulp.start('build', done)
})
gulp.task('prepublish', ['build:clean'])
gulp.task('default', ['static', 'test'])

7
husky.config.js Normal file
View File

@ -0,0 +1,7 @@
'use strict'
module.exports = {
hooks: {
"pre-commit": "yarn run lint-staged",
},
}

View File

@ -1,61 +0,0 @@
'use strict'
/* eslint strict:0, no-var:0, func-names:0 */
var createWebpackConfig = require('./createWebpackConfig')
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: [],
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
'test/**/*.js': ['webpack'],
},
webpack: createWebpackConfig(),
webpackMiddleware: {
noInfo: true,
watch: true,
},
// test results reporter to use
// possible values: 'dots', 'progress'
// 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
logLevel: config.LOG_INFO,
// start these browsers
// 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,
})
}

View File

@ -13,7 +13,7 @@ function needsFreezing(object) {
function recur(object) { function recur(object) {
Object.freeze(object) Object.freeze(object)
Object.keys(object).forEach(key => { Object.keys(object).forEach((key) => {
const value = object[key] const value = object[key]
if (needsFreezing(value)) { if (needsFreezing(value)) {
recur(value) recur(value)

View File

@ -2,5 +2,5 @@ import ifElse from './ifElse'
import curry from './util/curry' import curry from './util/curry'
export default curry((predicate, trueUpdates, object) => export default curry((predicate, trueUpdates, object) =>
ifElse(predicate, trueUpdates, x => x, object) ifElse(predicate, trueUpdates, (x) => x, object)
) )

View File

@ -29,4 +29,4 @@ u.updateIn = updateIn
u.omitted = omitted u.omitted = omitted
u.withDefault = withDefault u.withDefault = withDefault
module.exports = u export default u

View File

@ -47,7 +47,7 @@ function resolveUpdates(updates, object) {
function updateArray(updates, object) { function updateArray(updates, object) {
const newArray = [...object] const newArray = [...object]
Object.keys(updates).forEach(key => { Object.keys(updates).forEach((key) => {
newArray[key] = updates[key] newArray[key] = updates[key]
}) })
@ -91,13 +91,13 @@ function update(updates, object, ...args) {
if (Array.isArray(defaultedObject)) { if (Array.isArray(defaultedObject)) {
return updateArray(resolvedUpdates, defaultedObject).filter( return updateArray(resolvedUpdates, defaultedObject).filter(
value => value !== innerOmitted (value) => value !== innerOmitted
) )
} }
return _omitBy( return _omitBy(
{ ...defaultedObject, ...resolvedUpdates }, { ...defaultedObject, ...resolvedUpdates },
value => value === innerOmitted (value) => value === innerOmitted
) )
} }

View File

@ -7,7 +7,7 @@ const wildcard = '*'
function reducePath(acc, key) { function reducePath(acc, key) {
if (key === wildcard) { if (key === wildcard) {
return value => return (value) =>
Object.prototype.hasOwnProperty.call(value, wildcard) Object.prototype.hasOwnProperty.call(value, wildcard)
? // If we actually have wildcard as a property, update that ? // If we actually have wildcard as a property, update that
update({ [wildcard]: acc }, value) update({ [wildcard]: acc }, value)

View File

@ -1,5 +1,5 @@
import reject from 'lodash/reject' import reject from 'lodash/reject'
export default function splitPath(path) { 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)
} }

6
lint-staged.config.js Normal file
View File

@ -0,0 +1,6 @@
'use strict'
module.exports = {
'*.{js,ts}': ['eslint --fix'],
'*.{md,json,html,yml}': ['prettier --write'],
}

View File

@ -12,64 +12,59 @@
"dist", "dist",
"types" "types"
], ],
"main": "dist/index.js",
"keywords": [ "keywords": [
"immutable", "immutable",
"frozen", "frozen",
"functional", "functional",
"declarative" "declarative"
], ],
"scripts": { "source": "lib/index.js",
"dtslint": "dtslint --localTs node_modules/typescript/lib types", "main": "dist/index.js",
"test": "gulp && yarn -s dtslint", "module": "dist/index.module.js",
"test:watch": "gulp watch", "types": "types",
"prepublish": "gulp prepublish",
"perf-server": "`npm bin`/webpack-dev-server --config perf/webpack.config.js --hot"
},
"license": "MIT", "license": "MIT",
"bugs": { "bugs": {
"url": "https://github.com/substantial/updeep/issues" "url": "https://github.com/substantial/updeep/issues"
}, },
"scripts": {
"benchmark": "NODE_ENV=production node --require \"@babel/register\" perf",
"build": "microbundle",
"dev": "microbundle watch",
"dtslint": "dtslint --localTs node_modules/typescript/lib types",
"eslint": "eslint --ext .js,.jsx,.ts,.tsx",
"lint": "yarn -s eslint . && yarn -s dtslint",
"test": "mocha --recursive --require \"@babel/register\" test"
},
"dependencies": { "dependencies": {
"lodash": "^4.2.0" "lodash": "^4.2.0"
}, },
"devDependencies": { "devDependencies": {
"@babel/core": "^7.7.0",
"@babel/plugin-proposal-object-rest-spread": "^7.6.2",
"@babel/preset-env": "^7.7.1",
"@babel/preset-typescript": "^7.9.0",
"@babel/register": "^7.7.0",
"@types/chai": "^4.1.7", "@types/chai": "^4.1.7",
"@types/lodash": "^4.14.119", "@types/lodash": "^4.14.119",
"@types/mocha": "^7.0.1", "@types/mocha": "^7.0.1",
"@types/node": "^13.1.0", "@types/node": "^13.9.8",
"babel-core": "^6.4.0", "@typescript-eslint/eslint-plugin": "^2.26.0",
"babel-loader": "^6.2.1", "@typescript-eslint/parser": "^2.26.0",
"babel-preset-es2015": "^6.3.13",
"babel-preset-stage-2": "^6.3.13",
"benchmark": "^2.1.4", "benchmark": "^2.1.4",
"chai": "^4.2.0", "chai": "^4.2.0",
"dtslint": "^2.0.0", "chalk": "^4.0.0",
"eslint": "^4.19.1", "dtslint": "^3.4.1",
"eslint-config-airbnb-base": "^11.1.3", "eslint": "^6.8.0",
"eslint-config-prettier": "^6.3.0", "eslint-config-prettier": "^6.10.1",
"eslint-plugin-import": "^2.2.0", "eslint-plugin-expect-type": "^0.0.4",
"eslint-plugin-prettier": "^2.0.1", "eslint-plugin-import": "^2.20.2",
"exports-loader": "^0.7.0", "eslint-plugin-prettier": "^3.1.2",
"gulp": "^3.6.0", "husky": "^4.2.3",
"gulp-babel": "^7.0.1", "lint-staged": "^10.1.1",
"gulp-eslint": "^3.0.1", "microbundle": "^0.11.0",
"gulp-mocha": "^2.0.0",
"karma": "^4.3.0",
"karma-babel-preprocessor": "^7.0.0",
"karma-chrome-launcher": "^3.1.0",
"karma-mocha": "^1.3.0",
"karma-mocha-reporter": "^2.2.5",
"karma-phantomjs-launcher": "^1.0.4",
"karma-webpack": "^2.0.13",
"mocha": "^7.0.0", "mocha": "^7.0.0",
"phantomjs-prebuilt": "^2.1.14", "prettier": "^2.0.2",
"prettier": "^1.1.0", "table": "^5.4.6",
"rimraf": "^3.0.0", "typescript": "^3.6.3"
"typescript": "^3.6.3", }
"webpack": "^1.10.5",
"webpack-dev-server": "^3.1.11",
"webpack-stream": "^2.1.0"
},
"types": "types"
} }

View File

@ -1,10 +0,0 @@
{
"extends": "../.eslintrc",
"rules": {
"new-cap": [2, {
"capIsNewExceptions": [
"Suite"
]
}],
}
}

14
perf/.eslintrc.js Normal file
View File

@ -0,0 +1,14 @@
module.exports = {
extends: require.resolve("../.eslintrc.js"),
env: {
node: true,
es6: true,
},
parserOptions: {
sourceType: 'module',
},
rules: {
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': 'off'
}
}

View File

@ -1,14 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<title>updeep perf</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<div>Running tests...</div>
<div id='perf'></div>
<script src='/assets/perf.js'></script>
<p>Done!</p>
</body>
</html>

View File

@ -1,14 +1,14 @@
/* eslint no-console:0, no-unused-vars:0, import/no-extraneous-dependencies:0 */ import Benchmark from 'benchmark'
/* global document */ import {table} from 'table'
const Benchmark = require('benchmark') import chalk from 'chalk'
const u = require('../lib') import _ from 'lodash'
const _ = require('lodash') import u from '../dist/index.umd.js'
const { curry2, curry4 } = require('../lib/util/curry') import {curry2, curry4 } from '../lib/util/curry'
const add4 = (a, b, c, d) => a + b + c + d const add4 = (a, b, c, d) => a + b + c + d
const add2 = (a, b) => a + b const add2 = (a, b) => a + b
const fakeCurryAdd = x => y => x + y const fakeCurryAdd = (x) => (y) => x + y
const lodashCurryAdd2 = _.curry(add2) const lodashCurryAdd2 = _.curry(add2)
const updeepCurryAdd2 = curry2(add2) const updeepCurryAdd2 = curry2(add2)
const lodashCurryAdd4 = _.curry(add4) const lodashCurryAdd4 = _.curry(add4)
@ -18,33 +18,31 @@ const updeepCurryAdd4 = curry4(add4)
const array = [0, 1, 2, 3, 4, 5] const array = [0, 1, 2, 3, 4, 5]
// const doUpdate = u(x => x + 1); // const doUpdate = u(x => x + 1);
function log(str) {
if (typeof document !== 'undefined') { const log = console.log
console.log(str)
const el = document.getElementById('perf')
el.innerHTML += str
}
}
function createSuite(suiteName, tests) { function createSuite(suiteName, tests) {
const suite = Benchmark.Suite() // eslint-disable const results = []
return () => { const suite = Benchmark.Suite({
log(`<h2>${suiteName}</h2><ul>`) onCycle: (event) => {
results.push(event.target)
},
onError: (event) => {
console.error(event)
},
})
_.each(tests, (fn, testName) => { _.each(tests, (fn, testName) => {
suite.add(testName, fn) suite.add(testName, fn)
}) })
suite return () => new Promise((resolve, reject) => {
.on('cycle', event => { suite.on('complete', () => resolve({
log(`<li>${String(event.target)}</li>`) suiteName,
results,
})).on('error', reject).run({ async: true})
}) })
.on('complete', () => {
log('</ul>')
})
.run({ async: true })
}
} }
const curryVsLodash = createSuite('Curry', { const curryVsLodash = createSuite('Curry', {
@ -82,6 +80,25 @@ const applyVsDestructure = createSuite('apply vs destructure', {
destructure: () => fnDestructure(1, 2, 3, 4, 5), destructure: () => fnDestructure(1, 2, 3, 4, 5),
}) })
curryVsLodash() const printSuiteResults = (suiteResults) => {
mapVsLodash() const HEADERS = ['Suite Name', 'Results (fastest first)'].map(s => chalk.bold(s))
// applyVsDestructure();
const data = suiteResults.reduce((acc, {suiteName, results}) => {
const row = [
chalk.cyan(suiteName),
results.sort((a, b) => -a.compare(b)).map(String).join('\n'),
]
acc.push(row)
return acc
}, [HEADERS])
log(table(data))
}
Promise.all([
curryVsLodash(),
mapVsLodash(),
// applyVsDestructure(),
]).then(printSuiteResults)

View File

@ -1,29 +0,0 @@
'use strict'
/* eslint strict:0, no-var:0, func-names:0 */
var path = require('path')
var config = require('../createWebpackConfig')({
context: __dirname,
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$/]
module.exports = config

12
prettier.config.js Normal file
View File

@ -0,0 +1,12 @@
'use strict'
module.exports = {
endOfLine: 'lf',
semi: false,
singleQuote: true,
tabWidth: 2,
trailingComma: 'es5',
bracketSpacing: false,
proseWrap: 'always',
}

View File

@ -1,8 +0,0 @@
{
"env": {
"mocha": true
},
"rules": {
"no-unused-expressions": 0
}
}

View File

@ -50,15 +50,14 @@ describe('u.freeze', () => {
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', () => { it('does not freeze in production', () => {
process.env.NODE_ENV = 'production' process.env.NODE_ENV = 'production'
const object = {} const object = {}
u.freeze(object) u.freeze(object)
expect(Object.isFrozen(object)).to.be.false expect(Object.isFrozen(object)).to.be.false
}) })
}
it('handles null objects', () => { it('handles null objects', () => {
const object = { foo: null } const object = { foo: null }

View File

@ -19,7 +19,7 @@ describe('u.if', () => {
it('will use the result of a function passed as a predicate', () => { it('will use the result of a function passed as a predicate', () => {
const object = { a: 0 } const object = { a: 0 }
const aIsThree = x => x.a === 3 const aIsThree = (x) => x.a === 3
const result = u.if(aIsThree, { b: 1 }, object) const result = u.if(aIsThree, { b: 1 }, object)
expect(result).to.eql({ a: 0 }) expect(result).to.eql({ a: 0 })
@ -27,8 +27,8 @@ describe('u.if', () => {
it('can be partially applied', () => { it('can be partially applied', () => {
const object = { a: 2 } const object = { a: 2 }
const isEven = x => x % 2 === 0 const isEven = (x) => x % 2 === 0
const inc = x => x + 1 const inc = (x) => x + 1
const result = u( const result = u(
{ {

View File

@ -16,7 +16,7 @@ describe('u.ifElse', () => {
it('will use the result of a function passed as a predicate', () => { it('will use the result of a function passed as a predicate', () => {
const object = { a: 0 } const object = { a: 0 }
const aIsThree = x => x.a === 3 const aIsThree = (x) => x.a === 3
const result = u.ifElse(aIsThree, { b: 1 }, { b: 4 }, object) 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 })
@ -24,9 +24,9 @@ describe('u.ifElse', () => {
it('can be partially applied', () => { it('can be partially applied', () => {
const object = { a: 2 } const object = { a: 2 }
const isEven = x => x % 2 === 0 const isEven = (x) => x % 2 === 0
const inc = x => x + 1 const inc = (x) => x + 1
const dec = x => x - 1 const dec = (x) => x - 1
const result = u( const result = u(
{ {

View File

@ -8,7 +8,7 @@ describe('u.is', () => {
}) })
it('returns true if path matches a function predicate', () => { it('returns true if path matches a function predicate', () => {
const isEven = x => x % 2 === 0 const isEven = (x) => x % 2 === 0
const result = u.is('a.b', isEven, { a: { b: 6 } }) const result = u.is('a.b', isEven, { a: { b: 6 } })
expect(result).to.be.true expect(result).to.be.true
}) })
@ -19,7 +19,7 @@ describe('u.is', () => {
}) })
it('returns false if path matches a function predicate', () => { it('returns false if path matches a function predicate', () => {
const isEven = x => x % 2 === 0 const isEven = (x) => x % 2 === 0
const result = u.is('a.b', isEven, { a: { b: 7 } }) const result = u.is('a.b', isEven, { a: { b: 7 } })
expect(result).to.be.false expect(result).to.be.false
}) })

View File

@ -4,7 +4,7 @@ import u from '../lib'
describe('u.map', () => { describe('u.map', () => {
it('applies updates to each item in an array', () => { it('applies updates to each item in an array', () => {
const object = [0, 1, 2] const object = [0, 1, 2]
const inc = x => x + 1 const inc = (x) => x + 1
const result = u.map(inc, object) const result = u.map(inc, object)
expect(result).to.eql([1, 2, 3]) expect(result).to.eql([1, 2, 3])
@ -12,7 +12,7 @@ describe('u.map', () => {
it('applies updates to each value in an object', () => { it('applies updates to each value in an object', () => {
const object = { a: 0, b: 1, c: 2 } const object = { a: 0, b: 1, c: 2 }
const inc = x => x + 1 const inc = (x) => x + 1
const result = u.map(inc, object) 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 })
@ -27,7 +27,7 @@ describe('u.map', () => {
it('returns the same object if no updates are made', () => { it('returns the same object if no updates are made', () => {
const array = [0, 1] const array = [0, 1]
const ident = x => x const ident = (x) => x
let result = u.map(ident, array) let result = u.map(ident, array)
expect(result).to.equal(array) expect(result).to.equal(array)

View File

@ -18,7 +18,7 @@ describe('u.reject', () => {
const object = { foo: [1, 2, 3] } const object = { foo: [1, 2, 3] }
const result = u( const result = u(
{ {
foo: u.reject(x => x === 'Justin Bieber'), foo: u.reject((x) => x === 'Justin Bieber'),
}, },
object object
) )
@ -30,7 +30,7 @@ describe('u.reject', () => {
const object = { foo: [1, 2, 3, 4] } const object = { foo: [1, 2, 3, 4] }
const result = u( const result = u(
{ {
foo: u.reject(x => x === 4), foo: u.reject((x) => x === 4),
}, },
object object
) )

View File

@ -9,7 +9,7 @@ describe('u.updateIn', () => {
}) })
it('can update a single path described with a string with a function', () => { it('can update a single path described with a string with a function', () => {
const inc = x => x + 1 const inc = (x) => x + 1
const object = { a: { b: 0 } } const object = { a: { b: 0 } }
const result = u.updateIn('a.b', inc, object) const result = u.updateIn('a.b', inc, object)
expect(result).to.eql({ a: { b: 1 } }) expect(result).to.eql({ a: { b: 1 } })
@ -45,17 +45,17 @@ describe('u.updateIn', () => {
it('can multiple elements of an array with *', () => { it('can multiple elements of an array with *', () => {
let object = { a: [{ b: 0 }, { b: 1 }, { b: 2 }] } let object = { a: [{ b: 0 }, { b: 1 }, { b: 2 }] }
let result = u.updateIn('a.*.b', x => x + 1, object) let result = u.updateIn('a.*.b', (x) => x + 1, object)
expect(result).to.eql({ a: [{ b: 1 }, { b: 2 }, { b: 3 }] }) expect(result).to.eql({ a: [{ b: 1 }, { b: 2 }, { b: 3 }] })
object = { a: [0, 1, 2] } object = { a: [0, 1, 2] }
result = u.updateIn(['a', '*'], x => x + 1, object) result = u.updateIn(['a', '*'], (x) => x + 1, object)
expect(result).to.eql({ a: [1, 2, 3] }) expect(result).to.eql({ a: [1, 2, 3] })
}) })
it('can update properties named *', () => { it('can update properties named *', () => {
const object = { '*': 1, x: 1 } const object = { '*': 1, x: 1 }
const result = u.updateIn('*', x => x + 1, object) const result = u.updateIn('*', (x) => x + 1, object)
expect(result).to.eql({ '*': 2, x: 1 }) expect(result).to.eql({ '*': 2, x: 1 })
}) })
}) })

View File

@ -57,7 +57,7 @@ describe('updeep', () => {
}) })
it('can use functions to update values', () => { it('can use functions to update values', () => {
const inc = i => i + 1 const inc = (i) => i + 1
const object = { foo: 3, bar: 4, baz: 7 } const object = { foo: 3, bar: 4, baz: 7 }
const result = u({ foo: inc, bar: inc }, object) const result = u({ foo: inc, bar: inc }, object)
@ -65,7 +65,7 @@ describe('updeep', () => {
}) })
it('can be partially applied', () => { it('can be partially applied', () => {
const inc = i => i + 1 const inc = (i) => i + 1
const object = { foo: 3 } const object = { foo: 3 }
const incFoo = u({ foo: inc }) const incFoo = u({ foo: inc })
@ -95,7 +95,7 @@ describe('updeep', () => {
}) })
it('can take a function as the updater', () => { 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)
}) })
@ -148,7 +148,7 @@ describe('updeep', () => {
describe('u.omitted', () => { describe('u.omitted', () => {
it('omit properties via u.omitted', () => { it('omit properties via u.omitted', () => {
expectU(u({ a: u.omitted, b: i => i + 1 }), { a: 1, b: 2 }, { b: 3 }) expectU(u({ a: u.omitted, b: (i) => i + 1 }), { a: 1, b: 2 }, { b: 3 })
}) })
it('omit array and object properties', () => { it('omit array and object properties', () => {

View File

@ -3,7 +3,7 @@ import { curry1, curry2, curry3, curry4, _ } from '../../lib/util/curry'
describe('curry1', () => { describe('curry1', () => {
it('can curry one arguments', () => { it('can curry one arguments', () => {
const addOne = curry1(x => x + 1) const addOne = curry1((x) => x + 1)
expect(addOne(3)).to.equal(4) expect(addOne(3)).to.equal(4)
expect(addOne()(3)).to.equal(4) expect(addOne()(3)).to.equal(4)
}) })

View File

@ -3,14 +3,14 @@ import u from '../lib'
describe('u.withDefault', () => { describe('u.withDefault', () => {
it('uses the default as the basis for the update if the object is undefined', () => { it('uses the default as the basis for the update if the object is undefined', () => {
const inc = x => x + 1 const inc = (x) => x + 1
const result = u.withDefault({ a: 0 }, { a: inc }, undefined) 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', () => { it('uses ignores the default if the object is defined', () => {
const inc = x => x + 1 const inc = (x) => x + 1
const result = u.withDefault({ a: 0 }, { a: inc }, { a: 3 }) const result = u.withDefault({ a: 0 }, { a: inc }, { a: 3 })
expect(result).to.eql({ a: 4 }) expect(result).to.eql({ a: 4 })

View File

@ -39,7 +39,7 @@ u.ifElse(false, "foo", 3, { a: 3 }); // $ExpectType 3
u.ifElse(true, "foo", 3, { a: 3 }); // $ExpectType "foo" u.ifElse(true, "foo", 3, { a: 3 }); // $ExpectType "foo"
// *** map *** // *** map ***
const inc = (i:number) => i+1; const inc = (i: number) => i+1;
u.map(inc, [1,2,3]); // $ExpectType number[] u.map(inc, [1,2,3]); // $ExpectType number[]
u.map(inc, ["potato"]); // $ExpectType number[] u.map(inc, ["potato"]); // $ExpectType number[]

View File

@ -1,5 +0,0 @@
'use strict'
/* eslint strict:0, no-var:0, func-names:0 */
module.exports = require('./createWebpackConfig')()

9254
yarn.lock

File diff suppressed because it is too large Load Diff