Skip to content

Commit

Permalink
refactor: restructure utils (#36)
Browse files Browse the repository at this point in the history
* chore: upgrade packages

* refactor: change utils and tests files

It moves tests to test directory at root and utils to the src
  • Loading branch information
helderberto authored Jan 27, 2021
1 parent c8d779e commit 7bd5ac6
Show file tree
Hide file tree
Showing 15 changed files with 288 additions and 271 deletions.
4 changes: 2 additions & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = {
roots: ['<rootDir>/src'],
roots: ['<rootDir>'],
testEnvironment: 'node',
collectCoverageFrom: ['<rootDir>/src/**/*.js'],
collectCoverageFrom: ['<rootDir>/**/*.js'],
coverageDirectory: 'coverage',
testPathIgnorePatterns: ['/node_modules/', 'dist'],
}
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mxs",
"version": "0.3.0",
"version": "0.4.0",
"description": "⚔️ Lightweight functional JavaScript utilities",
"main": "dist/mxs.js",
"module": "src/index.js",
Expand Down Expand Up @@ -53,22 +53,22 @@
"babel-loader": "^8.2.2",
"clean-webpack-plugin": "^3.0.0",
"docsify-cli": "^4.4.2",
"eslint": "^7.16.0",
"eslint-config-prettier": "^7.1.0",
"eslint": "^7.18.0",
"eslint-config-prettier": "^7.2.0",
"eslint-config-standard": "^16.0.2",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^3.3.0",
"eslint-plugin-prettier": "^3.3.1",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-standard": "^5.0.0",
"faker": "^5.1.0",
"husky": "^4.3.6",
"faker": "^5.2.0",
"husky": "^4.3.8",
"jest": "^26.6.3",
"jsdoc-to-markdown": "^6.0.1",
"lint-staged": "10.5.3",
"prettier": "^2.2.1",
"webpack": "^5.11.1",
"webpack-cli": "^4.3.0",
"webpack": "^5.18.0",
"webpack-cli": "^4.4.0",
"webpack-merge": "^5.7.3"
},
"license": "MIT"
Expand Down
6 changes: 4 additions & 2 deletions src/common/apply-to/index.js → src/applyTo.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { curry } from '../curry'
import curry from './curry'

/**
*
Expand All @@ -14,6 +14,8 @@ import { curry } from '../curry'
* applyTo(1, increment) // => 2
*/

export const applyTo = curry(function applyTo(value, fn) {
const applyTo = curry(function applyTo(value, fn) {
return fn(value)
})

export default applyTo
5 changes: 0 additions & 5 deletions src/common/index.js

This file was deleted.

4 changes: 2 additions & 2 deletions src/common/compose/index.js → src/compose.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { applyTo } from '../apply-to'
import applyTo from './applyTo'

/**
*
Expand All @@ -15,7 +15,7 @@ import { applyTo } from '../apply-to'
* doubleAndIncrement(1) //=> 3
*/

export function compose(...functions) {
export default function compose(...functions) {
return function reduceFunctions(value) {
return functions.reduceRight(applyTo, value)
}
Expand Down
2 changes: 1 addition & 1 deletion src/common/curry/index.js → src/curry.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* const curriedSum = curry(sum)
* curriedSum(1)(2, 3) //=> 6
*/
export function curry(fn) {
export default function curry(fn) {
return function curried(...args) {
if (args.length >= fn.length) {
return fn.apply(this, args)
Expand Down
6 changes: 5 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
/* istanbul ignore file */
export * from './common'
export { default as pipe } from './pipe'
export { default as compose } from './compose'
export { default as curry } from './curry'
export { default as applyTo } from './applyTo'
export { default as isEmpty } from './isEmpty'
2 changes: 1 addition & 1 deletion src/common/is-empty/index.js → src/isEmpty.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* isEmpty([]) //=> true
* isEmpty() //=> true
*/
export const isEmpty = (value) => {
export default function isEmpty(value) {
return (
value === null ||
value === '' ||
Expand Down
5 changes: 2 additions & 3 deletions src/common/pipe/index.js → src/pipe.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { applyTo } from '../apply-to'
import applyTo from './applyTo'

/**
*
Expand All @@ -14,8 +14,7 @@ import { applyTo } from '../apply-to'
* const incrementAndDouble = pipe(increment, double)
* incrementAndDouble(1) //=> 4
*/

export function pipe(...functions) {
export default function pipe(...functions) {
return function reduceFunctions(value) {
return functions.reduce(applyTo, value)
}
Expand Down
2 changes: 1 addition & 1 deletion src/common/apply-to/test.js → test/applyTo.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { applyTo } from '.'
import { applyTo } from '../src'

describe('applyTo', () => {
it('should validate applying simple function', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/common/compose/test.js → test/compose.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { compose } from '.'
import { compose } from '../src'

describe('compose', () => {
const increment = jest.fn((x) => x + 1)
Expand Down
2 changes: 1 addition & 1 deletion src/common/curry/test.js → test/curry.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { curry } from '.'
import { curry } from '../src'

describe('curry', () => {
it('should validate curried numbers', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/common/is-empty/test.js → test/isEmpty.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isEmpty } from '.'
import { isEmpty } from '../src'

describe('isEmpty', () => {
it('should check if value is an empty string', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/common/pipe/test.js → test/pipe.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { pipe } from '.'
import { pipe } from '../src'

describe('pipe', () => {
const increment = jest.fn((x) => x + 1)
Expand Down
Loading

0 comments on commit 7bd5ac6

Please sign in to comment.