New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@aircall/numbers

Package Overview
Dependencies
Maintainers
5
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@aircall/numbers - npm Package Compare versions

Comparing version 0.3.7 to 0.3.8

4

CHANGELOG.md

@@ -6,2 +6,6 @@ # Change Log

## [0.3.8](https://gitlab.com/aircall/shared/front-end-modules/compare/@aircall/numbers@0.3.7...@aircall/numbers@0.3.8) (2023-01-13)
**Note:** Version bump only for package @aircall/numbers
## [0.3.7](https://gitlab.com/aircall/shared/front-end-modules/compare/@aircall/numbers@0.3.6...@aircall/numbers@0.3.7) (2023-01-10)

@@ -8,0 +12,0 @@

11

dist/constants.js

@@ -1,7 +0,4 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.COUNTRY_ISO_MAPPING = exports.COUNTRIES = exports.PHONE_NUMBER_MATCH_REGEXP = exports.PHONE_NUMBER_CARACTER_REGEXP = void 0;
exports.PHONE_NUMBER_CARACTER_REGEXP = /^\+?[\s|\d|(|)|||\-|/]*$/;
exports.PHONE_NUMBER_MATCH_REGEXP = /(\+?[\s|\d|(|).|||\-|/]*)/g;
exports.COUNTRIES = [
export const PHONE_NUMBER_CARACTER_REGEXP = /^\+?[\s|\d|(|)|||\-|/]*$/;
export const PHONE_NUMBER_MATCH_REGEXP = /(\+?[\s|\d|(|).|||\-|/]*)/g;
export const COUNTRIES = [
{

@@ -1245,3 +1242,3 @@ countryCode: 'US',

/** @see https://github.com/vtex/country-iso-3-to-2/blob/master/index.js */
exports.COUNTRY_ISO_MAPPING = {
export const COUNTRY_ISO_MAPPING = {
AD: 'AND',

@@ -1248,0 +1245,0 @@ AE: 'ARE',

@@ -1,9 +0,6 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getCountryISO3 = exports.getCountryByCode = exports.countryCodes = void 0;
const constants_1 = require("./constants");
import { COUNTRIES, COUNTRY_ISO_MAPPING } from './constants';
/**
* Returns a list of country codes
*/
exports.countryCodes = constants_1.COUNTRIES.map(country => country.countryCode);
export const countryCodes = COUNTRIES.map(country => country.countryCode);
/**

@@ -17,5 +14,5 @@ * Get countr (ICountry) base on given country code

*/
function getCountryByCode(countryCode, fallbackCountryCode) {
export function getCountryByCode(countryCode, fallbackCountryCode) {
const properCountryCode = countryCode === null || countryCode === void 0 ? void 0 : countryCode.toUpperCase();
const foundCountry = constants_1.COUNTRIES.find(country => country.countryCode === properCountryCode);
const foundCountry = COUNTRIES.find(country => country.countryCode === properCountryCode);
if (!foundCountry) {

@@ -29,3 +26,2 @@ if (fallbackCountryCode) {

}
exports.getCountryByCode = getCountryByCode;
/**

@@ -37,6 +33,5 @@ * Returns the ISO-3 country code from an ISO-2 country code

*/
function getCountryISO3(countryCode) {
return constants_1.COUNTRY_ISO_MAPPING[countryCode];
export function getCountryISO3(countryCode) {
return COUNTRY_ISO_MAPPING[countryCode];
}
exports.getCountryISO3 = getCountryISO3;
//# sourceMappingURL=countries.js.map

@@ -1,4 +0,2 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const countries_1 = require("./countries");
import { getCountryByCode, getCountryISO3 } from './countries';
describe('Countries', () => {

@@ -12,12 +10,12 @@ describe('getCountryByCode', () => {

it('gets specified country in exact match', () => {
expect((0, countries_1.getCountryByCode)('GR')).toEqual(greeceCountry);
expect(getCountryByCode('GR')).toEqual(greeceCountry);
});
it('gets specified country in insensitive case', () => {
expect((0, countries_1.getCountryByCode)('gr')).toEqual(greeceCountry);
expect(getCountryByCode('gr')).toEqual(greeceCountry);
});
it('returns throws if country code not found', () => {
expect(() => (0, countries_1.getCountryByCode)('XX')).toThrowError('INVALID_COUNTRY_CODE');
expect(() => getCountryByCode('XX')).toThrowError('INVALID_COUNTRY_CODE');
});
it('returns the `fallback` counrtry if not found', () => {
expect((0, countries_1.getCountryByCode)('XX', 'GR')).toEqual(greeceCountry);
expect(getCountryByCode('XX', 'GR')).toEqual(greeceCountry);
});

@@ -27,6 +25,6 @@ });

it('converts an ISO-2 country code into an ISO-3', () => {
expect((0, countries_1.getCountryISO3)('AO')).toEqual('AGO');
expect((0, countries_1.getCountryISO3)('FR')).toEqual('FRA');
expect((0, countries_1.getCountryISO3)('GB')).toEqual('GBR');
expect((0, countries_1.getCountryISO3)('US')).toEqual('USA');
expect(getCountryISO3('AO')).toEqual('AGO');
expect(getCountryISO3('FR')).toEqual('FRA');
expect(getCountryISO3('GB')).toEqual('GBR');
expect(getCountryISO3('US')).toEqual('USA');
});

@@ -33,0 +31,0 @@ });

@@ -1,6 +0,3 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.formatE164 = exports.formatAsYouType = exports.formatNational = exports.formatInternational = exports.normalizeNumber = void 0;
const max_1 = require("libphonenumber-js/max");
const validation_1 = require("./validation");
import { AsYouType, getCountryCallingCode, parsePhoneNumber } from 'libphonenumber-js/max';
import { isValidNumber } from './validation';
/**

@@ -15,6 +12,5 @@ * Normalize an e164 phone number

*/
function normalizeNumber(phoneNumber) {
export function normalizeNumber(phoneNumber) {
return phoneNumber.startsWith('+') ? phoneNumber : `+${phoneNumber}`;
}
exports.normalizeNumber = normalizeNumber;
/**

@@ -28,5 +24,5 @@ * Format an E164 or local phone number to the international format

*/
function formatInternational(phoneNumber, countryCode) {
export function formatInternational(phoneNumber, countryCode) {
try {
const parsedNumber = (0, max_1.parsePhoneNumber)(phoneNumber, countryCode);
const parsedNumber = parsePhoneNumber(phoneNumber, countryCode);
let formattedNumber = parsedNumber.formatInternational();

@@ -58,3 +54,2 @@ // Handle global numbers separately

}
exports.formatInternational = formatInternational;
/**

@@ -68,5 +63,5 @@ * Format an E164 phone number to the national format

*/
function formatNational(phoneNumber, countryCode) {
export function formatNational(phoneNumber, countryCode) {
if (countryCode) {
const countryPrefix = `+${(0, max_1.getCountryCallingCode)(countryCode)}`;
const countryPrefix = `+${getCountryCallingCode(countryCode)}`;
/**

@@ -87,3 +82,3 @@ * Strip country prefix from the number

*/
if ((0, validation_1.isValidNumber)(strippedNumber, countryCode)) {
if (isValidNumber(strippedNumber, countryCode)) {
phoneNumber = strippedNumber;

@@ -93,3 +88,3 @@ }

try {
const parsedNumber = (0, max_1.parsePhoneNumber)(phoneNumber, countryCode);
const parsedNumber = parsePhoneNumber(phoneNumber, countryCode);
return parsedNumber.formatNational();

@@ -103,3 +98,2 @@ }

}
exports.formatNational = formatNational;
/**

@@ -113,7 +107,6 @@ * Format as the user types

*/
function formatAsYouType(value, countryCode) {
const service = new max_1.AsYouType(countryCode);
export function formatAsYouType(value, countryCode) {
const service = new AsYouType(countryCode);
return service.input(value);
}
exports.formatAsYouType = formatAsYouType;
/**

@@ -129,4 +122,4 @@ * Formats a phone number in E164 format

*/
function formatE164(phoneNumber, countryCode) {
const parsedNumber = (0, max_1.parsePhoneNumber)(phoneNumber, countryCode);
export function formatE164(phoneNumber, countryCode) {
const parsedNumber = parsePhoneNumber(phoneNumber, countryCode);
let formattedNumber = parsedNumber.format('E.164');

@@ -140,3 +133,2 @@ // Handle global numbers separately

}
exports.formatE164 = formatE164;
//# sourceMappingURL=formatting.js.map

@@ -1,5 +0,3 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const fs_1 = require("fs");
const formatting_1 = require("./formatting");
import { readFileSync } from 'fs';
import { formatAsYouType, formatE164, formatInternational, formatNational, normalizeNumber } from './formatting';
describe('Formatting', () => {

@@ -10,3 +8,3 @@ describe('formatInternational and formatNational', () => {

const inputValue = 'not a number';
expect((0, formatting_1.formatInternational)(inputValue)).toBe(inputValue);
expect(formatInternational(inputValue)).toBe(inputValue);
});

@@ -17,10 +15,10 @@ });

const inputValue = 'not a number';
expect((0, formatting_1.formatNational)(inputValue, 'FR')).toBe(inputValue);
expect(formatNational(inputValue, 'FR')).toBe(inputValue);
});
it('formats E164 numbers without passing country code', () => {
expect((0, formatting_1.formatNational)('+33123456789')).toBe('01 23 45 67 89');
expect(formatNational('+33123456789')).toBe('01 23 45 67 89');
});
});
describe(' based on CSV dataset', () => {
const lines = (0, fs_1.readFileSync)(__dirname + '/phoneNumberDataset.csv')
const lines = readFileSync(__dirname + '/phoneNumberDataset.csv')
.toString()

@@ -43,7 +41,7 @@ .split('\n');

it(`determines "${nationalFormatted}" is the national format`, () => {
expect((0, formatting_1.formatNational)(e164Number, countryCode)).toBe(nationalFormatted);
expect(formatNational(e164Number, countryCode)).toBe(nationalFormatted);
});
}
it(`determines "${internationalFormatted}" is the international format`, () => {
expect((0, formatting_1.formatInternational)(e164Number)).toBe(internationalFormatted);
expect(formatInternational(e164Number)).toBe(internationalFormatted);
});

@@ -55,7 +53,7 @@ });

it(`determines "${nationalFormatted}" is the national format`, () => {
expect((0, formatting_1.formatNational)(e164NoPlusSign, countryCode)).toBe(nationalFormatted);
expect(formatNational(e164NoPlusSign, countryCode)).toBe(nationalFormatted);
});
}
it(`determines "${internationalFormatted}" is the international format`, () => {
expect((0, formatting_1.formatInternational)(e164NoPlusSign)).toBe(internationalFormatted);
expect(formatInternational(e164NoPlusSign)).toBe(internationalFormatted);
});

@@ -76,6 +74,6 @@ });

it(`formats ${partialNational} as ${regionalResult}`, () => {
expect((0, formatting_1.formatAsYouType)(partialNational, countryCode)).toBe(regionalResult);
expect(formatAsYouType(partialNational, countryCode)).toBe(regionalResult);
});
it(`formats ${partialInternational} as ${internationalResult}`, () => {
expect((0, formatting_1.formatAsYouType)(partialInternational, countryCode)).toBe(internationalResult);
expect(formatAsYouType(partialInternational, countryCode)).toBe(internationalResult);
});

@@ -97,7 +95,7 @@ });

it(`formats ${formattedNumber}`, () => {
expect((0, formatting_1.formatE164)(formattedNumber, countryCode)).toBe(expectedResult);
expect(formatE164(formattedNumber, countryCode)).toBe(expectedResult);
});
});
it('throws on fail', () => {
expect(() => (0, formatting_1.formatE164)('+')).toThrow();
expect(() => formatE164('+')).toThrow();
});

@@ -109,3 +107,3 @@ });

const validPhoneNumber = '+33123456789';
expect((0, formatting_1.normalizeNumber)(validPhoneNumber)).toBe(validPhoneNumber);
expect(normalizeNumber(validPhoneNumber)).toBe(validPhoneNumber);
});

@@ -115,3 +113,3 @@ });

