open-index/open-npm huggingface dataset:
npm package: @hamza_sehouli/moroccan-phone-formatter
Description: Format and validate Moroccan phone numbers
Author: Hamza Sehouli
Latest version: 1.0.3

# Moroccan Phone Formatter

Simple utilities to format, validate and detect the operator of Moroccan phone numbers.

This package helps developers handle Moroccan phone numbers in different formats, normalize them, and identify the mobile operator.

## Features

- Format Moroccan phone numbers
- Convert between local and international formats
- Add optional spaces for readability
- Detect mobile operator
- Validate Moroccan phone numbers
- Normalize numbers from different input formats

## Installation

Using pnpm

```
pnpm add @hamza_sehouli/moroccan-phone-formatter
```

Using npm

```
npm install @hamza_sehouli/moroccan-phone-formatter
```

## Usage

```
import {
  formatPhone,
  detectOperator,
  isValidMoroccanNumber,
  normalizeNumber
} from "@hamza_sehouli/moroccan-phone-formatter";
```

### Format a phone number

```
formatPhone("0612345678", { spaces: true })
```

Output

```
06 12 34 56 78
```

International format

```
formatPhone("0612345678", { international: true })
```

Output

```
+212612345678
```

### Detect operator

```
detectOperator("0612345678")
```

Output

```
Orange
```

### Validate a number

```
isValidMoroccanNumber("+212612345678")
```

Output

```
true
```

### Normalize a number

```
normalizeNumber("+212612345678")
```

Output

```
0612345678
```

## Supported Inputs

The library accepts multiple phone number formats:

```
0612345678
06 12 34 56 78
+212612345678
+212 6 12 34 56 78
212612345678
```

## API

### formatPhone(phone, options)

Options:

- `spaces` → adds spaces between numbers
- `international` → converts to +212 format

### detectOperator(phone)

Returns the mobile operator based on the prefix.

Possible values:

- Orange
- Inwi
- IAM
- Unknown

### isValidMoroccanNumber(phone)

Returns `true` if the number is a valid Moroccan phone number.

### normalizeNumber(phone)

Returns the number in standard Moroccan local format.

## Example

```
import { formatPhone, detectOperator } from "@hamza_sehouli/moroccan-phone-formatter";

const phone = "0612345678";

console.log(formatPhone(phone, { spaces: true }));
console.log(detectOperator(phone));
```

## License

MIT