Socket
Socket
Sign inDemoInstall

phone-fns

Package Overview
Dependencies
1
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.0.0 to 3.1.0

src/_internals/_curry2.js

12

CHANGELOG.md
# 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

@@ -4,0 +16,0 @@

50

dist/phone-fns.js
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('kyanite')) :
typeof define === 'function' && define.amd ? define(['exports', 'kyanite'], factory) :
(factory((global.phoneFns = {}),global.kyanite));
}(this, (function (exports,kyanite) { 'use strict';
(global = global || self, factory(global.phoneFns = {}, global.kyanite));
}(this, function (exports, kyanite) { 'use strict';

@@ -63,2 +63,16 @@ function _slicedToArray(arr, i) {

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) {

@@ -79,23 +93,19 @@ var uglyPhone = uglify(phone);

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);

@@ -109,2 +119,2 @@ exports.breakdown = breakdown;

})));
}));

2

dist/phone-fns.min.js

@@ -1,1 +0,1 @@

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("kyanite")):"function"==typeof define&&define.amd?define(["exports","kyanite"],t):t(e.phoneFns={},e.kyanite)}(this,function(e,t){"use strict";function r(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r=[],n=!0,o=!1,i=void 0;try{for(var u,a=e[Symbol.iterator]();!(n=(u=a.next()).done)&&(r.push(u.value),!t||r.length!==t);n=!0);}catch(e){o=!0,i=e}finally{try{n||null==a.return||a.return()}finally{if(o)throw i}}return r}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}var n=t.compose(t.replace(/[a-z]\w?|\W/gi,""),String),o=function(e){var t=r(n(e).match(/([0-9]{3})?([0-9]{3})([0-9]{4})([0-9]{1,})?/),5),o=t[1],i=t[2],u=t[3],a=t[4];return{areaCode:o,localCode:i,lineNumber:u,extension:void 0===a?"":a}},i=function(e){var r=n(e);if(t.or(t.isEmpty(r),t.length(r))<7)return!1;var i=o(r),u=i.areaCode,a=i.localCode,c=i.lineNumber;return t.compose(t.eq(7),t.length,r)?/^([0-9]{3})[-. ]?([0-9]{4})$/.test(a+c):/^\+?([0-9]{2})\)?[-. ]?([0-9]{4})[-. ]?([0-9]{4})$/.test(u+a+c)},u=t.curry(function(e,r){var o=t.compose(t.split(""),n,r),u=t.includes("C",e)?t.length(e.match(/C/g)):0;return t.or(!i(r),!function(e,r){var o=t.compose(t.countBy(t.toUpper),t.split(""),e),i=o.N,u=o.C,a=void 0===u?0:u;return t.pipe([n,t.length,t.eq(t.add(i,a))],r)}(e,r))?r:o.reduce(function(e,r,n){return t.gt(n,u)?e.replace(/C/i,r):e.replace(/N/i,r)},e)});e.breakdown=o,e.format=u,e.isValid=i,e.uglify=n,Object.defineProperty(e,"__esModule",{value:!0})});
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("kyanite")):"function"==typeof define&&define.amd?define(["exports","kyanite"],t):t((e=e||self).phoneFns={},e.kyanite)}(this,function(e,t){"use strict";function n(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=[],r=!0,o=!1,i=void 0;try{for(var u,a=e[Symbol.iterator]();!(r=(u=a.next()).done)&&(n.push(u.value),!t||n.length!==t);r=!0);}catch(e){o=!0,i=e}finally{try{r||null==a.return||a.return()}finally{if(o)throw i}}return n}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}var r=t.compose(t.replace(/[a-z]\w?|\W/gi,""),String),o=function(e){var t=n(r(e).match(/([0-9]{3})?([0-9]{3})([0-9]{4})([0-9]{1,})?/),5),o=t[1],i=t[2],u=t[3],a=t[4];return{areaCode:o,localCode:i,lineNumber:u,extension:void 0===a?"":a}};var i,u=function(e){var n=r(e);if(t.or(t.isEmpty(n),t.length(n))<7)return!1;var i=o(n),u=i.areaCode,a=i.localCode,c=i.lineNumber;return t.compose(t.eq(7),t.length,n)?/^([0-9]{3})[-. ]?([0-9]{4})$/.test(a+c):/^\+?([0-9]{2})\)?[-. ]?([0-9]{4})[-. ]?([0-9]{4})$/.test(u+a+c)},a=(i=function(e,n){var o=t.includes("C",e)?t.length(e.match(/C/g)):0,i=t.addIndex(t.reduce);return t.branch(t.both(t.complement(u),t.complement(function(e){return function(n){var o=t.compose(t.countBy(t.toUpper),t.split(""),e),i=o.N,u=o.C,a=void 0===u?0:u;return t.pipe([r,t.length,t.eq(t.add(i,a))],n)}}(e))),t.identity,t.pipe([t.split(""),r,i(function(e,n,r){return t.gt(r,o)?t.replace(/C/i,e,n):t.replace(/N/i,e,n)},e)]),n)},function e(t,n){return arguments.length?1===arguments.length?function(e){return i(t,e)}:i(t,n):e});e.breakdown=o,e.format=a,e.isValid=u,e.uglify=r,Object.defineProperty(e,"__esModule",{value:!0})});
{
"name": "phone-fns",
"version": "3.0.0",
"version": "3.1.0",
"description": "A small, modern, and functional phone library for javascript",

@@ -8,7 +8,2 @@ "main": "dist/phone-fns.min.js",

"typings": "types/index.d.ts",
"files": [
"dist",
"src",
"types"
],
"scripts": {

@@ -19,7 +14,7 @@ "prepack": "npm run scripts && rollup -c",

"build": "rollup -c",
"postpublish": "node scripts/clean.js",
"lint": "standard src/**/*.js",
"test": "tape -r esm tests/*.js | tap-spec",
"test:cov": "nyc npm test",
"coverage": "nyc report --reporter=text-lcov | coveralls"
"check-cov": "nyc check-coverage --lines 90 --functions 100 --branches 90",
"report": "nyc report --reporter=text-lcov > coverage.lcov"
},

@@ -64,23 +59,22 @@ "nyc": {

"devDependencies": {
"@babel/core": "7.1.2",
"@babel/preset-env": "7.1.0",
"@babel/core": "7.4.4",
"@babel/preset-env": "7.4.4",
"@killparadise/docdash": "github:dhershman1/docdash",
"coveralls": "3.0.2",
"esm": "3.0.84",
"globby": "8.0.1",
"jsdoc": "3.5.5",
"esm": "3.2.22",
"globby": "9.2.0",
"jsdoc": "3.6.1",
"jsdoc-to-markdown": "4.0.1",
"nyc": "13.0.1",
"rollup": "0.66.6",
"rollup-plugin-babel": "4.0.3",
"rollup-plugin-cleanup": "3.0.0",
"rollup-plugin-filesize": "4.0.1",
"rollup-plugin-terser": "3.0.0",
"nyc": "14.1.0",
"rollup": "1.11.3",
"rollup-plugin-babel": "4.3.2",
"rollup-plugin-cleanup": "3.1.1",
"rollup-plugin-filesize": "6.0.1",
"rollup-plugin-terser": "4.0.4",
"standard": "12.0.1",
"tap-spec": "5.0.0",
"tape": "4.9.1"
"tape": "4.10.1"
},
"dependencies": {
"kyanite": "0.10.1"
"kyanite": "0.12.2"
}
}
[![npm](https://img.shields.io/npm/v/phone-fns.svg?style=flat-square)](https://www.npmjs.com/package/phone-fns)
[![David](https://img.shields.io/david/dhershman1/phone-fns.svg?style=flat-square)](https://david-dm.org/dhershman1/phone-fns)
[![Travis](https://img.shields.io/travis/dhershman1/phone-fns.svg?style=flat-square)](https://travis-ci.org/dhershman1/phone-fns)
[![Coverage Status](https://img.shields.io/coveralls/github/dhershman1/phone-fns.svg?style=flat-square)](https://coveralls.io/github/dhershman1/phone-fns?branch=master)
[![CircleCI](https://circleci.com/gh/dhershman1/phone-fns.svg?style=svg)](https://circleci.com/gh/dhershman1/phone-fns)
[![codecov](https://codecov.io/gh/dhershman1/phone-fns/branch/master/graph/badge.svg)](https://codecov.io/gh/dhershman1/phone-fns)

@@ -14,3 +14,5 @@ # Phone Fns

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

@@ -17,0 +19,0 @@ Standard module system

@@ -1,3 +0,21 @@

import { add, compose, curry, gt, eq, includes, length, or, pipe, countBy, split, toUpper } from 'kyanite'
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'

@@ -12,3 +30,3 @@ import uglify from './uglify'

*/
const validFormat = (layout, phone) => {
const validFormat = layout => phone => {
const { N, C = 0 } = compose(countBy(toUpper), split(''), layout)

@@ -35,3 +53,3 @@

* @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'

@@ -51,18 +69,20 @@ * format('CC + NNN.NNN.NNNN', '163334445555') // => '16 + 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)
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc