Skip to content

Commit

Permalink
Merge pull request #5 from dhershman1/development
Browse files Browse the repository at this point in the history
v3.1.0 development
  • Loading branch information
Dustin Hershman authored May 7, 2019
2 parents e304376 + 0682868 commit fc11d86
Show file tree
Hide file tree
Showing 15 changed files with 1,784 additions and 1,404 deletions.
10 changes: 5 additions & 5 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
old-readmes/
old-changelogs/
.travis.yml
bitbucket-pipelines.yml
webpack.config.js
webpack.dist.js
rollup.config.js
.babelrc
.circleci
.nyc_output
.eslintrc.js
.eslintignore
.gitignore
src/
configs/
tests/
scripts/
docs/
jsdoc.json
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ A small modern, and functional phone number library which gathers inspiration fr

## How-To

`npm i phone-fns`
```cli
npm i phone-fns
```

Standard module system

Expand Down
12 changes: 12 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Changelog

## 3.1.0

### Improved

- Switched to internal currying
- Improved `format`s performance and broke it down to a more intelligent function

### Fixed

- Typo in `format`s example
- Remove unused code

## v3.0.0

### Breaking Changes
Expand Down
44 changes: 27 additions & 17 deletions dist/phone-fns.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,20 @@
};
};

function _curry2(fn) {
return function f2(a, b) {
if (!arguments.length) {
return f2;
}
if (arguments.length === 1) {
return function (_b) {
return fn(a, _b);
};
}
return fn(a, b);
};
}

var isValid = function isValid(phone) {
var uglyPhone = uglify(phone);
if (kyanite.or(kyanite.isEmpty(uglyPhone), kyanite.length(uglyPhone)) < 7) {
Expand All @@ -75,27 +89,23 @@
return /^\+?([0-9]{2})\)?[-. ]?([0-9]{4})[-. ]?([0-9]{4})$/.test(areaCode + localCode + lineNumber);
};