it('prepends +', () => {
expect((0, formatting_1.normalizeNumber)('33123456789')).toBe('+33123456789');
expect(normalizeNumber('33123456789')).toBe('+33123456789');
});

@@ -118,0 +116,0 @@ });

@@ -1,23 +0,7 @@

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
/* istanbul ignore file */
__exportStar(require("./constants"), exports);
__exportStar(require("./countries"), exports);
__exportStar(require("./formatting"), exports);
__exportStar(require("./parsing"), exports);
__exportStar(require("./validation"), exports);
export * from './constants';
export * from './countries';
export * from './formatting';
export * from './parsing';
export * from './validation';
//# sourceMappingURL=index.js.map

@@ -1,8 +0,5 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseText = exports.guessCountryCode = exports.getCountryCode = exports.getCountryCodeAsYouType = exports.parsePartialPhoneNumber = exports.parseNumber = void 0;
const max_1 = require("libphonenumber-js/max");
const constants_1 = require("./constants");
const formatting_1 = require("./formatting");
const validation_1 = require("./validation");
import { AsYouType, findPhoneNumbersInText, getCountryCallingCode, parsePhoneNumber } from 'libphonenumber-js/max';
import { COUNTRIES } from './constants';
import { normalizeNumber } from './formatting';
import { isValidNumber } from './validation';
/**

@@ -18,6 +15,5 @@ * Parses strings with phone numbers.

*/
function parseNumber(text, countryCode) {
return (0, max_1.parsePhoneNumber)(text, countryCode);
export function parseNumber(text, countryCode) {
return parsePhoneNumber(text, countryCode);
}
exports.parseNumber = parseNumber;
/**

@@ -32,8 +28,7 @@ * Parses strings with partial phone numbers.

*/
function parsePartialPhoneNumber(text, countryCode) {
const asYouType = new max_1.AsYouType(countryCode);
export function parsePartialPhoneNumber(text, countryCode) {
const asYouType = new AsYouType(countryCode);
asYouType.input(text);
return asYouType.getNumber();
}
exports.parsePartialPhoneNumber = parsePartialPhoneNumber;
/**

@@ -46,7 +41,6 @@ * Extract country code from number as user types

*/
function getCountryCodeAsYouType(phoneNumber) {
export function getCountryCodeAsYouType(phoneNumber) {
const parsedNumber = parsePartialPhoneNumber(phoneNumber);
return parsedNumber === null || parsedNumber === void 0 ? void 0 : parsedNumber.country;
}
exports.getCountryCodeAsYouType = getCountryCodeAsYouType;
/**

@@ -59,3 +53,3 @@ * Extract country data from given number

*/
function getCountryCode(phoneNumber) {
export function getCountryCode(phoneNumber) {
if (!phoneNumber.trim()) {

@@ -67,3 +61,3 @@ return;

// Try to parse the number first (works only for numbers > 5 digits)
const parsedNumber = (0, max_1.parsePhoneNumber)(phoneNumber);
const parsedNumber = parsePhoneNumber(phoneNumber);
countryCode = parsedNumber.country;

@@ -76,3 +70,3 @@ }

if (!countryCode) {
const country = constants_1.COUNTRIES.find(countryData => (0, formatting_1.normalizeNumber)(phoneNumber).startsWith(countryData.phonePrefix));
const country = COUNTRIES.find(countryData => normalizeNumber(phoneNumber).startsWith(countryData.phonePrefix));
// When countries share the same prefix, we can return a preferred one

@@ -83,3 +77,3 @@ // It is particularly useful for small territories attached to big countries

const mainPrefixx = country.mainCountryWithSamePrefix;
const mainCountry = constants_1.COUNTRIES.find(countryData => countryData.countryCode === mainPrefixx);
const mainCountry = COUNTRIES.find(countryData => countryData.countryCode === mainPrefixx);
return mainCountry === null || mainCountry === void 0 ? void 0 : mainCountry.countryCode;

@@ -91,6 +85,5 @@ }

}
const foundCountry = constants_1.COUNTRIES.find(countryData => countryData.countryCode === countryCode);
const foundCountry = COUNTRIES.find(countryData => countryData.countryCode === countryCode);
return foundCountry === null || foundCountry === void 0 ? void 0 : foundCountry.countryCode;
}
exports.getCountryCode = getCountryCode;
/**

@@ -109,3 +102,3 @@ * Literally guess the country data for a given number based on

*/
function guessCountryCode(phoneNumber, countryCode, defaultCountryCode, isTyping) {
export function guessCountryCode(phoneNumber, countryCode, defaultCountryCode, isTyping) {
// If no number return currently selected country

@@ -116,3 +109,3 @@ if (!phoneNumber) {

const extractedCountryCode = getCountryCode(phoneNumber);
const extractedCountryPrefix = extractedCountryCode && `+${(0, max_1.getCountryCallingCode)(extractedCountryCode)}`;
const extractedCountryPrefix = extractedCountryCode && `+${getCountryCallingCode(extractedCountryCode)}`;
/**

@@ -131,3 +124,3 @@ * If we have extracted country data and:

phoneNumber.startsWith('+') &&
((0, validation_1.isValidNumber)(phoneNumber, extractedCountryCode) ||
(isValidNumber(phoneNumber, extractedCountryCode) ||
phoneNumber.startsWith(extractedCountryPrefix))) {

@@ -137,11 +130,11 @@ return extractedCountryCode;

// If user is typing or number is valid in the currently selected country, return it
if (isTyping || (0, validation_1.isValidNumber)(phoneNumber, countryCode)) {
if (isTyping || isValidNumber(phoneNumber, countryCode)) {
return countryCode;
}
// If number is valid in the user's default country, return it
if ((0, validation_1.isValidNumber)(phoneNumber, defaultCountryCode)) {
if (isValidNumber(phoneNumber, defaultCountryCode)) {
return defaultCountryCode;
}
// If number is valid after normalization (appending `+`) withing the extracted country, return it
if (extractedCountryCode && (0, validation_1.isValidNumber)((0, formatting_1.normalizeNumber)(phoneNumber), extractedCountryCode)) {
if (extractedCountryCode && isValidNumber(normalizeNumber(phoneNumber), extractedCountryCode)) {
return extractedCountryCode;

@@ -152,3 +145,2 @@ }

}
exports.guessCountryCode = guessCountryCode;
/**

@@ -162,6 +154,5 @@ * Parses text for phone numbers

*/
function parseText(text, countryCode) {
return (0, max_1.findPhoneNumbersInText)(text, countryCode);
export function parseText(text, countryCode) {
return findPhoneNumbersInText(text, countryCode);
}
exports.parseText = parseText;
//# sourceMappingURL=parsing.js.map

@@ -1,5 +0,3 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const libphonenumber_js_1 = require("libphonenumber-js");
const parsing_1 = require("./parsing");
import { ParseError } from 'libphonenumber-js';
import { getCountryCode, guessCountryCode, parseNumber, parsePartialPhoneNumber, parseText } from './parsing';
describe('Parsing', () => {

@@ -10,3 +8,3 @@ describe('parseNumber', () => {

const testNumber = '+33999999999';
const result = (0, parsing_1.parseNumber)(testNumber);
const result = parseNumber(testNumber);
expect(result && result.number).toBe(testNumber);

@@ -17,3 +15,3 @@ });

const expectedNumber = '+33999999999';
const result = (0, parsing_1.parseNumber)(testNumber);
const result = parseNumber(testNumber);
expect(result && result.number).toBe(expectedNumber);

@@ -23,3 +21,3 @@ });

const testNumber = '+3';
expect(() => (0, parsing_1.parseNumber)(testNumber)).toThrowError(libphonenumber_js_1.ParseError);
expect(() => parseNumber(testNumber)).toThrowError(ParseError);
});

@@ -31,3 +29,3 @@ });

const expectedNumber = '+33999999999';
const result = (0, parsing_1.parseNumber)(testNumber, 'FR');
const result = parseNumber(testNumber, 'FR');
expect(result && result.number).toBe(expectedNumber);

@@ -38,3 +36,3 @@ });

const expectedNumber = '+33999999999';
const result = (0, parsing_1.parseNumber)(testNumber, 'FR');
const result = parseNumber(testNumber, 'FR');
expect(result && result.number).toBe(expectedNumber);

@@ -44,3 +42,3 @@ });

