-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from dhershman1/development
v4.1.0
- Loading branch information
Showing
26 changed files
with
668 additions
and
150 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/** | ||
* @private | ||
* @function | ||
* @param {String} str The string to check for placeholders | ||
* @returns {Boolean} Whether or not the string has a placeholder | ||
*/ | ||
export default function _hasPlaceholder (str) { | ||
return str.includes('_') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/** | ||
* @private | ||
* @function | ||
* @param {String} str The string to strip special characters | ||
* @returns {String} The newly created string with special characters stripped | ||
*/ | ||
export default function _uglifyFormats (str) { | ||
return str.replace(/[^a-wyz]/gi, '') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import _curry2 from './_internals/_curry2.js' | ||
import isValidWithFormat from './isValidWithFormat.js' | ||
|
||
/** | ||
* @name breakdownWithFormat | ||
* @since v4.1.0 | ||
* @function | ||
* @category Function | ||
* @sig String -> String -> Object | ||
* @description | ||
* Breaks down a phone number based on a custom format provided and returns an object with the parts of the phone number | ||
* C - Country Code A- Area Code L - Local Code N - Line Number X - Extension | ||
* Does NOT work with placeholders | ||
* @param {String} format The format to validate against | ||
* @param {String} phone The phone number to breakdown | ||
* @return {Object} Returns an object with the parts of the phone number | ||
* @example | ||
* import { breakdownWithFormat } from 'phone-fns' | ||
* | ||
* breakdownWithFormat('+C (AAA) LLL-NNNN xXXX', '+1-555-444-3333 x123') // => { countryCode: '1', areaCode: '555', localCode: '444', lineNumber: '3333', extension: '123' } | ||
* breakdownWithFormat('AAA-LLL-NNNN', '010-XYZ-1234') // => Error: The phone number provided does not match the format provided or is an invalid phone number | ||
* | ||
* // it's also curried | ||
* const fn = breakdownWithFormat('+C (AAA) LLL-NNNN xXXX') | ||
* fn('+1-555-444-3333 x123') // => { countryCode: '', areaCode: '123', localCode: '456', lineNumber: '7890', extension: '' } | ||
*/ | ||
function breakdownWithFormat (format, phone) { | ||
if (!format) { | ||
throw new Error('You must provide a format to breakdown') | ||
} | ||
|
||
if (!isValidWithFormat(format, phone)) { | ||
throw new Error('The phone number provided does not match the format provided or is an invalid phone number') | ||
} | ||
|
||
const results = { | ||
countryCode: '', | ||
areaCode: '', | ||
localCode: '', | ||
lineNumber: '', | ||
extension: '' | ||
} | ||
|
||
for (let i = 0; i < format.length; i++) { | ||
switch (format[i]) { | ||
case 'C': | ||
results.countryCode += phone[i] | ||
break | ||
case 'A': | ||
results.areaCode += phone[i] | ||
break | ||
case 'N': | ||
results.lineNumber += phone[i] | ||
break | ||
case 'L': | ||
results.localCode += phone[i] | ||
break | ||
case 'X': | ||
results.extension += phone[i] | ||
break | ||
} | ||
} | ||
|
||
return results | ||
} | ||
|
||
export default _curry2(breakdownWithFormat) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/** | ||
* @name findSeparators | ||
* @since v4.1.0 | ||
* @function | ||
* @category Function | ||
* @sig String -> Array | ||
* @description | ||
* Finds a list of separators in a phone number string | ||
* @param {String} phone The phone number to breakdown | ||
* @return {Array} Returns an array of separators found in the phone number | ||
* @example | ||
* import { findSeparators } from 'phone-fns' | ||
* | ||
* findSeparators('123-456-7890') // => ['-'] | ||
* findSeparators('123.456.7890') // => ['.'] | ||
* findSeparators('123 456 7890') // => [' '] | ||
* findSeparators('1234567890') // => [] | ||
*/ | ||
function findSeparators (phone) { | ||
const separators = ['-', '.', ' '] | ||
const foundSeparators = [] | ||
for (const separator of separators) { | ||
if (phone.includes(separator)) { | ||
foundSeparators.push(separator) | ||
} | ||
} | ||
return foundSeparators | ||
} | ||
|
||
export default findSeparators |
Oops, something went wrong.