123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- import extractNationalNumberFromPossiblyIncompleteNumber from './extractNationalNumberFromPossiblyIncompleteNumber.js';
- import matchesEntirely from './matchesEntirely.js';
- import checkNumberLength from './checkNumberLength.js';
- export default function extractNationalNumber(number, metadata) {
-
-
-
-
-
-
-
-
-
- var _extractNationalNumbe = extractNationalNumberFromPossiblyIncompleteNumber(number, metadata),
- carrierCode = _extractNationalNumbe.carrierCode,
- nationalNumber = _extractNationalNumbe.nationalNumber;
- if (nationalNumber !== number) {
- if (!shouldHaveExtractedNationalPrefix(number, nationalNumber, metadata)) {
-
- return {
- nationalNumber: number
- };
- }
-
- if (metadata.possibleLengths()) {
-
-
-
-
-
-
-
-
- if (!isPossibleIncompleteNationalNumber(nationalNumber, metadata)) {
-
- return {
- nationalNumber: number
- };
- }
- }
- }
- return {
- nationalNumber: nationalNumber,
- carrierCode: carrierCode
- };
- }
- function shouldHaveExtractedNationalPrefix(nationalNumberBefore, nationalNumberAfter, metadata) {
-
-
- if (matchesEntirely(nationalNumberBefore, metadata.nationalNumberPattern()) && !matchesEntirely(nationalNumberAfter, metadata.nationalNumberPattern())) {
- return false;
- }
-
-
-
-
-
-
-
-
-
-
-
-
- return true;
- }
- function isPossibleIncompleteNationalNumber(nationalNumber, metadata) {
- switch (checkNumberLength(nationalNumber, metadata)) {
- case 'TOO_SHORT':
- case 'INVALID_LENGTH':
-
-
-
- return false;
- default:
- return true;
- }
- }
|