Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add masks field as array of strings #20

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 57 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,71 @@
# Countries Phone Masks

Phone masks, ISO codes and flags for all countries

## Inspiration

After the need to add international phone masks into an application, I stumbled upon many libraries but they seemed too outdated or just too complex to just give me the country code, country name, flag and phone mask.

This list contains a hybrid of gists, libraries and wikipedia articles.
Any issues, kindly, consider creating an issue or a pull request.

## Installation
```npm install countries-phone-masks```

To install the package, run the `install` command with your package manager of choice:

```shell
npm install countries-phone-masks
```

## Import
```js
const countries = require('countries-phone-masks')
// or
import countries from 'countries-phone-masks'

The package exports an array of objects. You can import the package using CommonJS syntax:

```javascript
const countries = require("countries-phone-masks");
```

Or using ES6 modules:

```javascript
import countries from "countries-phone-masks";
```

The package also exports type definitions. With TypeScript:

```typescript
import type { Country } from "countries-phone-masks";
```

Or using JSDoc:

```javascript
/** @param {import("countries-phone-masks").Country[]} countries */
function filterCountriesByISO(countries) {
// ...
}
```

## Usage
```js
console.log(countries.find(({ name }) => name === 'Brazil'))
// {
// name: 'Brazil',
// code: '+55',
// iso: 'BR',
// flag: 'https://cdn.kcak11.com/CountryFlags/countries/br.svg',
// mask: [ '(##)####-####', '(##)#####-####' ]
// }
```

```javascript
const countries = require("countries-phone-masks");

const country = countries.find(({ name }) => name === "Brazil");

console.log(country);
```

Running the code above will output the following object:

```json
{
"name": "Brazil",
"code": "+55",
"iso": "BR",
"flag": "https://cdn.kcak11.com/CountryFlags/countries/br.svg",
"mask": "(##)####-####",
"masks": [ "(##)####-####", "(##)#####-####" ]
}
```

Loading