const testNumber = '0';
expect(() => (0, parsing_1.parseNumber)(testNumber)).toThrowError(libphonenumber_js_1.ParseError);
expect(() => parseNumber(testNumber)).toThrowError(ParseError);
});

@@ -51,3 +49,3 @@ });

const testNumber = 'abc';
expect(() => (0, parsing_1.parseNumber)(testNumber)).toThrowError(libphonenumber_js_1.ParseError);
expect(() => parseNumber(testNumber)).toThrowError(ParseError);
});

@@ -61,3 +59,3 @@ });

const expectedNumber = '+33999';
const result = (0, parsing_1.parsePartialPhoneNumber)(testNumber, 'FR');
const result = parsePartialPhoneNumber(testNumber, 'FR');
expect(result).toBeDefined();

@@ -69,3 +67,3 @@ expect(result && result.number).toBe(expectedNumber);

const expectedNumber = '+33999';
const result = (0, parsing_1.parsePartialPhoneNumber)(testNumber, 'FR');
const result = parsePartialPhoneNumber(testNumber, 'FR');
expect(result).toBeDefined();

@@ -79,3 +77,3 @@ expect(result && result.number).toBe(expectedNumber);

const expectedNumber = '+33999';
const result = (0, parsing_1.parsePartialPhoneNumber)(testNumber, 'FR');
const result = parsePartialPhoneNumber(testNumber, 'FR');
expect(result).toBeDefined();

