CARVIEW |
Select Language
HTTP/2 301
location: https://raw.githubusercontent.com/chenglou/phone-parser/master/index.js
accept-ranges: bytes
age: 0
date: Thu, 24 Jul 2025 21:36:25 GMT
via: 1.1 varnish
x-served-by: cache-bom-vanm7210086-BOM
x-cache: MISS
x-cache-hits: 0
x-timer: S1753392985.646004,VS0,VE1191
vary: Accept-Encoding
x-fastly-request-id: 1e166def8bc4be95a77e2dd75fd9b6034c5a7c8b
content-length: 0
HTTP/2 200
cache-control: max-age=300
content-security-policy: default-src 'none'; style-src 'unsafe-inline'; sandbox
content-type: text/plain; charset=utf-8
etag: W/"8bc5bebc34eb438f9d6ee10e0d586ca2ffd7e66bf1ad05e541dfcc15358b8f38"
strict-transport-security: max-age=31536000
x-content-type-options: nosniff
x-frame-options: deny
x-xss-protection: 1; mode=block
x-github-request-id: B500:15132:3A679:A5B17:6882A757
content-encoding: gzip
accept-ranges: bytes
date: Thu, 24 Jul 2025 21:36:26 GMT
via: 1.1 varnish
x-served-by: cache-bom-vanm7210046-BOM
x-cache: MISS
x-cache-hits: 0
x-timer: S1753392986.887931,VS0,VE257
vary: Authorization,Accept-Encoding
access-control-allow-origin: *
cross-origin-resource-policy: cross-origin
x-fastly-request-id: fef8ab4a1aa2fbbf845d47b480ceb02585f84a63
expires: Thu, 24 Jul 2025 21:41:26 GMT
source-age: 0
content-length: 392
function phoneParser(input, format) {
// Trim away everything that's not a digit.
input = input.replace(/\D/g, '');
// Split to array for easier popping.
input = input.split('');
format = format.split('');
var output = '';
while (format.length) {
currentFormatSymbol = format.pop();
if (currentFormatSymbol === 'x') {
var digitToInsert = input.pop();
if (digitToInsert === undefined) break;
output = digitToInsert + output;
} else {
output = currentFormatSymbol + output;
}
}
if (input.length !== 0 || format.length !== 0) {
throw new Error('Phone format cannot be parsed.');
}
return output;
}
// Direct browser support.
if (typeof module === 'undefined') {
window.phoneParser = phoneParser;
} else {
module.exports = phoneParser;
}