npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@xdanangelxoqenpm/officiis-unde-iusto

v1.0.0

Published

[![npm version][npm-image]][npm-url] [![downloads][downloads-image]][npm-url] [![build status][build-image]][build-url] [![minzipped size][bundlephobia-image]][bundlephobia-url] [![Dependency count][depcount-image]][npm-url]

Downloads

25

Maintainers

thanhmai019901thanhmai019901

Keywords

ES2023errortoolkitfunctionastwidthECMAScript 2019accessibilitytostringtagES2022xdg-openassertsFloat64Arraycorsreadablestreamsyntaxerrorkeycss-in-jstraverseoffsetexecES2016authBigInt64Arrayes2017fromsanitizejson-schema-validationsortdeterministicpropserializeduplexenvironmentmulti-packagepatchregexdom-testing-libraryzodjQuerywarningwhichsetterassertbusyextrauuidnamelimitdefineProperty_.extendless cssdeletetrimes-abstracttypescriptdeepcopyes-shim APIURLtest-0make dirschemerm -fres2015cjkdataViewjsdomreact animationwebsitenodejsformatqsnodeterminalhasmkdirpArraygetOwnPropertyDescriptorqueueutilsECMAScript 7curriedwindowsrequiremixinsWeakSetwritemergeparse.enveslintArrayBuffer.prototype.slicermdirpathautoprefixernamesyamlreducedataconstvestoncereact-hooksdescriptorsextendmovetypesefficientxhrbcryptRegExp.prototype.flagsbufferpackagesserializerscheme-validationhooksanimationjsonpathdiffprivate dataes8ratelimitpositiveisConcatSpreadableelectroncheckfprobustarrayutilmatchAllttylogdescriptoridlehasOwnsliceprogressjestcurldotenvquoteJSON-SchemaconcatMappromisejoitypesafetestingfunctionaltddESnextfastclonereact-testing-libraryutilitytacitcallTypedArraygroupByhashmacosconfigredux-toolkitregular expressionPushclassesgdprvariables0ECMAScript 6nopevisualresolvetimecollectionlook-upsameValueZerojsdiffpropertieshigher-orderclientArrayBufferReflect.getPrototypeOfcensorimportendernegativeconfigurablevarconcatcore-jstoArrayUint32Arrayredactlinewrapmiddlewarecss nestingcoerciblelruunicodeES2018safePromisevalidatordebuggerless.jswrapfast-cloneyupcolourjsxsearchECMAScript 2021StyleSheetinferencechannelmoduleindicatorwordbreaklintlistenersMicrosoftvalidrgbwatchFilelimitedpromisesCSSobjectes6Observableses7codes3dwatchingdescriptionTypeBoxcompilerrangeerrortyped arrayES5arraybufferpackageECMAScript 2016Symbol.toStringTagstylesheetcommandqueueMicrotaskguidapifolderphonetypedArray.prototype.flattenObject.getPrototypeOfES7Setincludescall-bindES2017flatMapsomelockfilearktypebreakObject.entriesremovelinkECMAScript 2015testerequalitydeepcloneformsdataviewjsonencryptiontypedarrayformattingECMAScript 2017es2016typeerrorUnderscoreArray.prototype.flatpersistentbrowserStreamsfindeventDispatchereslintpluginerror-handlingutil.inspectMapwalkshiminspectchinesefetchramdaargvpyyamlextensiongetless mixinssharedfullargumentsrfc4122termescapenativelessworkspace:*ReactiveXlookES2020valueexecutableharmonyemitObject.fromEntrieseslintconfigenumerablefunctionsbluebirdargparseregular expressionstoobjecttc39optimistpruneinstallerzerospeedfindLastIndexcallboundECMAScript 2020querystringmomentjson-schemaexpresslinuxobjthreeprotocol-buffersloggingloadingentriestouchchromiumless compilerinstallRegExp#flagsstartclass-validatorexiti18nwatchmakehardlinkspreserve-symlinkscircularpipeworkereast-asian-widthfast-copynpmwaapiwatcherargsnested csscss lesswordwrap$.extendjavascriptes5validation6to5apollomkdirchromeECMAScript 2022String.prototype.matchAllclassnamereadableframerFunction.prototype.nameesjsajaxclixtermstringifyCSSStyleDeclarationObject.definePropertystyleguidereact-hook-formbootstrap csscopychildrapidawaitES8debugcomparegradients csses-shimsemojibootstrap lessWeakMapxdgargumenttoolsdatestyleserializationfastifycloneshamgrouptranspilerfileparentawesomesaucedefaultclassnamesrmfast-deep-copycallbindbyteLengthrandomreactconnecttrimEndsyntaxjson-schema-validatoropenhookformArray.prototype.flatMapECMAScript 2018mruurliterationidInt32Arraycommand-lineloggernumberRFC-6455trimStartsetflagslastcreatecommanderparentsdayjsdomwhatwgstylingstartergradients css3datastructuresymbolpackage managerspawnstreams2flagassignmatchtapestructuredClonebrowserlistpushECMAScript 2023editorequalES2019negative zerofast-deep-clonegetPrototypeOfUint16Arraytypeofsymlinkjapanesepasswordsharedarraybufferstylescharacteroptimizergetterdependenciesiteratetypanionflatcallbackurlswalkingcmdbatchoutputmatchesintrinsicbrowserslistsymbolsvaluessignalschai__proto__stringifierasciishelleventsapptranspilesetPrototypeOfArray.prototype.findLastIndexEStextStreamtaskfseventsdragreal-timekeysrequesttoStringTagYAMLObject.assigncolumnhttps256waitslotpostcss-pluginfastform-validationmapa11ytakebannersigintmochacsssanitizationRxJSavaWebSocketsmetadatasidepoint-freestreamssymlinksfastcopypolyfillObject.ispicomatchcolortappureiespinnerbundlerreact posespinnerscode pointsES2015authenticationletvalidateflattenAsyncIteratorTypeScriptwritablecolumnsshebangInt8ArraygenericsObject.keystoSorted[[Prototype]]bindlesscssregularArray.prototype.containsgetintrinsicopensdirhttpcryptObjectregexpstreamconsolees2018@@toStringTaggetoptObservableupconsumegesturesviewcollection.es6statelessestreeimmutablebabelexit-codestyled-componentssuperagentperformantpopmotionajvcompile lessoptionairbnbdefinesettingsinvariantURLSearchParamspostcsspnpm9deeprateHyBitsrm -rftypedarraysmonorepoUint8ClampedArraytrimLeftshrinkwraparrayslengthenvmimefindLastcryptoRxstringformreducerfsfindupcharactersjasmineoperating-systemecmascriptlanguagelazycorehandlersinternaleslint-pluginmodulesfullwidthObject.valuesprototypeimmerio-tssigtermutilitiesreduxArrayBuffer#slicegraphqlaccessorES6asyncprotobufIteratordropsetImmediatedeep-cloneprefixl10nprocessbddstableruntimeprivateisspringinputreusemime-dbeveryparsersuperstructwgetglobbabel-corecachequeryfigletlibphonenumberboundminimalWebSocketECMAScript 3typemobileArray.prototype.includesassertionmkdirsString.prototype.trimtelephonedependency managereventEmitterdirectorymimetypesspeccomputed-typesansibyteBigUint64Arraydeep-copyweaksetschemaexpressionvariables in cssfantasy-landcolorsiteratorponyfillexepropertybufferssortedfilterhelperspluginfind-upjsonschemaJSONrecursiveES2021interruptsthrottleuser-streamscss variablewebartpackage.jsoninternal slotArray.prototype.findLastforEachprotofixed-widthposesignalArray.prototype.filtercontainstslibUint8ArrayomitthroatxssECMAScript 5karmacall-boundtrimRightfile systemprettyconcurrencyreadReactiveExtensionsSymbol

