1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- import mergeArrays from './mergeArrays.js'
- export default function checkNumberLength(nationalNumber, metadata) {
- return checkNumberLengthForType(nationalNumber, undefined, metadata)
- }
- export function checkNumberLengthForType(nationalNumber, type, metadata) {
- const type_info = metadata.type(type)
-
-
-
-
-
-
-
- let possible_lengths = type_info && type_info.possibleLengths() || metadata.possibleLengths()
-
-
- if (!possible_lengths) {
- return 'IS_POSSIBLE'
- }
- if (type === 'FIXED_LINE_OR_MOBILE') {
-
-
- if (!metadata.type('FIXED_LINE')) {
-
-
- return checkNumberLengthForType(nationalNumber, 'MOBILE', metadata)
- }
- const mobile_type = metadata.type('MOBILE')
- if (mobile_type) {
-
-
-
-
-
- possible_lengths = mergeArrays(possible_lengths, mobile_type.possibleLengths())
-
-
-
-
-
-
-
-
- }
- }
-
- else if (type && !type_info) {
- return 'INVALID_LENGTH'
- }
- const actual_length = nationalNumber.length
-
-
-
-
-
-
-
- const minimum_length = possible_lengths[0]
- if (minimum_length === actual_length) {
- return 'IS_POSSIBLE'
- }
- if (minimum_length > actual_length) {
- return 'TOO_SHORT'
- }
- if (possible_lengths[possible_lengths.length - 1] < actual_length) {
- return 'TOO_LONG'
- }
-
- return possible_lengths.indexOf(actual_length, 1) >= 0 ? 'IS_POSSIBLE' : 'INVALID_LENGTH'
- }
|