@@ -87,3 +85,3 @@ expect(result && result.number).toBe(expectedNumber);

const expectedNumber = '+33999';
const result = (0, parsing_1.parsePartialPhoneNumber)(testNumber, 'FR');
const result = parsePartialPhoneNumber(testNumber, 'FR');
expect(result).toBeDefined();

@@ -96,3 +94,3 @@ expect(result && result.number).toBe(expectedNumber);

const testNumber = 'abc';
expect((0, parsing_1.parsePartialPhoneNumber)(testNumber, 'FR')).toBeUndefined();
expect(parsePartialPhoneNumber(testNumber, 'FR')).toBeUndefined();
});

@@ -104,3 +102,3 @@ });

it('returs "undefined"', () => {
expect((0, parsing_1.getCountryCode)('')).toBeUndefined();
expect(getCountryCode('')).toBeUndefined();
});

@@ -123,3 +121,3 @@ });

it(`returns the correct country for ${data[0]}`, () => {
expect((0, parsing_1.getCountryCode)(data[0])).toBe(data[1]);
expect(getCountryCode(data[0])).toBe(data[1]);
});

@@ -143,3 +141,3 @@ });

it(`returns the correct country for ${data[0]}`, () => {
expect((0, parsing_1.getCountryCode)(data[0])).toBe(data[1]);
expect(getCountryCode(data[0])).toBe(data[1]);
});