var validFormat = function validFormat(layout, phone) {
var _compose = kyanite.compose(kyanite.countBy(kyanite.toUpper), kyanite.split(''), layout),
N = _compose.N,
_compose$C = _compose.C,
C = _compose$C === void 0 ? 0 : _compose$C;
return kyanite.pipe([uglify, kyanite.length, kyanite.eq(kyanite.add(N, C))], phone);
var validFormat = function validFormat(layout) {
return function (phone) {
var _compose = kyanite.compose(kyanite.countBy(kyanite.toUpper), kyanite.split(''), layout),
N = _compose.N,
_compose$C = _compose.C,
C = _compose$C === void 0 ? 0 : _compose$C;
return kyanite.pipe([uglify, kyanite.length, kyanite.eq(kyanite.add(N, C))], phone);
};
};
var format = function format(layout, phone) {
var fullPhone = kyanite.compose(kyanite.split(''), uglify, phone);
var cCount = kyanite.includes('C', layout) ? kyanite.length(layout.match(/C/g)) : 0;
if (kyanite.or(!isValid(phone), !validFormat(layout, phone))) {
return phone;
}
return fullPhone.reduce(function (acc, d, i) {
if (kyanite.gt(i, cCount)) {
return acc.replace(/C/i, d);
}
return acc.replace(/N/i, d);
}, layout);
var _reduce = kyanite.addIndex(kyanite.reduce);
return kyanite.branch(kyanite.both(kyanite.complement(isValid), kyanite.complement(validFormat(layout))), kyanite.identity, kyanite.pipe([kyanite.split(''), uglify, _reduce(function (d, acc, i) {
return kyanite.gt(i, cCount) ? kyanite.replace(/C/i, d, acc) : kyanite.replace(/N/i, d, acc);
}, layout)]), phone);
};
var format$1 = kyanite.curry(format);
var format$1 = _curry2(format);

exports.breakdown = breakdown;
exports.format = format$1;
Expand Down
2 changes: 1 addition & 1 deletion dist/phone-fns.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/breakdown.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ <h1 class="page-title">breakdown.js</h1>
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.1</a> using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>

<script>prettyPrint();</script>
Expand Down
56 changes: 38 additions & 18 deletions docs/format.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,26 @@ <h1 class="page-title">format.js</h1>

<section>
<article>
<pre class="prettyprint source linenums"><code>import { add, compose, curry, gt, eq, includes, length, or, pipe, countBy, split, toUpper } from 'kyanite'

<pre class="prettyprint source linenums"><code>import {
add,
addIndex,
both,
branch,
complement,
compose,
countBy,
eq,
gt,
identity,
includes,
length,
pipe,
reduce,
replace,
split,
toUpper
} from 'kyanite'
import _curry2 from './_internals/_curry2'
import isValid from './isValid'
import uglify from './uglify'

Expand All @@ -60,7 +78,7 @@ <h1 class="page-title">format.js</h1>
* @param {String} layout The desired layout format
* @param {String} phone The phone number to validate against
*/
const validFormat = (layout, phone) => {
const validFormat = layout => phone => {
const { N, C = 0 } = compose(countBy(toUpper), split(''), layout)

return pipe([
Expand All @@ -82,7 +100,7 @@ <h1 class="page-title">format.js</h1>
* @return {String} Returns a string which is the formatted phone number
*
* @example
* format((NNN) NNN.NNNN', '444-555-6666') // => '(444) 555.6666'
* format('(NNN) NNN.NNNN', '444-555-6666') // => '(444) 555.6666'
* format('C + (NNN) NNN.NNNN', '1444-555-6666') // => '1 + (444) 555.6666'
* format('CC + NNN.NNN.NNNN', '163334445555') // => '16 + 333.444.5555'
* format('(NNN) NNN.NNNN x NNNN', '44455566668989') // => '(444) 555.6666 x 8989'
Expand All @@ -97,23 +115,25 @@ <h1 class="page-title">format.js</h1>
* fn('(333) 444-5555') // => '333.444.5555'
*/
const format = (layout, phone) => {
const fullPhone = compose(split(''), uglify, phone)
const cCount = includes('C', layout) ? length(layout.match(/C/g)) : 0
const _reduce = addIndex(reduce)

if (or(!isValid(phone), !validFormat(layout, phone))) {
return phone
}

return fullPhone.reduce((acc, d, i) => {
if (gt(i, cCount)) {
return acc.replace(/C/i, d)
}

return acc.replace(/N/i, d)
}, layout)
return branch(
both(
complement(isValid),
complement(validFormat(layout))
),
identity,
pipe([
split(''),
uglify,
_reduce((d, acc, i) => gt(i, cCount) ? replace(/C/i, d, acc) : replace(/N/i, d, acc), layout)
]),
phone
)
}

export default curry(format)
export default _curry2(format)
</code></pre>
</article>
</section>
Expand All @@ -128,7 +148,7 @@ <h1 class="page-title">format.js</h1>
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.1</a> using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>

<script>prettyPrint();</script>
Expand Down
6 changes: 3 additions & 3 deletions docs/functions.html
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ <h4 class="name" id="format"><span class="type-signature"></span>format<span cla

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="format.js.html">format.js</a>, <a href="format.js.html#line22">line 22</a>
<a href="format.js.html">format.js</a>, <a href="format.js.html#line40">line 40</a>
</li></ul></dd>


Expand Down Expand Up @@ -384,7 +384,7 @@ <h4 class="name" id="format"><span class="type-signature"></span>format<span cla

<h5>Example</h5>

<pre class="prettyprint"><code>format((NNN) NNN.NNNN', '444-555-6666') // => '(444) 555.6666'format('C + (NNN) NNN.NNNN', '1444-555-6666') // => '1 + (444) 555.6666'format('CC + NNN.NNN.NNNN', '163334445555') // => '16 + 333.444.5555'format('(NNN) NNN.NNNN x NNNN', '44455566668989') // => '(444) 555.6666 x 8989'// Format is case insensitiveformat('(NNN) nnn-NNnn', '4445556666') // => (444) 555-6666// Format is also curriedconst fn = format('NNN.NNN.NNNN')fn('4445556666') // => '444.555.6666'fn('(333) 444-5555') // => '333.444.5555'</code></pre>
<pre class="prettyprint"><code>format('(NNN) NNN.NNNN', '444-555-6666') // => '(444) 555.6666'format('C + (NNN) NNN.NNNN', '1444-555-6666') // => '1 + (444) 555.6666'format('CC + NNN.NNN.NNNN', '163334445555') // => '16 + 333.444.5555'format('(NNN) NNN.NNNN x NNNN', '44455566668989') // => '(444) 555.6666 x 8989'// Format is case insensitiveformat('(NNN) nnn-NNnn', '4445556666') // => (444) 555-6666// Format is also curriedconst fn = format('NNN.NNN.NNNN')fn('4445556666') // => '444.555.6666'fn('(333) 444-5555') // => '333.444.5555'</code></pre>



Expand Down Expand Up @@ -863,7 +863,7 @@ <h5>Returns:</h5>
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.1</a> using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>

<script>prettyPrint();</script>
Expand Down
33 changes: 24 additions & 9 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,34 +58,49 @@ <h2><a href="index.html">Home</a></h2><h2><a href="https://github.com/dhershman1


<section class="readme">
<article><p><a href="https://www.npmjs.com/package/phone-fns"><img src="https://img.shields.io/npm/v/phone-fns.svg?style=flat-square" alt="npm"></a><br><a href="https://david-dm.org/dhershman1/phone-fns"><img src="https://img.shields.io/david/dhershman1/phone-fns.svg?style=flat-square" alt="David"></a><br><a href="https://travis-ci.org/dhershman1/phone-fns"><img src="https://img.shields.io/travis/dhershman1/phone-fns.svg?style=flat-square" alt="Travis"></a><br><a href="https://coveralls.io/github/dhershman1/phone-fns?branch=master"><img src="https://img.shields.io/coveralls/github/dhershman1/phone-fns.svg?style=flat-square" alt="Coverage Status"></a></p>
<article><p><a href="https://www.npmjs.com/package/phone-fns"><img src="https://img.shields.io/npm/v/phone-fns.svg?style=flat-square" alt="npm"></a><br>
<a href="https://david-dm.org/dhershman1/phone-fns"><img src="https://img.shields.io/david/dhershman1/phone-fns.svg?style=flat-square" alt="David"></a><br>
<a href="https://circleci.com/gh/dhershman1/phone-fns"><img src="https://circleci.com/gh/dhershman1/phone-fns.svg?style=svg" alt="CircleCI"></a><br>
<a href="https://codecov.io/gh/dhershman1/phone-fns"><img src="https://codecov.io/gh/dhershman1/phone-fns/branch/master/graph/badge.svg" alt="codecov"></a></p>
<h1 id="phone-fns">Phone Fns</h1>
<p>A small modern, and functional phone number library which gathers inspiration from the fun <a href="https://github.com/date-fns/date-fns">date-fns</a> library</p>
<ul>
<li><a href="https://phone-fns.dusty.codes/">Documentation</a></li>
</ul>
<h2 id="how-to">How-To</h2>
<p><code>npm i phone-fns</code></p>
<pre class="prettyprint source lang-cli"><code>npm i phone-fns
</code></pre>
<p>Standard module system</p>
<pre class="prettyprint source lang-js"><code>import phoneFns from 'phone-fns'</code></pre><p>Common JS</p>
<pre class="prettyprint source lang-js"><code>const phoneFns = require('phone-fns')</code></pre><p>CDN</p>
<pre class="prettyprint source lang-js"><code>import phoneFns from 'phone-fns'
</code></pre>
<p>Common JS</p>
<pre class="prettyprint source lang-js"><code>const phoneFns = require('phone-fns')
</code></pre>
<p>CDN</p>
<pre class="prettyprint source lang-html"><code>&lt;!-- It is recommended to replace the @latest with a strict version number for production -->
&lt;script src=&quot;https://cdn.jsdelivr.net/npm/phone-fns@latest/dist/phone-fns.min.js&quot;>&lt;/script></code></pre><p>Through the browser</p>
<pre class="prettyprint source lang-html"><code>&lt;script src=&quot;path/to/location/dist/phone-fns.min.js&quot;>&lt;/script></code></pre><h2 id="usage">Usage</h2>
&lt;script src=&quot;https://cdn.jsdelivr.net/npm/phone-fns@latest/dist/phone-fns.min.js&quot;>&lt;/script>
</code></pre>
<p>Through the browser</p>
<pre class="prettyprint source lang-html"><code>&lt;script src=&quot;path/to/location/dist/phone-fns.min.js&quot;>&lt;/script>
</code></pre>
<h2 id="usage">Usage</h2>
<pre class="prettyprint source lang-javascript"><code>import phoneFns from 'phone-fns'

phoneFns.breakdown('4443332222')
// => { areaCode: '444', localCode: '333', lineNumber: '2222', extension: '' }

phoneFns.format('(NNN) NNN-NNNN', '4443332222')
// => '(444) 333-2222'</code></pre><p>You can also destructure to only use the functions you want</p>
// => '(444) 333-2222'
</code></pre>
<p>You can also destructure to only use the functions you want</p>
<pre class="prettyprint source lang-javascript"><code>import { breakdown, format } from 'phone-fns'

breakdown('4443332222')
// => { areaCode: '444', localCode: '333', lineNumber: '2222', extension: '' }

format('(NNN) NNN-NNNN', '4443332222')
// => '(444) 333-2222'</code></pre></article>
// => '(444) 333-2222'
</code></pre></article>
</section>


Expand All @@ -100,7 +115,7 @@ <h2 id="how-to">How-To</h2>
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.1</a> using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>

<script>prettyPrint();</script>
Expand Down
2 changes: 1 addition & 1 deletion docs/isValid.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ <h1 class="page-title">isValid.js</h1>
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.1</a> using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>

<script>prettyPrint();</script>
Expand Down
2 changes: 1 addition & 1 deletion docs/uglify.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ <h1 class="page-title">uglify.js</h1>
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.1</a> using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>

<script>prettyPrint();</script>
Expand Down
Loading

0 comments on commit fc11d86

Please sign in to comment.