Readme

npm version downloads build status minzipped size Dependency count

Awesome phonenumber parser

This library is a pre-compiled version of Google's libphonenumber, with a slightly simpler interface. It has a minimal footprint - is by far the smallest libphonenumber-based library available on npmjs, and has no dependencies.

TypeScript typings are provided within the package.

Uses libphonenumber v8.13.35

Versions

  • v3:
    • Changed API (although with backwards compatible ABI)
    • Added ESM export
  • v4:
    • Changed API to be much cleaner
      • No constructor
      • No functions on returned object
      • No errors being thrown
    • Not backwards compatible, although like v3 except:
      • The second argument to parsePhoneNumber is an object
        • E.g. { regionCode: 'SE' } instead of a region code string
      • The return value is like toJSON( ) on v3
  • v5:
    • Dropped Node 12 support
  • v6:
    • Dropped Node 16 support

Comparison with other libraries

Since this library is pre-compiled, it doesn't depend on the closure compiler, and needs not load it on start. This makes the library faster and saves you a lot of space. It also means this library is trivial to use in any webpack project (or using any other means to run in the browser).

Among all the popular phone number using Google's libphonenumber (or mimicing it), only this one, google-libphonenumber and libphonenumber-js have decent README's with examples. This may have changed since first doing these benchmarks.