@@ -158,3 +156,3 @@ });

it(`returns the main country for ${data[0]}`, () => {
expect((0, parsing_1.getCountryCode)(data[0])).toBe(data[1]);
expect(getCountryCode(data[0])).toBe(data[1]);
});

@@ -165,3 +163,3 @@ });

it('returns "undefined"', () => {
expect((0, parsing_1.getCountryCode)('+99999999999')).toBeUndefined();
expect(getCountryCode('+99999999999')).toBeUndefined();
});

@@ -175,3 +173,3 @@ });

it('returns current country', () => {
expect((0, parsing_1.guessCountryCode)('', currentCountryCode, defaultCountryCode, false)).toEqual(currentCountryCode);
expect(guessCountryCode('', currentCountryCode, defaultCountryCode, false)).toEqual(currentCountryCode);
});

@@ -181,3 +179,3 @@ });

it('returns current country', () => {
expect((0, parsing_1.guessCountryCode)('+33650', currentCountryCode, defaultCountryCode, true)).toEqual(currentCountryCode);
expect(guessCountryCode('+33650', currentCountryCode, defaultCountryCode, true)).toEqual(currentCountryCode);
});

@@ -195,3 +193,3 @@ });

it(`returns ${data[1]} for ${data[0]}`, () => {
const countryCode = (0, parsing_1.guessCountryCode)(data[0], 'AU', 'AU', false);
const countryCode = guessCountryCode(data[0], 'AU', 'AU', false);
expect(countryCode).toBe(data[1]);

@@ -216,3 +214,3 @@ });

