Socket
Socket
Sign inDemoInstall

phone-fns

Package Overview
Dependencies
0
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.1 to 2.0.0

tests/breakdown.js

2

breakdown.js

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

!function(n,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):n.breakdown=e()}(this,function(){"use strict";function n(n,e){return function(n){if(Array.isArray(n))return n}(n)||function(n,e){var r=[],t=!0,o=!1,i=void 0;try{for(var u,a=n[Symbol.iterator]();!(t=(u=a.next()).done)&&(r.push(u.value),!e||r.length!==e);t=!0);}catch(n){o=!0,i=n}finally{try{t||null==a.return||a.return()}finally{if(o)throw i}}return r}(n,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}return function n(e){for(var r=arguments.length,t=new Array(r>1?r-1:0),o=1;o<r;o++)t[o-1]=arguments[o];return e.length<=t.length?e.apply(void 0,t):function(){for(var r=arguments.length,o=new Array(r),i=0;i<r;i++)o[i]=arguments[i];return n.apply(void 0,[e].concat(t,o))}}(function(e,r){var t=n(function(n){return n.replace(/[a-z]\w?|\W/gi,"")}(r).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{countryCode:e,areaCode:o,localCode:i,lineNumber:u,extension:void 0===a?"":a}})});
!function(n,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):n.breakdown=e()}(this,function(){"use strict";function f(n,e){return function(n){if(Array.isArray(n))return n}(n)||function(n,e){var r=[],t=!0,o=!1,i=void 0;try{for(var u,a=n[Symbol.iterator]();!(t=(u=a.next()).done)&&(r.push(u.value),!e||r.length!==e);t=!0);}catch(n){o=!0,i=n}finally{try{t||null==a.return||a.return()}finally{if(o)throw i}}return r}(n,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}return function t(o){for(var n=arguments.length,i=new Array(1<n?n-1:0),e=1;e<n;e++)i[e-1]=arguments[e];return o.length<=i.length?o.apply(void 0,i):function(){for(var n=arguments.length,e=new Array(n),r=0;r<n;r++)e[r]=arguments[r];return t.apply(void 0,[o].concat(i,e))}}(function(n,e){var r,t=f((r=e,r.replace(/[a-z]\w?|\W/gi,"")).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{countryCode:n,areaCode:o,localCode:i,lineNumber:u,extension:void 0===a?"":a}})});
# Changelog
## v2.0.0
### BREAKING CHANGES
- The API usage for `format` is now different, you only need to use the letter `N` in your layout now in the order you want the numbers to fill in
- The letter `N` is case insensitive
- Example: an old layout may have looked like: `(AAA) LLL-NNNN` now it is: `(NNN) NNN-NNNN` or `(nnn) nnn-nnNN` if you wanted to get creative
### New
- `find` has been deprecated and may be removed in later versions, please transition to `breakdown`
- Added a 2nd validation level to `format` it will now validate the phone number has enough digits to fill out the layout properly
- You can now pass country code as a number or string
### Fixed
- JSdocs for format were backwards
- Able to properly handle numbers without an area code now
## v1.0.1

@@ -4,0 +23,0 @@

@@ -61,3 +61,3 @@ (function (global, factory) {

var breakdown = curry(function (countryCode, phone) {
var breakdown = function breakdown(countryCode, phone) {
var _uglify$match = uglify(phone).match(/([0-9]{3})?([0-9]{3})([0-9]{4})([0-9]{1,})?/),

@@ -77,50 +77,48 @@ _uglify$match2 = _slicedToArray(_uglify$match, 5),

};
});
};
var breakdown$1 = curry(breakdown);
var find = curry(function (type, phone) {
return breakdown('', phone)[type];
});
var find = function find(type, phone) {
return breakdown$1('', phone)[type];
};
var find$1 = curry(find);
var isValid = (function (phone) {
var uglyPhone = uglify(phone);
if (!phone || uglyPhone.length < 10) {
if (!phone || uglyPhone.length < 7) {
return false;
}
var _breakdown = breakdown('', uglyPhone),
var _breakdown = breakdown$1('', uglyPhone),
areaCode = _breakdown.areaCode,
localCode = _breakdown.localCode,
lineNumber = _breakdown.lineNumber;
return phone && /^\+?([0-9]{2})\)?[-. ]?([0-9]{4})[-. ]?([0-9]{4})$/.test(areaCode + localCode + lineNumber);
if (uglyPhone.length === 7) {
return /^([0-9]{3})[-. ]?([0-9]{4})$/.test(localCode + lineNumber);
}
return /^\+?([0-9]{2})\)?[-. ]?([0-9]{4})[-. ]?([0-9]{4})$/.test(areaCode + localCode + lineNumber);
});
var replaceLayout = function replaceLayout(layout, num, type) {
var letters = {
areaCode: 'A',
localCode: 'L',
lineNumber: 'N',
extension: 'E',
countryCode: 'C'
};
var results = layout.concat();
num.split('').forEach(function (n) {
results = results.replace(letters[type], n);
});
return results;
var validFormat = function validFormat(phone, layout) {
var count = layout.split('').reduce(function (acc, v) {
if (v.toLowerCase() === 'n') {
acc++;
}
return acc;
}, 0);
return count === phone.length;
};
var format = curry(function (countryCode, layout, phone) {
if (!isValid(phone)) {
var format = function format(cc, layout, phone) {
var fullPhone = "".concat(cc).concat(uglify(phone));
if (!isValid(phone) || !validFormat(fullPhone, layout)) {
return phone;
}
var uglyPhone = uglify(phone);
var phoneObj = breakdown(countryCode, uglyPhone);
var results = layout;
for (var prop in phoneObj) {
if (phoneObj[prop]) {
results = replaceLayout(results, phoneObj[prop], prop);
}
}
var results = fullPhone.split('').reduce(function (acc, d) {
var temp = acc.replace(/N/i, d);
return temp;
}, layout);
return results;
});
};
var format$1 = curry(format);
var match = curry(function (x, y) {
var match = function match(x, y) {
if (!isValid(x) || !isValid(y)) {

@@ -130,15 +128,17 @@ return false;

return uglify(x) === uglify(y);
});
};
var match$1 = curry(match);
var phoneFns = function phoneFns() {
var countryCode = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
if (typeof countryCode !== 'string') {
throw new TypeError('Country Code needs to be a string');
if (typeof countryCode !== 'string' && typeof countryCode !== 'number') {
throw new TypeError('Country Code needs to be a string or number');
}
var ccStr = String(countryCode);
return {
breakdown: breakdown(countryCode),
format: format(countryCode),
find: find(countryCode),
breakdown: breakdown$1(ccStr),
format: format$1(ccStr),
find: find$1(ccStr),
isValid: isValid,
match: match,
match: match$1,
uglify: uglify

@@ -145,0 +145,0 @@ };

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

!function(n,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):n.phoneFns=r()}(this,function(){"use strict";function n(n,r){return function(n){if(Array.isArray(n))return n}(n)||function(n,r){var e=[],t=!0,o=!1,i=void 0;try{for(var u,a=n[Symbol.iterator]();!(t=(u=a.next()).done)&&(e.push(u.value),!r||e.length!==r);t=!0);}catch(n){o=!0,i=n}finally{try{t||null==a.return||a.return()}finally{if(o)throw i}}return e}(n,r)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}var r=function n(r){for(var e=arguments.length,t=new Array(e>1?e-1:0),o=1;o<e;o++)t[o-1]=arguments[o];return r.length<=t.length?r.apply(void 0,t):function(){for(var e=arguments.length,o=new Array(e),i=0;i<e;i++)o[i]=arguments[i];return n.apply(void 0,[r].concat(t,o))}},e=function(n){return n.replace(/[a-z]\w?|\W/gi,"")},t=r(function(r,t){var o=n(e(t).match(/([0-9]{3})?([0-9]{3})([0-9]{4})([0-9]{1,})?/),5),i=o[1],u=o[2],a=o[3],f=o[4];return{countryCode:r,areaCode:i,localCode:u,lineNumber:a,extension:void 0===f?"":f}}),o=r(function(n,r){return t("",r)[n]}),i=function(n){var r=e(n);if(!n||r.length<10)return!1;var o=t("",r),i=o.areaCode,u=o.localCode,a=o.lineNumber;return n&&/^\+?([0-9]{2})\)?[-. ]?([0-9]{4})[-. ]?([0-9]{4})$/.test(i+u+a)},u=function(n,r,e){var t={areaCode:"A",localCode:"L",lineNumber:"N",extension:"E",countryCode:"C"},o=n.concat();return r.split("").forEach(function(n){o=o.replace(t[e],n)}),o},a=r(function(n,r,o){if(!i(o))return o;var a=e(o),f=t(n,a),c=r;for(var l in f)f[l]&&(c=u(c,f[l],l));return c}),f=r(function(n,r){return!(!i(n)||!i(r))&&e(n)===e(r)});return function(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";if("string"!=typeof n)throw new TypeError("Country Code needs to be a string");return{breakdown:t(n),format:a(n),find:o(n),isValid:i,match:f,uglify:e}}});
!function(n,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):n.phoneFns=r()}(this,function(){"use strict";function a(n,r){return function(n){if(Array.isArray(n))return n}(n)||function(n,r){var e=[],t=!0,o=!1,i=void 0;try{for(var u,a=n[Symbol.iterator]();!(t=(u=a.next()).done)&&(e.push(u.value),!r||e.length!==r);t=!0);}catch(n){o=!0,i=n}finally{try{t||null==a.return||a.return()}finally{if(o)throw i}}return e}(n,r)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}var n=function t(o){for(var n=arguments.length,i=new Array(1<n?n-1:0),r=1;r<n;r++)i[r-1]=arguments[r];return o.length<=i.length?o.apply(void 0,i):function(){for(var n=arguments.length,r=new Array(n),e=0;e<n;e++)r[e]=arguments[e];return t.apply(void 0,[o].concat(i,r))}},c=function(n){return n.replace(/[a-z]\w?|\W/gi,"")},u=n(function(n,r){var e=a(c(r).match(/([0-9]{3})?([0-9]{3})([0-9]{4})([0-9]{1,})?/),5),t=e[1],o=e[2],i=e[3],u=e[4];return{countryCode:n,areaCode:t,localCode:o,lineNumber:i,extension:void 0===u?"":u}}),e=n(function(n,r){return u("",r)[n]}),i=function(n){var r=c(n);if(!n||r.length<7)return!1;var e=u("",r),t=e.areaCode,o=e.localCode,i=e.lineNumber;return 7===r.length?/^([0-9]{3})[-. ]?([0-9]{4})$/.test(o+i):/^\+?([0-9]{2})\)?[-. ]?([0-9]{4})[-. ]?([0-9]{4})$/.test(t+o+i)},t=n(function(n,r,e){var t,o="".concat(n).concat(c(e));return i(e)&&(t=o,r.split("").reduce(function(n,r){return"n"===r.toLowerCase()&&n++,n},0)===t.length)?o.split("").reduce(function(n,r){return n.replace(/N/i,r)},r):e}),o=n(function(n,r){return!(!i(n)||!i(r))&&c(n)===c(r)});return function(){var n=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"";if("string"!=typeof n&&"number"!=typeof n)throw new TypeError("Country Code needs to be a string or number");var r=String(n);return{breakdown:u(r),format:t(r),find:e(r),isValid:i,match:o,uglify:c}}});

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

module.exports = [{"since":"v0.1.0","category":"Function","title":"breakdown","desc":"Takes a provided phone string and breaks it down into an object of codes","examples":["breakdown('', '111-222-3333');\r// => { countryCode: '', areaCode: '111', localCode: '222', lineNumber: '3333', extension: '' }\r\rbreakdown('1787', '5554441111');\r// => { countryCode: 1787, areaCode: '555', localCode: '444', lineNumber: '1111', extension: '' }\r\rbreakdown('', '555-444-3333 x 8989');\r// => { countryCode: '', areaCode: '555', localCode: '444', lineNumber: '3333', extension: 8989 }\r\r// Breakdown is curried\rconst breaker = breakdown('');\r\rbreaker('222-333-4444'); // => { areaCode: '222', localCode: '333', lineNumber: '4444' }"],"returns":[{"type":{"names":["Object"]},"description":"Returns an object of the broken down phone number"}],"params":[{"type":{"names":["String"]},"description":"The provided country code for the number","name":"countryCode"},{"type":{"names":["String"]},"description":"The phone number to breakdown","name":"phone"}],"syntax":"breakdown(countryCode, phone)","usage":{"commonjs":{"title":"CommonJs","code":"const breakdown = require('phone-fns/breakdown');"},"standard":{"title":"Standard","code":"import breakdown from 'phone-fns/breakdown';"},"cdn":{"title":"CDN","code":"<script src=\"https://cdn.jsdelivr.net/npm/phone-fns@1.0.1/breakdown.js\"></script>"},"browser":{"title":"Browser","code":"<script src=\"path/to/node_modules/phone-fns/breakdown.js\"></script>"}}},{"since":"v0.1.0","category":"Function","title":"find","desc":"Find a piece of the phone number and return it","examples":["find('areaCode', '555-444-1111'); // => '555'\rfind('localCode', '555-444-1111'); // => '444'\rfind('lineNumber', '555-444-1111'); // => '1111'\rfind('countryCode', '1555-444-1111'); // => '1'\rfind('extension', '555-444-1111 8989'); // => '8989'\r\r// find is also curried\r\rconst finder = find('areaCode');\r\rfinder('555-444-1111'); // => '555'"],"returns":[{"type":{"names":["String"]},"description":"Returns a string from the desired part of the phone number"}],"params":[{"type":{"names":["String"]},"description":"The phone number to breakdown","name":"phone"},{"type":{"names":["String"]},"description":"The piece of the phone to look for","name":"type"}],"syntax":"find(phone, type)","usage":{"commonjs":{"title":"CommonJs","code":"const find = require('phone-fns/find');"},"standard":{"title":"Standard","code":"import find from 'phone-fns/find';"},"cdn":{"title":"CDN","code":"<script src=\"https://cdn.jsdelivr.net/npm/phone-fns@1.0.1/find.js\"></script>"},"browser":{"title":"Browser","code":"<script src=\"path/to/node_modules/phone-fns/find.js\"></script>"}}},{"since":"v0.1.0","category":"Function","title":"format","desc":"Allows you to format phone numbers however you desire\rL = Local Code\rA = Area Code\rN = Line Number\rE = Extension\rC = Country Code","examples":["format('444-555-6666', '(AAA) LLL.NNNN'); // => '(444) 555.6666'\rformat('1444-555-6666', 'C + (AAA) LLL.NNNN', true); // => '1 + (444) 555.6666'\rformat('444-555-66668989', '(AAA) LLL.NNNN x EEEE'); // => '(444) 555.6666 x 8989'\r\r// Format is also curried\rconst noCC = format('');\rconst withLayout = format('', 'AAA.LLL.NNNN');\r\rnoCC('AAA-LLL-NNNN', '4445556666'); // => '444-555-6666'\rwithLayout('4445556666'); // => '444.555.6666'"],"returns":[{"type":{"names":["String"]},"description":"Returns a string which is the formatted phone number"}],"params":[{"type":{"names":["String"]},"description":"The provided country code for the number","name":"countryCode"},{"type":{"names":["String"]},"description":"The desired layout of the phone number","name":"layout"},{"type":{"names":["String"]},"description":"The phone number to breakdown","name":"phone"}],"syntax":"format(countryCode, layout, phone)","usage":{"commonjs":{"title":"CommonJs","code":"const format = require('phone-fns/format');"},"standard":{"title":"Standard","code":"import format from 'phone-fns/format';"},"cdn":{"title":"CDN","code":"<script src=\"https://cdn.jsdelivr.net/npm/phone-fns@1.0.1/format.js\"></script>"},"browser":{"title":"Browser","code":"<script src=\"path/to/node_modules/phone-fns/format.js\"></script>"}}},{"since":"v0.1.0","category":"Function","title":"isValid","desc":"Validates the base number, does not take the country code or extension into consideration for this validation","examples":["isValid('555-444-3333'); // => true"],"returns":[{"type":{"names":["Boolean"]},"description":"Returns a boolean if the number provided is valid or not\rphone && (/^\\+?([0-9]{2})\\)?[-. ]?([0-9]{4})[-. ]?([0-9]{4})$/).test(uglify(phone));"}],"params":[{"type":{"names":["String"]},"description":"The phone number to breakdown","name":"phone"},{"type":{"names":["String"]},"description":"The country name to validate with","name":"country"}],"syntax":"isValid(phone, country)","usage":{"commonjs":{"title":"CommonJs","code":"const isValid = require('phone-fns/isValid');"},"standard":{"title":"Standard","code":"import isValid from 'phone-fns/isValid';"},"cdn":{"title":"CDN","code":"<script src=\"https://cdn.jsdelivr.net/npm/phone-fns@1.0.1/isValid.js\"></script>"},"browser":{"title":"Browser","code":"<script src=\"path/to/node_modules/phone-fns/isValid.js\"></script>"}}},{"since":"v1.0.0","category":"Function","title":"match","desc":"Checks if the two provided numbers are matching or not","examples":["match('5554443333', '5554443333'); // => true\rmatch('5554443333', '555-444-3333'); // => true\rmatch('555-444-3333', '555-444-3333'); // => true\rmatch('555.444.3333', '555-444-3333'); // => true\r\r// Or use it as a curried function\r\rconst matcher = match('5554443333');\r\rmatcher('555-444-3333'); // => true\rmatcher('555.444.3333'); // => true\rmatcher('555.444.2222'); // => false"],"returns":[{"type":{"names":["Boolean"]},"description":"Returns a boolean if the numbers provided to match"}],"params":[{"type":{"names":["String"]},"description":"The number to validate against","name":"x"},{"type":{"names":["String"]},"description":"The number to validate","name":"y"}],"syntax":"match(x, y)","usage":{"commonjs":{"title":"CommonJs","code":"const match = require('phone-fns/match');"},"standard":{"title":"Standard","code":"import match from 'phone-fns/match';"},"cdn":{"title":"CDN","code":"<script src=\"https://cdn.jsdelivr.net/npm/phone-fns@1.0.1/match.js\"></script>"},"browser":{"title":"Browser","code":"<script src=\"path/to/node_modules/phone-fns/match.js\"></script>"}}},{"since":"v0.1.0","category":"Function","title":"uglify","desc":"Strips all of the special characters from the given string","examples":["const results = uglify('555-444-3333'); // => '5554443333'"],"returns":[{"type":{"names":["String"]},"description":"Returns the newly created phone number string"}],"params":[{"type":{"names":["String"]},"description":"The phone number to trim and strip down","name":"phone"}],"syntax":"uglify(phone)","usage":{"commonjs":{"title":"CommonJs","code":"const uglify = require('phone-fns/uglify');"},"standard":{"title":"Standard","code":"import uglify from 'phone-fns/uglify';"},"cdn":{"title":"CDN","code":"<script src=\"https://cdn.jsdelivr.net/npm/phone-fns@1.0.1/uglify.js\"></script>"},"browser":{"title":"Browser","code":"<script src=\"path/to/node_modules/phone-fns/uglify.js\"></script>"}}}]
module.exports = [{"since":"v0.1.0","deprecated":false,"category":"Function","title":"breakdown","desc":"Takes a provided phone string and breaks it down into an object of codes","examples":["breakdown('', '111-222-3333');\r// => { countryCode: '', areaCode: '111', localCode: '222', lineNumber: '3333', extension: '' }\r\rbreakdown('1787', '5554441111');\r// => { countryCode: 1787, areaCode: '555', localCode: '444', lineNumber: '1111', extension: '' }\r\rbreakdown('', '555-444-3333 x 8989');\r// => { countryCode: '', areaCode: '555', localCode: '444', lineNumber: '3333', extension: 8989 }\r\r// Breakdown is curried\rconst breaker = breakdown('');\r\rbreaker('222-333-4444'); // => { areaCode: '222', localCode: '333', lineNumber: '4444' }"],"returns":[{"type":{"names":["Object"]},"description":"Returns an object of the broken down phone number"}],"params":[{"type":{"names":["String"]},"description":"The provided country code for the number","name":"countryCode"},{"type":{"names":["String"]},"description":"The phone number to breakdown","name":"phone"}],"syntax":"breakdown(countryCode, phone)","usage":{"commonjs":{"title":"CommonJs","code":"const breakdown = require('phone-fns/breakdown');"},"standard":{"title":"Standard","code":"import breakdown from 'phone-fns/breakdown';"},"cdn":{"title":"CDN","code":"<script src=\"https://cdn.jsdelivr.net/npm/phone-fns@2.0.0/breakdown.js\"></script>"},"browser":{"title":"Browser","code":"<script src=\"path/to/node_modules/phone-fns/breakdown.js\"></script>"}}},{"since":"v0.1.0","deprecated":"The use case for this method is too low to keep it, use breakdown instead","category":"Function","title":"find","desc":"Find a piece of the phone number and return it","examples":["find('areaCode', '555-444-1111'); // => '555'\rfind('localCode', '555-444-1111'); // => '444'\rfind('lineNumber', '555-444-1111'); // => '1111'\rfind('extension', '555-444-1111 8989'); // => '8989'\r\r// find is also curried\r\rconst finder = find('areaCode');\r\rfinder('555-444-1111'); // => '555'"],"returns":[{"type":{"names":["String"]},"description":"Returns a string from the desired part of the phone number"}],"params":[{"type":{"names":["String"]},"description":"The piece of the phone to look for","name":"type"},{"type":{"names":["String"]},"description":"The phone number to breakdown","name":"phone"}],"syntax":"find(type, phone)","usage":{"commonjs":{"title":"CommonJs","code":"const find = require('phone-fns/find');"},"standard":{"title":"Standard","code":"import find from 'phone-fns/find';"},"cdn":{"title":"CDN","code":"<script src=\"https://cdn.jsdelivr.net/npm/phone-fns@2.0.0/find.js\"></script>"},"browser":{"title":"Browser","code":"<script src=\"path/to/node_modules/phone-fns/find.js\"></script>"}}},{"since":"v0.1.0","deprecated":false,"category":"Function","title":"format","desc":"Allows you to format phone numbers however you desire using N as number placeholders this placeholder is case insensitive","examples":["format('', '(NNN) NNN.NNNN', '444-555-6666'); // => '(444) 555.6666'\rformat('1', 'N + (NNN) NNN.NNNN', '444-555-6666'); // => '1 + (444) 555.6666'\rformat('', '(NNN) NNN.NNNN x NNNN', '444-555-66668989'); // => '(444) 555.6666 x 8989'\r\r// Format is case insensitive\rformat('', '(NNN) nnn-NNnn', '4445556666') // => (444) 555-6666\r\r// Format is also curried\rconst noCC = format('');\rconst withLayout = format('', 'NNN.NNN.NNNN');\r\rnoCC('NNN-NNN-NNNN', '4445556666'); // => '444-555-6666'\rwithLayout('4445556666'); // => '444.555.6666'"],"returns":[{"type":{"names":["String"]},"description":"Returns a string which is the formatted phone number"}],"params":[{"type":{"names":["String"]},"description":"The provided country code for the number or an empty string if none provided","name":"cc"},{"type":{"names":["String"]},"description":"The desired layout of the phone number","name":"layout"},{"type":{"names":["String"]},"description":"The phone number to breakdown","name":"phone"}],"syntax":"format(cc, layout, phone)","usage":{"commonjs":{"title":"CommonJs","code":"const format = require('phone-fns/format');"},"standard":{"title":"Standard","code":"import format from 'phone-fns/format';"},"cdn":{"title":"CDN","code":"<script src=\"https://cdn.jsdelivr.net/npm/phone-fns@2.0.0/format.js\"></script>"},"browser":{"title":"Browser","code":"<script src=\"path/to/node_modules/phone-fns/format.js\"></script>"}}},{"since":"v0.1.0","deprecated":false,"category":"Function","title":"isValid","desc":"Validates the base number, does not take the country code or extension into consideration for this validation","examples":["isValid('555-444-3333'); // => true"],"returns":[{"type":{"names":["Boolean"]},"description":"Returns a boolean if the number provided is valid or not"}],"params":[{"type":{"names":["String"]},"description":"The phone number to breakdown","name":"phone"}],"syntax":"isValid(phone)","usage":{"commonjs":{"title":"CommonJs","code":"const isValid = require('phone-fns/isValid');"},"standard":{"title":"Standard","code":"import isValid from 'phone-fns/isValid';"},"cdn":{"title":"CDN","code":"<script src=\"https://cdn.jsdelivr.net/npm/phone-fns@2.0.0/isValid.js\"></script>"},"browser":{"title":"Browser","code":"<script src=\"path/to/node_modules/phone-fns/isValid.js\"></script>"}}},{"since":"v1.0.0","deprecated":false,"category":"Function","title":"match","desc":"Checks if the two provided numbers are matching or not","examples":["match('5554443333', '5554443333'); // => true\rmatch('5554443333', '555-444-3333'); // => true\rmatch('555-444-3333', '555-444-3333'); // => true\rmatch('555.444.3333', '555-444-3333'); // => true\r\r// Or use it as a curried function\r\rconst matcher = match('5554443333');\r\rmatcher('555-444-3333'); // => true\rmatcher('555.444.3333'); // => true\rmatcher('555.444.2222'); // => false"],"returns":[{"type":{"names":["Boolean"]},"description":"Returns a boolean if the numbers provided to match"}],"params":[{"type":{"names":["String"]},"description":"The number to validate against","name":"x"},{"type":{"names":["String"]},"description":"The number to validate","name":"y"}],"syntax":"match(x, y)","usage":{"commonjs":{"title":"CommonJs","code":"const match = require('phone-fns/match');"},"standard":{"title":"Standard","code":"import match from 'phone-fns/match';"},"cdn":{"title":"CDN","code":"<script src=\"https://cdn.jsdelivr.net/npm/phone-fns@2.0.0/match.js\"></script>"},"browser":{"title":"Browser","code":"<script src=\"path/to/node_modules/phone-fns/match.js\"></script>"}}},{"since":"v0.1.0","deprecated":false,"category":"Function","title":"uglify","desc":"Strips all of the special characters from the given string","examples":["const results = uglify('555-444-3333'); // => '5554443333'"],"returns":[{"type":{"names":["String"]},"description":"Returns the newly created phone number string"}],"params":[{"type":{"names":["String"]},"description":"The phone number to trim and strip down","name":"phone"}],"syntax":"uglify(phone)","usage":{"commonjs":{"title":"CommonJs","code":"const uglify = require('phone-fns/uglify');"},"standard":{"title":"Standard","code":"import uglify from 'phone-fns/uglify';"},"cdn":{"title":"CDN","code":"<script src=\"https://cdn.jsdelivr.net/npm/phone-fns@2.0.0/uglify.js\"></script>"},"browser":{"title":"Browser","code":"<script src=\"path/to/node_modules/phone-fns/uglify.js\"></script>"}}}]

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

!function(n,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):n.find=r()}(this,function(){"use strict";function n(n,r){return function(n){if(Array.isArray(n))return n}(n)||function(n,r){var e=[],t=!0,o=!1,i=void 0;try{for(var u,a=n[Symbol.iterator]();!(t=(u=a.next()).done)&&(e.push(u.value),!r||e.length!==r);t=!0);}catch(n){o=!0,i=n}finally{try{t||null==a.return||a.return()}finally{if(o)throw i}}return e}(n,r)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}var r=function n(r){for(var e=arguments.length,t=new Array(e>1?e-1:0),o=1;o<e;o++)t[o-1]=arguments[o];return r.length<=t.length?r.apply(void 0,t):function(){for(var e=arguments.length,o=new Array(e),i=0;i<e;i++)o[i]=arguments[i];return n.apply(void 0,[r].concat(t,o))}},e=r(function(r,e){var t=n(function(n){return n.replace(/[a-z]\w?|\W/gi,"")}(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{countryCode:r,areaCode:o,localCode:i,lineNumber:u,extension:void 0===a?"":a}});return r(function(n,r){return e("",r)[n]})});
!function(n,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):n.find=e()}(this,function(){"use strict";function f(n,e){return function(n){if(Array.isArray(n))return n}(n)||function(n,e){var r=[],t=!0,o=!1,i=void 0;try{for(var u,a=n[Symbol.iterator]();!(t=(u=a.next()).done)&&(r.push(u.value),!e||r.length!==e);t=!0);}catch(n){o=!0,i=n}finally{try{t||null==a.return||a.return()}finally{if(o)throw i}}return r}(n,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}var n=function t(o){for(var n=arguments.length,i=new Array(1<n?n-1:0),e=1;e<n;e++)i[e-1]=arguments[e];return o.length<=i.length?o.apply(void 0,i):function(){for(var n=arguments.length,e=new Array(n),r=0;r<n;r++)e[r]=arguments[r];return t.apply(void 0,[o].concat(i,e))}},r=n(function(n,e){var r,t=f((r=e,r.replace(/[a-z]\w?|\W/gi,"")).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{countryCode:n,areaCode:o,localCode:i,lineNumber:u,extension:void 0===a?"":a}});return n(function(n,e){return r("",e)[n]})});

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

!function(n,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):n.format=r()}(this,function(){"use strict";function n(n,r){return function(n){if(Array.isArray(n))return n}(n)||function(n,r){var e=[],t=!0,o=!1,a=void 0;try{for(var i,u=n[Symbol.iterator]();!(t=(i=u.next()).done)&&(e.push(i.value),!r||e.length!==r);t=!0);}catch(n){o=!0,a=n}finally{try{t||null==u.return||u.return()}finally{if(o)throw a}}return e}(n,r)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}var r=function n(r){for(var e=arguments.length,t=new Array(e>1?e-1:0),o=1;o<e;o++)t[o-1]=arguments[o];return r.length<=t.length?r.apply(void 0,t):function(){for(var e=arguments.length,o=new Array(e),a=0;a<e;a++)o[a]=arguments[a];return n.apply(void 0,[r].concat(t,o))}},e=function(n){return n.replace(/[a-z]\w?|\W/gi,"")},t=r(function(r,t){var o=n(e(t).match(/([0-9]{3})?([0-9]{3})([0-9]{4})([0-9]{1,})?/),5),a=o[1],i=o[2],u=o[3],c=o[4];return{countryCode:r,areaCode:a,localCode:i,lineNumber:u,extension:void 0===c?"":c}}),o=function(n,r,e){var t={areaCode:"A",localCode:"L",lineNumber:"N",extension:"E",countryCode:"C"},o=n.concat();return r.split("").forEach(function(n){o=o.replace(t[e],n)}),o};return r(function(n,r,a){if(!function(n){var r=e(n);if(!n||r.length<10)return!1;var o=t("",r),a=o.areaCode,i=o.localCode,u=o.lineNumber;return n&&/^\+?([0-9]{2})\)?[-. ]?([0-9]{4})[-. ]?([0-9]{4})$/.test(a+i+u)}(a))return a;var i=e(a),u=t(n,i),c=r;for(var f in u)u[f]&&(c=o(c,u[f],f));return c})});
!function(n,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):n.format=e()}(this,function(){"use strict";var n=function t(o){for(var n=arguments.length,u=new Array(1<n?n-1:0),e=1;e<n;e++)u[e-1]=arguments[e];return o.length<=u.length?o.apply(void 0,u):function(){for(var n=arguments.length,e=new Array(n),r=0;r<n;r++)e[r]=arguments[r];return t.apply(void 0,[o].concat(u,e))}};function a(n,e){return function(n){if(Array.isArray(n))return n}(n)||function(n,e){var r=[],t=!0,o=!1,u=void 0;try{for(var i,a=n[Symbol.iterator]();!(t=(i=a.next()).done)&&(r.push(i.value),!e||r.length!==e);t=!0);}catch(n){o=!0,u=n}finally{try{t||null==a.return||a.return()}finally{if(o)throw u}}return r}(n,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}var c=function(n){return n.replace(/[a-z]\w?|\W/gi,"")},i=n(function(n,e){var r=a(c(e).match(/([0-9]{3})?([0-9]{3})([0-9]{4})([0-9]{1,})?/),5),t=r[1],o=r[2],u=r[3],i=r[4];return{countryCode:n,areaCode:t,localCode:o,lineNumber:u,extension:void 0===i?"":i}});return n(function(n,e,r){var t,o="".concat(n).concat(c(r));return function(n){var e=c(n);if(!n||e.length<7)return!1;var r=i("",e),t=r.areaCode,o=r.localCode,u=r.lineNumber;return 7===e.length?/^([0-9]{3})[-. ]?([0-9]{4})$/.test(o+u):/^\+?([0-9]{2})\)?[-. ]?([0-9]{4})[-. ]?([0-9]{4})$/.test(t+o+u)}(r)&&(t=o,e.split("").reduce(function(n,e){return"n"===e.toLowerCase()&&n++,n},0)===t.length)?o.split("").reduce(function(n,e){return n.replace(/N/i,e)},e):r})});

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

!function(n,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):n.isValid=e()}(this,function(){"use strict";function n(n,e){return function(n){if(Array.isArray(n))return n}(n)||function(n,e){var r=[],t=!0,o=!1,i=void 0;try{for(var u,a=n[Symbol.iterator]();!(t=(u=a.next()).done)&&(r.push(u.value),!e||r.length!==e);t=!0);}catch(n){o=!0,i=n}finally{try{t||null==a.return||a.return()}finally{if(o)throw i}}return r}(n,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}var e=function(n){return n.replace(/[a-z]\w?|\W/gi,"")},r=function n(e){for(var r=arguments.length,t=new Array(r>1?r-1:0),o=1;o<r;o++)t[o-1]=arguments[o];return e.length<=t.length?e.apply(void 0,t):function(){for(var r=arguments.length,o=new Array(r),i=0;i<r;i++)o[i]=arguments[i];return n.apply(void 0,[e].concat(t,o))}}(function(r,t){var o=n(e(t).match(/([0-9]{3})?([0-9]{3})([0-9]{4})([0-9]{1,})?/),5),i=o[1],u=o[2],a=o[3],l=o[4];return{countryCode:r,areaCode:i,localCode:u,lineNumber:a,extension:void 0===l?"":l}});return function(n){var t=e(n);if(!n||t.length<10)return!1;var o=r("",t),i=o.areaCode,u=o.localCode,a=o.lineNumber;return n&&/^\+?([0-9]{2})\)?[-. ]?([0-9]{4})[-. ]?([0-9]{4})$/.test(i+u+a)}});
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):e.isValid=n()}(this,function(){"use strict";function a(e,n){return function(e){if(Array.isArray(e))return e}(e)||function(e,n){var r=[],t=!0,o=!1,i=void 0;try{for(var u,a=e[Symbol.iterator]();!(t=(u=a.next()).done)&&(r.push(u.value),!n||r.length!==n);t=!0);}catch(e){o=!0,i=e}finally{try{t||null==a.return||a.return()}finally{if(o)throw i}}return r}(e,n)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}var l=function(e){return e.replace(/[a-z]\w?|\W/gi,"")},u=function t(o){for(var e=arguments.length,i=new Array(1<e?e-1:0),n=1;n<e;n++)i[n-1]=arguments[n];return o.length<=i.length?o.apply(void 0,i):function(){for(var e=arguments.length,n=new Array(e),r=0;r<e;r++)n[r]=arguments[r];return t.apply(void 0,[o].concat(i,n))}}(function(e,n){var r=a(l(n).match(/([0-9]{3})?([0-9]{3})([0-9]{4})([0-9]{1,})?/),5),t=r[1],o=r[2],i=r[3],u=r[4];return{countryCode:e,areaCode:t,localCode:o,lineNumber:i,extension:void 0===u?"":u}});return function(e){var n=l(e);if(!e||n.length<7)return!1;var r=u("",n),t=r.areaCode,o=r.localCode,i=r.lineNumber;return 7===n.length?/^([0-9]{3})[-. ]?([0-9]{4})$/.test(o+i):/^\+?([0-9]{2})\)?[-. ]?([0-9]{4})[-. ]?([0-9]{4})$/.test(t+o+i)}});

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

!function(n,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):n.match=r()}(this,function(){"use strict";var n=function n(r){for(var e=arguments.length,t=new Array(e>1?e-1:0),o=1;o<e;o++)t[o-1]=arguments[o];return r.length<=t.length?r.apply(void 0,t):function(){for(var e=arguments.length,o=new Array(e),u=0;u<e;u++)o[u]=arguments[u];return n.apply(void 0,[r].concat(t,o))}};function r(n,r){return function(n){if(Array.isArray(n))return n}(n)||function(n,r){var e=[],t=!0,o=!1,u=void 0;try{for(var i,a=n[Symbol.iterator]();!(t=(i=a.next()).done)&&(e.push(i.value),!r||e.length!==r);t=!0);}catch(n){o=!0,u=n}finally{try{t||null==a.return||a.return()}finally{if(o)throw u}}return e}(n,r)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}var e=function(n){return n.replace(/[a-z]\w?|\W/gi,"")},t=n(function(n,t){var o=r(e(t).match(/([0-9]{3})?([0-9]{3})([0-9]{4})([0-9]{1,})?/),5),u=o[1],i=o[2],a=o[3],f=o[4];return{countryCode:n,areaCode:u,localCode:i,lineNumber:a,extension:void 0===f?"":f}}),o=function(n){var r=e(n);if(!n||r.length<10)return!1;var o=t("",r),u=o.areaCode,i=o.localCode,a=o.lineNumber;return n&&/^\+?([0-9]{2})\)?[-. ]?([0-9]{4})[-. ]?([0-9]{4})$/.test(u+i+a)};return n(function(n,r){return!(!o(n)||!o(r))&&e(n)===e(r)})});
!function(n,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):n.match=e()}(this,function(){"use strict";var n=function t(o){for(var n=arguments.length,u=new Array(1<n?n-1:0),e=1;e<n;e++)u[e-1]=arguments[e];return o.length<=u.length?o.apply(void 0,u):function(){for(var n=arguments.length,e=new Array(n),r=0;r<n;r++)e[r]=arguments[r];return t.apply(void 0,[o].concat(u,e))}};function a(n,e){return function(n){if(Array.isArray(n))return n}(n)||function(n,e){var r=[],t=!0,o=!1,u=void 0;try{for(var i,a=n[Symbol.iterator]();!(t=(i=a.next()).done)&&(r.push(i.value),!e||r.length!==e);t=!0);}catch(n){o=!0,u=n}finally{try{t||null==a.return||a.return()}finally{if(o)throw u}}return r}(n,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}var f=function(n){return n.replace(/[a-z]\w?|\W/gi,"")},i=n(function(n,e){var r=a(f(e).match(/([0-9]{3})?([0-9]{3})([0-9]{4})([0-9]{1,})?/),5),t=r[1],o=r[2],u=r[3],i=r[4];return{countryCode:n,areaCode:t,localCode:o,lineNumber:u,extension:void 0===i?"":i}}),r=function(n){var e=f(n);if(!n||e.length<7)return!1;var r=i("",e),t=r.areaCode,o=r.localCode,u=r.lineNumber;return 7===e.length?/^([0-9]{3})[-. ]?([0-9]{4})$/.test(o+u):/^\+?([0-9]{2})\)?[-. ]?([0-9]{4})[-. ]?([0-9]{4})$/.test(t+o+u)};return n(function(n,e){return!(!r(n)||!r(e))&&f(n)===f(e)})});
{
"name": "phone-fns",
"version": "1.0.1",
"version": "2.0.0",
"description": "Small and simple functional phone library",

@@ -13,22 +13,13 @@ "main": "dist/phone-fns.min.js",

"lint": "standard src/**/*.js",
"test:watch": "ava --watch",
"test": "ava"
"test": "tape -r esm tests/*.js | tap-spec",
"test:cov": "nyc npm test",
"coverage": "nyc report --reporter=text-lcov | coveralls"
},
"ava": {
"files": [
"test/*.js"
"nyc": {
"include": [
"src/**"
],
"require": [
"@babel/register"
],
"failFast": true,
"concurrency": 5,
"babel": {
"testOptions": {
"presets": [
"@ava/transform-test-files",
"@ava/stage-4"
]
}
}
"exclude": [
"tests/**"
]
},

@@ -62,23 +53,20 @@ "standard": {

"devDependencies": {
"@babel/core": "7.0.0-beta.46",
"@babel/preset-env": "7.0.0-beta.46",
"@babel/preset-stage-0": "7.0.0-beta.46",
"@babel/preset-stage-2": "7.0.0-beta.46",
"@babel/register": "7.0.0-beta.46",
"ava": "1.0.0-beta.4",
"@babel/core": "7.0.0-beta.44",
"@babel/preset-env": "7.0.0-beta.44",
"@babel/preset-stage-2": "7.0.0-beta.44",
"coveralls": "3.0.1",
"del": "3.0.0",
"esm": "3.0.37",
"globby": "8.0.1",
"jsdoc-to-markdown": "4.0.1",
"rollup": "0.58.1",
"nyc": "11.8.0",
"rollup": "0.59.3",
"rollup-plugin-babel": "4.0.0-beta.4",
"rollup-plugin-cleanup": "2.0.1",
"rollup-plugin-cleanup": "3.0.0-beta.1",
"rollup-plugin-filesize": "1.5.0",
"rollup-plugin-uglify": "3.0.0",
"standard": "11.0.1"
},
"config": {
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
}
"rollup-plugin-uglify": "4.0.0",
"standard": "11.0.1",
"tap-spec": "4.1.1",
"tape": "4.9.0"
}
}

@@ -1,4 +0,5 @@

[![npm](https://img.shields.io/npm/v/phone-fns.svg?style=for-the-badge)](https://www.npmjs.com/package/phone-fns)
[![David](https://img.shields.io/david/dhershman1/phone-fns.svg?style=for-the-badge)](https://david-dm.org/dhershman1/phone-fns)
[![Travis](https://img.shields.io/travis/dhershman1/phone-fns.svg?style=for-the-badge)](https://travis-ci.org/dhershman1/phone-fns)
[![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)

@@ -16,3 +17,3 @@ # phone-fns

```js
import phoneFns from 'phone-fns';
import phoneFns from 'phone-fns'
```

@@ -23,3 +24,3 @@

```js
const phoneFns = require('phone-fns');
const phoneFns = require('phone-fns')
```

@@ -40,10 +41,10 @@

```javascript
import phoneFns from 'phone-fns';
import phoneFns from 'phone-fns'
const phoneLib = phoneFns();
const phoneLib = phoneFns()
phoneLib.breakdown('4443332222');
phoneLib.breakdown('4443332222')
// => { countryCode: '', areaCode: '444', localCode: '333', lineNumber: '2222', extension: '' }
phoneLib.format('(AAA) LLL-NNNN', '4443332222');
phoneLib.format('(NNN) NNN-NNNN', '4443332222')
// => '(444) 333-2222'

@@ -55,10 +56,10 @@ ```

```javascript
import phoneFns from 'phone-fns';
import phoneFns from 'phone-fns'
const phoneLib = phoneFns('1');
const phoneLib = phoneFns('1')
phoneLib.breakdown('4443332222');
phoneLib.breakdown('4443332222')
// => { countryCode: '1', areaCode: '444', localCode: '333', lineNumber: '2222', extension: '' }
phoneLib.format('C + (AAA) LLL-NNNN', '4443332222');
phoneLib.format('N + (NNN) NNN-NNNN', '4443332222')
// => '1 + (444) 333-2222'

@@ -82,8 +83,8 @@ ```

```js
import uglify from 'phone-fns/uglify';
import uglify from 'phone-fns/uglify'
uglify('555-444-1111'); // => '5554441111'
uglify('555-444-1111') // => '5554441111'
```
### format(countryCode, layout, phone)
### format(cc, layout, phone)

@@ -96,44 +97,36 @@ Customized formatting function allowing you to create your own custom formats

- `countryCode` - `String`: The country code to use (Only required if you call `format` individually)
- `cc` - `String`: The country code to use (Only required if you call `format` individually)
- `layout` - `String`: The desired format to transform the number to
- `phone` - `String`: The desired phone number to run against
- `format` - `String`: The desired format to set the number into, see above
#### Formatting
**NOTE you have to use capitalized letters when creating your layout string**
- `A` - Area Code Number
- `L` - Local Code Number (Usually the first three digits)
- `N` - Line Number (Usually the last four digits)
- `E` - Extension Number (Usually an additional set of digits at the end)
- `C` - Country Code Number (Usually the set of digits that go ahead of a number)
#### Usage
```js
import format from 'phone-fns/format';
import format from 'phone-fns/format'
// Without a country code
format('', '(AAA) LLL-NNNN', '4443332222'); // => '(444) 333-2222'
format('', '(NNN) NNN-NNNN', '4443332222') // => '(444) 333-2222'
// With a country code
format('112', 'CCC + (AAA)-LLL.NNNN', '4443332222'); // => '112 + (444)-333.2222'
format('112', 'NNN + (NNN)-NNN.NNNN', '4443332222') // => '112 + (444)-333.2222'
// Extensions
format('', '(AAA).LLL.NNNN x EEEE', '44433322228989'); // => '(444).333.2222 x 8989'
format('', '(NNN).NNN.NNNN x NNNN', '44433322228989') // => '(444).333.2222 x 8989'
// Case insensitive
format('', '(nnn).nnn.nnNN', '4445556666') // => (444).555.6666
```
`format` is also a curried function
If `format` is called from the main function like so:
```javascript
import format from 'phone-fns/format';
```js
import phoneFns from 'phone-fns'
// Setting it to have no country code
const formatter = format('');
// Or setting it to have no country code and a default layout
const formatWithLayout = format('', '(AAA) LLL.NNNN');
const lib = phoneFns()
const withCC = phoneFns('1')
formatter('AAA.LLL.NNNN', '4443332222'); // => '444.333.2222'
formatWithLayout('4443332222'); // => '(444) 333.2222'
// You no longer are able to pass a country code to format
lib.format('NNN.NNN.NNNN', 4445556666) // => 444.555.6666
withCC.format('N + NNN.NNN.NNNN', 4445556666) // => 1 + 444.555.6666
```

@@ -153,5 +146,5 @@

```js
import find from 'phone-fns/find';
import find from 'phone-fns/find'
find('areaCode', '555-444-3333'); // => '555'
find('areaCode', '555-444-3333') // => '555'
```

@@ -162,8 +155,8 @@

```javascript
import find from 'phone-fns/find';
import find from 'phone-fns/find'
const finder = find('areaCode');
const finder = find('areaCode')
finder('4445556666'); // => '444'
finder('5554443333'); // => '555'
finder('4445556666') // => '444'
finder('5554443333') // => '555'
```

@@ -193,9 +186,9 @@

```js
import breakdown from 'phone-fns/breakdown';
import breakdown from 'phone-fns/breakdown'
breakdown('', '555-444-3333'); // => { countryCode: '', areaCode: '555', localCode: '444', lineNumber: '3333', extension: '' }
breakdown('', '555-444-3333') // => { countryCode: '', areaCode: '555', localCode: '444', lineNumber: '3333', extension: '' }
breakdown('112', '555-444-3333'); // => { countryCode: '112', areaCode: '555', localCode: '444', lineNumber: '3333', extension: '' }
breakdown('112', '555-444-3333') // => { countryCode: '112', areaCode: '555', localCode: '444', lineNumber: '3333', extension: '' }
breakdown('', '555-444-33338989'); // => { countryCode: '', areaCode: '555', localCode: '444', lineNumber: '3333', extension: '8989' }
breakdown('', '555-444-33338989') // => { countryCode: '', areaCode: '555', localCode: '444', lineNumber: '3333', extension: '8989' }
```

@@ -206,11 +199,11 @@

```js
import breakdown from 'phone-fns/breakdown';
import breakdown from 'phone-fns/breakdown'
const breaker = breakdown('');
const breaker = breakdown('')
breaker('555-444-3333'); // => { countryCode: '', areaCode: '555', localCode: '444', lineNumber: '3333', extension: '' }
breaker('555-444-3333') // => { countryCode: '', areaCode: '555', localCode: '444', lineNumber: '3333', extension: '' }
const ccBreaker = breakdown('1');
const ccBreaker = breakdown('1')
ccBreaker('555-444-3333'); // => { countryCode: '1', areaCode: '555', localCode: '444', lineNumber: '3333', extension: '' }
ccBreaker('555-444-3333') // => { countryCode: '1', areaCode: '555', localCode: '444', lineNumber: '3333', extension: '' }
```

@@ -231,7 +224,7 @@

```js
import isValid from 'phone-fns/isValid';
import isValid from 'phone-fns/isValid'
isValid('555-444-3333'); // => true
isValid('555-444-3333') // => true
isValid('8896'); // => false
isValid('8896') // => false
```

@@ -251,7 +244,7 @@

```js
import match from 'phone-fns/match';
import match from 'phone-fns/match'
match('555-444-3333', '555-444-3333'); // => true
match('555-444-3333', '555-444-3333') // => true
match('555-444-3333', '555-333-4444'); // => false
match('555-444-3333', '555-333-4444') // => false
```

@@ -262,10 +255,10 @@

```js
import match from 'phone-fns/match';
import match from 'phone-fns/match'
const matcher = match('555-444-3333');
const matcher = match('555-444-3333')
matcher('5554443333'); // => true
matcher('555-444-3333'); // => true
matcher('555-333-4444'); // => false
matcher('8898'); // => false
matcher('5554443333') // => true
matcher('555-444-3333') // => true
matcher('555-333-4444') // => false
matcher('8898') // => false
```
import babel from 'rollup-plugin-babel'
import cleanup from 'rollup-plugin-cleanup'
import filesize from 'rollup-plugin-filesize'
import uglify from 'rollup-plugin-uglify'
import { uglify } from 'rollup-plugin-uglify'

@@ -9,24 +9,3 @@ export default [{

plugins: [
babel({
babelrc: false,
presets: [
[
'@babel/preset-env',
{
'targets': {
'browsers': [
'last 2 versions',
'ie >= 9'
]
},
'modules': false
}
],
['@babel/preset-stage-2', {
'decoratorsLegacy': true
}]
],
exclude: 'node_modules/**',
runtimeHelpers: true
}),
babel(),
uglify(),

@@ -43,24 +22,3 @@ filesize()

plugins: [
babel({
babelrc: false,
presets: [
[
'@babel/preset-env',
{
'targets': {
'browsers': [
'last 2 versions',
'ie >= 9'
]
},
'modules': false
}
],
['@babel/preset-stage-2', {
'decoratorsLegacy': true
}]
],
exclude: 'node_modules/**',
runtimeHelpers: true
}),
babel(),
cleanup(),

@@ -67,0 +25,0 @@ filesize()

@@ -5,3 +5,3 @@ import babel from 'rollup-plugin-babel'

import path from 'path'
import uglify from 'rollup-plugin-uglify'
import { uglify } from 'rollup-plugin-uglify'

@@ -23,24 +23,3 @@ const buildEntry = () => {

plugins: [
babel({
babelrc: false,
presets: [
[
'@babel/preset-env',
{
'targets': {
'browsers': [
'last 2 versions',
'ie >= 9'
]
},
'modules': false
}
],
['@babel/preset-stage-2', {
'decoratorsLegacy': true
}]
],
exclude: 'node_modules/**',
runtimeHelpers: true
}),
babel(),
uglify(),

@@ -47,0 +26,0 @@ filesize()

Sorry, the diff of this file is not supported yet

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