Skip to content

Commit

Permalink
Merge pull request #19 from thibmaek/release/1.13.0
Browse files Browse the repository at this point in the history
Release/1.13.0
  • Loading branch information
thibmaek authored Sep 13, 2018
2 parents 93addc7 + d311814 commit d128ba5
Show file tree
Hide file tree
Showing 33 changed files with 4,977 additions and 2,310 deletions.
2 changes: 1 addition & 1 deletion .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"plugins": ["transform-runtime"],
"presets": [
["env", { "targets": { "node": "current" } }],
"flow",
"flow"
]
}
}
Expand Down
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"extends": "thibmaek",
"rules": {
"import/prefer-default-export": "off",
"comma-dangle": [
"error",
"always-multiline"
Expand Down
4 changes: 4 additions & 0 deletions .github/release-drafter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
template: |
## What's Changed
$CHANGES
6 changes: 6 additions & 0 deletions .huskyrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"hooks": {
"pre-commit": "lint-staged",
"pre-push": "npm test"
}
}
11 changes: 11 additions & 0 deletions .lintstagedrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"ignore": [
"package-lock.json"
],
"linters": {
"**/*.js": [
"eslint --fix",
"git add"
]
}
}
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2017 Thibault Maekelbergh
Copyright (c) 2018 Thibault Maekelbergh

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
23 changes: 17 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
# pure-fun
😊 A collection of JavaScript pure functions/helpers with zero dependencies.
<p align="center">
<h1 align="center">😊 pure-fun</h1>
<p>A collection of JavaScript pure functions/helpers with zero dependencies.</p>

Currently ESM support only, use Babel or @std/esm (node v8+) for Node.
<p align="center">
<a href="https://travis-ci.org/thibmaek/pure-fun.svg?branch=master">
<img src="https://badgen.net/badge/Build status/travis?icon=travis" alt="Travis CI">
</a>
<a href="https://www.notion.so/thibmaek/89015d654dbf4600acf001dbe229fb38?v=b5d231eef3a84993b16abca0a120b04e">
<img src="https://img.shields.io/badge/check-our%20roadmap-5362F5.svg" alt="Chat">
</a>
</p>

[![Build Status](https://travis-ci.org/thibmaek/pure-fun.svg?branch=master)](https://travis-ci.org/thibmaek/pure-fun)
<blockquote>Currently ESM support only, use Babel or @std/esm (node v8+) for Node.</blockquote>
</p>

## Installing
# Installing

```
```console
npm install (--save-dev) pure-fun
yarn add (--dev) pure-fun
```

## Usage
Expand All @@ -26,6 +36,7 @@ const delayedRes = sleep(1000)
```

### Development

The dev env for this is Node LTS/latest with ESM (import/export) syntax as a standard.
Linting is done with eslint and testing with jest.

Expand Down
70 changes: 21 additions & 49 deletions esm/arrays/index.js
Original file line number Diff line number Diff line change
@@ -1,49 +1,21 @@
import diff from './diff';
import filterEven from './filterEven';
import filterFalsies from './filterFalsies';
import flatten from './flatten';
import getDuplicates from './getDuplicates';
import groupBy from './groupBy';
import head from './head';
import initial from './initial';
import intersect from './intersect';
import isEmpty from './isEmpty';
import join from './join';
import last from './last';
import median from './median';
import pickRandom from './pickRandom';
import randomize from './randomize';
import sortBy from './sortBy';
import tail from './tail';
import total from './total';
import unique from './unique';
import without from './without';
import zip from './zip';

export default {
diff,
difference: diff,
duplicates: getDuplicates,
empty: isEmpty,
filterEven,
filterFalsies,
flatten,
getDuplicates,
groupBy,
head,
initial,
intersect,
intersection: intersect,
isEmpty,
join,
last,
median,
pickRandom,
randomize,
sortBy,
tail,
total,
unique,
without,
zip,
};
export { default as diff } from './diff';
export { default as filterEven } from './filterEven';
export { default as filterFalsies } from './filterFalsies';
export { default as flatten } from './flatten';
export { default as getDuplicates } from './getDuplicates';
export { default as groupBy } from './groupBy';
export { default as head } from './head';
export { default as initial } from './initial';
export { default as intersect } from './intersect';
export { default as isEmpty } from './isEmpty';
export { default as join } from './join';
export { default as last } from './last';
export { default as median } from './median';
export { default as pickRandom } from './pickRandom';
export { default as randomize } from './randomize';
export { default as sortBy } from './sortBy';
export { default as tail } from './tail';
export { default as total } from './total';
export { default as unique } from './unique';
export { default as without } from './without';
export { default as zip } from './zip';
3 changes: 2 additions & 1 deletion esm/async/__tests__/throttle.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ const THROTTLE_TIME = 4000;
const PROMISE = new Promise(resolve => resolve({ status: `RESOLVED` }));

describe(`[Async]: throttle`, () => {
beforeAll(() => console.log(`Starting a ${THROTTLE_TIME}ms Promise test...`));

it(`should return a Promise`, () => {
expect(throttle(THROTTLE_TIME)).toBeInstanceOf(Promise);
expect(throttle(THROTTLE_TIME, PROMISE)).toBeInstanceOf(Promise);
});

describe(`should throttle the function`, () => {
beforeAll(() => console.log(`Starting a ${THROTTLE_TIME}ms Promise test...`));
it(`should just wait for given time if no promise is passed`, done => {
const startTime = process.hrtime();
const throttledPromise = throttle(500);
Expand Down
14 changes: 4 additions & 10 deletions esm/async/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
import mapPromise from './mapPromise';
import sleep from './sleep';
import throttle from './throttle';

export default {
map: mapPromise,
sleep,
takeAtLeast: throttle,
throttle,
};
export { default as map } from './mapPromise';
export { default as forEach } from './forEach';
export { default as sleep } from './sleep';
export { default as throttle } from './throttle';
9 changes: 2 additions & 7 deletions esm/dates/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,2 @@
import convertToDateIfNeeded from './convertToDateIfNeeded';
import isDate from './isDate';

export default {
convertToDate: convertToDateIfNeeded,
isDate,
};
export { default as convertToDateIfNeeded } from './convertToDateIfNeeded';
export { default as isDate } from './isDate';
16 changes: 4 additions & 12 deletions esm/functions/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
import always from './always';
import compose from './compose';
import merge from './merge';
import requireArgs from './requireArgs';

export default {
always,
compose,
converge: merge,
merge,
requireArgs,
};
export { default as always } from './always';
export { default as compose } from './compose';
export { default as merge } from './merge';
export { default as requireArgs } from './requireArgs';
6 changes: 1 addition & 5 deletions esm/isomorphics/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
import entries from './entries';

export default {
entries,
};
export { default as entries } from './entries';
6 changes: 1 addition & 5 deletions esm/maps/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
import deepClone from './deepClone';

export default {
deepClone,
};
export { default as deepClone } from './deepClone';
9 changes: 2 additions & 7 deletions esm/numbers/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,2 @@
import isEven from './isEven';
import isNumber from './isNumber';

export default {
isEven,
isNumber,
};
export { default as isEven } from './isEven';
export { default as isNumber } from './isNumber';
22 changes: 22 additions & 0 deletions esm/objects/__tests__/deepCopy.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import deepCopy from '../deepCopy';

const obj1 = { a: 1, b: { c: { d: [4] } } };
const arr1 = [{ ...obj1 }, [{ d: [{ c: 3 }] }]];

describe(`[Objects]: deepCopy`, () => {
it(`should make a deep copy of an object`, () => {
const cp = deepCopy(obj1);
expect(cp).toEqual(obj1);

obj1.b.c = 2;
expect(cp).not.toEqual(obj1);
});
it(`should also work on arrays`, () => {
const cp = deepCopy(arr1);
expect(cp).toEqual(arr1);

arr1[0] = null;
arr1[1].d = 4;
expect(cp).not.toEqual(arr1);
});
});
13 changes: 13 additions & 0 deletions esm/objects/deepCopy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
const deepCopy = obj => {
if (typeof obj === `object` && !Array.isArray(obj)) {
return Object.keys(obj)
.map(k => ({ [k]: deepCopy(obj[k]) }))
.reduce((a, b) => Object.assign(a, b), {});
} else if (Array.isArray(obj)) {
return obj.map(deepCopy);
}

return obj;
};
export default deepCopy;
29 changes: 9 additions & 20 deletions esm/objects/index.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,9 @@
import deepMerge from './deepMerge';
import getMappedArray from './getMappedArray';
import getQueryString from './getQueryString';
import isEmpty from './isEmpty';
import makeImmutable from './makeImmutable';
import makeIterable from './makeIterable';
import parseJSON from './parseJSON';
import pluckDeep from './pluckDeep';

export default {
deepMerge,
empty: isEmpty,
getMappedArray,
getQueryString,
isEmpty,
makeImmutable,
makeIterable,
parseJSON,
pluckDeep,
};
export { default as deepCopy } from './deepCopy';
export { default as deepMerge } from './deepMerge';
export { default as getMappedArray } from './getMappedArray';
export { default as getQueryString } from './getQueryString';
export { default as isEmpty } from './isEmpty';
export { default as makeImmutable } from './makeImmutable';
export { default as makeIterable } from './makeIterable';
export { default as parseJSON } from './parseJSON';
export { default as pluckDeep } from './pluckDeep';
3 changes: 3 additions & 0 deletions esm/sets/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export { default as diff } from './diff';
export { default as intersect } from './intersect';
export { default as join } from './join';
15 changes: 3 additions & 12 deletions esm/strings/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
import capitalize from './capitalize';
import ellipsize from './ellipsize';
import isEmpty from './isEmpty';

export default {
capitalize,
ellipsize,
empty: isEmpty,
isEmpty,
trunc: ellipsize,
truncate: ellipsize,
};
export { default as capitalize } from './capitalize';
export { default as ellipsize } from './ellipsize';
export { default as isEmpty } from './isEmpty';
Loading

0 comments on commit d128ba5

Please sign in to comment.