it(`returns ${data[1]} for ${data[0]}`, () => {
const countryCode = (0, parsing_1.guessCountryCode)(data[0], 'AU', 'AU', false);
const countryCode = guessCountryCode(data[0], 'AU', 'AU', false);
expect(countryCode).toBe(data[1]);

@@ -237,3 +235,3 @@ });

it(`returns ${data[1]} for ${data[0]}`, () => {
const countryCode = (0, parsing_1.guessCountryCode)(data[0], 'AU', 'AU', false);
const countryCode = guessCountryCode(data[0], 'AU', 'AU', false);
expect(countryCode).toBe(data[1]);

@@ -247,3 +245,3 @@ });

// Local number for the Louvre Pyramid
const countryCode = (0, parsing_1.guessCountryCode)('0140205050', currentCountryCode, 'US', false);
const countryCode = guessCountryCode('0140205050', currentCountryCode, 'US', false);
expect(countryCode).toBe(currentCountryCode);

@@ -255,3 +253,3 @@ });

// Local number for the Buckingham Palace
const countryCode = (0, parsing_1.guessCountryCode)('3031237300', 'US', defaultCountryCode, false);
const countryCode = guessCountryCode('3031237300', 'US', defaultCountryCode, false);
expect(countryCode).toBe(defaultCountryCode);