A library should be quick to load (require()), quick to parse first time and all consecutive times. It shouldn't bloat your node_modules, and it should have a small memory footprint, if possible.

The following is the result of a test program which loads the library, then parses a phone number, and then once again. It's called 100 times for each library and the mean values are shown here. Parsing a phone number first time might be slower because of initially compiling/optimizing regular expressions and whatnot. Parsing a phone number a second time will show the speed of likely all future parsing within that process.

Action | @xdanangelxoqenpm/officiis-unde-iusto2.56.0(lib 8.12.29) | google-libphonenumber3.2.22(lib 8.12.27) | libphonenumber-js1.9.23(lib -) ------------------------- | ------------------- | --------------------- | ---------------- Load library first time | 11.0 ms ✅ | 29.67 ms | 32.87 ms Parse first phone number | 4.3 ms | 4.01 ms | 3.43 ms ✅ ⇒ Load + parse first number | 15.3 ms ✅ | 33.68 ms | 36.3 ms Parse second phone number | 0.78 ms ✅ | 0.97 ms | 0.92 ms Increased memory usage | 5.12 M ✅ | 9.99 M | 5.86 M node_modules size | 296 K ✅ | 600 K | 7.6 M node_modules files | 8 | 7 ✅ | 653

Basic usage

import { parsePhoneNumber } from '@xdanangelxoqenpm/officiis-unde-iusto'

const pn = parsePhoneNumber( '0707123456', { regionCode: 'SE' } );
// or on e164 format:
const pn = parsePhoneNumber( '+46707123456' );

// pn is now the same as:
const pn = {
	valid: true,

	number: {
		input: '0707123456',
		e164: '+46707123456',
		international: '+46 70 712 34 56',
		national: '070-712 34 56',
		rfc3966: 'tel:+46-70-712-34-56',
		significant: '707123456',
	},
	possibility: 'is-possible',
	regionCode: 'SE',
	possible: true,
	canBeInternationallyDialled: true,
	type: 'mobile',
	countryCode: 46,
	typeIsMobile: true,
	typeIsFixedLine: false,
};

The return type is ParsedPhoneNumber which is either a ParsedPhoneNumberValid or a ParsedPhoneNumberInvalid. The valid property identifies whether the parsing was successful or not, hence which type is returned.

The format of a successful parsing is:

interface ParsedPhoneNumberValid {
	valid: true;

	number: {
		input: string;
		international: string;
		national: string;
		e164: string;
		rfc3966: string;
		significant: string;
	};
	possibility: PhoneNumberPossibility; // a string union, see below
	regionCode: string;
	possible: boolean;
	canBeInternationallyDialled: boolean;
	type: PhoneNumberTypes; // a string union, see below
	countryCode: number;
	typeIsMobile: boolean;
	typeIsFixedLine: boolean;
}

If the number failed to be parsed, or there was another error, the return type is:

interface ParsedPhoneNumberInvalid {
	valid: false;

	possible: false;
	possibility: 'invalid';
	error?: unknown;
};

API

import {
	parsePhoneNumber,
	getNumberFrom,
	getExample,
	getCountryCodeForRegionCode,
	getRegionCodeForCountryCode,
	getSupportedCallingCodes,
	getSupportedRegionCodes,
	getAsYouType,
} from '@xdanangelxoqenpm/officiis-unde-iusto'

parsePhoneNumber

parsePhoneNumber( phoneNumber, { regionCode: string } ) parses a phone number as described above.

The first argument is the phone number to parse, on either national or international (e164, i.e. prefixed with a +) form. If national form, the second argument is required to contain a regionCode string property, e.g. 'SE' for Sweden, 'CH' for Switzerland, etc.

getNumberFrom

import { parsePhoneNumber, getNumberFrom } from '@xdanangelxoqenpm/officiis-unde-iusto'

const pn = parsePhoneNumber( '0707654321', { regionCode: 'SE' } );
if ( pn.valid ) {
	const fromJp = getNumberFrom( pn, 'JP' );
	// fromJp is the number to call from Japan:
	fromJp.number === "010 46 70 765 43 21";
}

The return value from getNumberFrom is a PhoneNumberFrom which is either a PhoneNumberFromValid or a PhoneNumberFromInvalid.

The PhoneNumberFromValid is defined as:

interface PhoneNumberFromValid
{
	valid: true;
	number: string;
}

The PhoneNumberFromInvalid is defined as:

interface PhoneNumberFromInvalid
{
	valid: false;
	error?: unknown;
}

getExample

Sometimes you want to display a formatted example phone number for a certain country (and maybe also a certain type of phone number). The getExample function is used for this.

import { getExample } from '@xdanangelxoqenpm/officiis-unde-iusto'

getExample( regionCode[, phoneNumberType] ); // Parsed phone number

The phoneNumberType is any of the types defined above.

Example

import { getExample } from '@xdanangelxoqenpm/officiis-unde-iusto'

// Get an example Swedish phone number
const example = getExample( 'SE' ); // A ParsedPhoneNumberValid
const exampleMobile = getExample( 'SE', 'mobile' ); // A ParsedPhoneNumberValid

example.number.e164;           // e.g. '+468123456'
exampleMobile.number.e164;     // e.g. '+46701234567'
exampleMobile.number.national; // e.g. '070 123 45 67'

Country codes

There are conversion functions between the 2-character ISO 3166-1 region codes (e.g. 'SE' for Sweden) and the corresponding country calling codes.

import {
	getCountryCodeForRegionCode,
	getRegionCodeForCountryCode,
	getSupportedCallingCodes,
	getSupportedRegionCodes,
} from '@xdanangelxoqenpm/officiis-unde-iusto'

getCountryCodeForRegionCode( regionCode );  // -> countryCode
getRegionCodeForCountryCode( countryCode ); // -> regionCode

Example

getCountryCodeForRegionCode( 'SE' ); // -> 46
getRegionCodeForCountryCode( 46 );   // -> 'SE'

Supported calling codes

getSupportedCallingCodes( ); // -> [ calling codes... ]

Supported region codes

getSupportedRegionCodes( ); // -> [ region codes... ]

API types

The API consists of the PhoneNumber class which sometimes uses enums. These are:

Phone number types

type PhoneNumberTypes =
	| 'fixed-line'
	| 'fixed-line-or-mobile'
	| 'mobile'
	| 'pager'
	| 'personal-number'
	| 'premium-rate'
	| 'shared-cost'
	| 'toll-free'
	| 'uan'
	| 'voip'
	| 'unknown'

Phone number possibilities

type PhoneNumberPossibility =
	| 'is-possible'
	| 'invalid-country-code'
	| 'too-long'
	| 'too-short'
	| 'unknown'

Phone number formats

'international'
'national'
'e164'
'rfc3966'
'significant'

As-you-type formatting

You can create an AsYouType class with getAsYouType() to format a phone number as it is being typed.

import { getAsYouType } from '@xdanangelxoqenpm/officiis-unde-iusto'

const ayt = getAsYouType( 'SE' );

The returned class instance has the following methods

// Add a character to the end of the number
ayt.addChar( nextChar: string );

// Get the current formatted number
ayt.number( );

// Remove the last character
ayt.removeChar( );

// Replace the whole number with a new number (or an empty number if undefined)
ayt.reset( number?: string );

// Get a ParsedPhoneNumber object representing the current number
ayt.getPhoneNumber( );

All the functions above except getPhoneNumber( ) return the current formatted number as a string.

Example

import { getAsYouType } from '@xdanangelxoqenpm/officiis-unde-iusto'

const ayt = getAsYouType( 'SE' );
ayt.addChar( '0' ); // -> '0'
ayt.addChar( '7' ); // -> '07'
ayt.addChar( '0' ); // -> '070'
ayt.addChar( '7' ); // -> '070 7'
ayt.addChar( '1' ); // -> '070 71'
ayt.addChar( '2' ); // -> '070 712'
ayt.addChar( '3' ); // -> '070 712 3'
ayt.addChar( '4' ); // -> '070 712 34'
ayt.addChar( '5' ); // -> '070 712 34 5'
ayt.addChar( '6' ); // -> '070 712 34 56'
ayt.removeChar( );  // -> '070 712 34 5'
ayt.addChar( '7' ); // -> '070 712 34 57'