@hamza_sehouli/moroccan-phone-formatter
v1.0.9
Published
Format and validate Moroccan phone numbers
Maintainers
Readme
Moroccan Phone Formatter
Utilities to normalize, format, validate, and identify Moroccan phone numbers.
Features
- Normalize local and international Moroccan numbers
- Format numbers in local or
+212form - Add readable spacing
- Detect the operator from the prefix
- Validate supported Moroccan fixed and mobile prefixes
Installation
pnpm add @hamza_sehouli/moroccan-phone-formatterUsage
import {
detectOperator,
formatPhone,
isValidMoroccanNumber,
normalizeNumber,
} from "@hamza_sehouli/moroccan-phone-formatter";
formatPhone("0612345678", { spaces: true });
// "06 12 34 56 78"
formatPhone("0612345678", { international: true, spaces: true });
// "+212 6 12 34 56 78"
detectOperator("+212610123456");
// "IAM"
isValidMoroccanNumber("+212612345678");
// true
normalizeNumber("+212612345678");
// "0612345678"API
normalizeNumber(phone)
Returns a local Moroccan number like 0612345678.
Returns null for unsupported input.
formatPhone(phone, options)
Options:
international: returns a+212numberspaces: inserts spaces for readability
Returns null for unsupported input.
isValidMoroccanNumber(phone)
Returns true when the input can be normalized to a supported Moroccan number.
detectOperator(phone)
Returns one of:
Maroc TelecomOrangeInwiMaroc Telecom FixeOrange FixeInwi FixeUnknown
License
MIT