@@ -264,3 +262,3 @@ });

// Local number for the Sydney Opera
const countryCode = (0, parsing_1.guessCountryCode)('2323120', currentCountryCode, defaultCountryCode, false);
const countryCode = guessCountryCode('2323120', currentCountryCode, defaultCountryCode, false);
expect(countryCode).toBe(currentCountryCode);

@@ -277,3 +275,3 @@ });

].join(' ');
const result = (0, parsing_1.parseText)(text, 'US');
const result = parseText(text, 'US');
expect(result.map(foundNumber => foundNumber.number.number)).toEqual([

@@ -292,3 +290,3 @@ '+33175000000',

].join(' ');
const result = (0, parsing_1.parseText)(text);
const result = parseText(text);
expect(result.map(foundNumber => foundNumber.number.number)).toEqual([

@@ -295,0 +293,0 @@ '+33175000000',

@@ -1,6 +0,3 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isPartialPhoneNumber = exports.isPossibleNumber = exports.isValidNumber = void 0;
const max_1 = require("libphonenumber-js/max");
const constants_1 = require("./constants");
import { parsePhoneNumber } from 'libphonenumber-js/max';
import { PHONE_NUMBER_CARACTER_REGEXP } from './constants';
/**

@@ -14,5 +11,5 @@ * Checks if given input is a valid phone number

*/
function isValidNumber(phoneNumber, countryCode) {
export function isValidNumber(phoneNumber, countryCode) {
try {
return (0, max_1.parsePhoneNumber)(phoneNumber, countryCode).isValid();
return parsePhoneNumber(phoneNumber, countryCode).isValid();
}

@@ -23,3 +20,2 @@ catch (_a) {

}
exports.isValidNumber = isValidNumber;
/**

@@ -33,5 +29,5 @@ * Checks if the given input is a possible phone number

*/
function isPossibleNumber(text, countryCode) {
export function isPossibleNumber(text, countryCode) {
try {
return (0, max_1.parsePhoneNumber)(text, countryCode).isPossible();
return parsePhoneNumber(text, countryCode).isPossible();
}

@@ -42,3 +38,2 @@ catch (_a) {

}
exports.isPossibleNumber = isPossibleNumber;
/**

@@ -50,6 +45,5 @@ * Checks if a string is a potential partial phone number

*/
function isPartialPhoneNumber(text) {
return !!text && constants_1.PHONE_NUMBER_CARACTER_REGEXP.test(text);
export function isPartialPhoneNumber(text) {
return !!text && PHONE_NUMBER_CARACTER_REGEXP.test(text);
}
exports.isPartialPhoneNumber = isPartialPhoneNumber;
//# sourceMappingURL=validation.js.map

@@ -1,4 +0,2 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const validation_1 = require("./validation");
import { isPartialPhoneNumber, isPossibleNumber, isValidNumber } from './validation';
describe('Validation', () => {

@@ -20,3 +18,3 @@ describe('isValidNumber', () => {

it(`matches ${phoneNumber} with ${countryCode}`, () => {
expect((0, validation_1.isValidNumber)(phoneNumber, countryCode)).toEqual(true);
expect(isValidNumber(phoneNumber, countryCode)).toEqual(true);
});

@@ -36,3 +34,3 @@ });

it(`does not match ${phoneNumber} with ${countryCode}`, () => {
expect((0, validation_1.isValidNumber)(phoneNumber, countryCode)).toEqual(false);
expect(isValidNumber(phoneNumber, countryCode)).toEqual(false);
});

@@ -56,3 +54,3 @@ });

it(`matches ${phoneNumber} with ${countryCode}`, () => {
expect((0, validation_1.isPossibleNumber)(phoneNumber, countryCode)).toEqual(true);
expect(isPossibleNumber(phoneNumber, countryCode)).toEqual(true);
});

@@ -71,3 +69,3 @@ });

it(`does not match ${phoneNumber} with ${countryCode}`, () => {
expect((0, validation_1.isPossibleNumber)(phoneNumber, countryCode)).toEqual(false);
expect(isPossibleNumber(phoneNumber, countryCode)).toEqual(false);
});

@@ -87,3 +85,3 @@ });

it(`matches ${value}`, () => {
expect((0, validation_1.isPartialPhoneNumber)(value)).toEqual(true);
expect(isPartialPhoneNumber(value)).toEqual(true);
});

@@ -94,3 +92,3 @@ });

it(`does not match ${value}`, () => {
expect((0, validation_1.isPartialPhoneNumber)(value)).toEqual(false);
expect(isPartialPhoneNumber(value)).toEqual(false);
});

@@ -97,0 +95,0 @@ });

{
"name": "@aircall/numbers",
"version": "0.3.7",
"version": "0.3.8",
"main": "dist/index.js",

@@ -14,6 +14,6 @@ "types": "dist/index.d.ts",

},
"gitHead": "f11d05e96ef43b6d3691b5d597ffeabe9a0d899c",
"gitHead": "8b834c28bfd294b3c6094b1b3103f033cd57f227",
"dependencies": {
"libphonenumber-js": "1.10.15"
"libphonenumber-js": "1.10.18"
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc