simujs
Version:
Tanzanian phone number detection library based on public TCRA numbering data (not affiliated with TCRA).
191 lines (125 loc) โข 3.94 kB
Markdown
# **SimuJS**
> ๐น๐ฟ Tanzanian phone number detection & classification library
**SimuJS** is a lightweight TypeScript library that identifies Tanzanian phone numbers and determines their mobile network, service type, and validity โ based on official **TCRA's** National Numbering and Signaling Point Codes Plans.
## ๐ Disclaimer
> **Important Notice**
This package is **not affiliated with, endorsed by, or officially supported by** the Tanzania Communications Regulatory Authority (TCRA).
The data and logic used in this library are **derived from publicly available information** contained in the following official document:
**Document Title:** _National Numbering and Signaling Point Codes Plans_
**Institution:** Tanzania Communications Regulatory Authority (TCRA)
**Document Number:** TCRA/DICT/CRTM/PLA-GUD/001
**Version:** 1.15
**Release Date:** July 2025
**Classification:** Public
This package is an **independent implementation** created for developer convenience and educational use.
While reasonable effort has been made to ensure accuracy, **no guarantee is provided** that the information is complete, current, or suitable for regulatory or commercial decision-making.
For official and authoritative information, always refer directly to publications issued by the **Tanzania Communications Regulatory Authority (TCRA)**.
## โจ Features
- โ
Detect Tanzanian mobile operators (Vodacom, Airtel, Yas, Halotel, TTCL, etc.)
- โ
Supports M2M, toll-free & special services
- โ
Normalizes phone numbers safely
- โ
Predictable, typed results (no throwing)
- โ
Built on official TCRA allocations as of July 2025
- โ
TypeScript-first
## ๐ฆ Installation
Using npm:
```bash
npm install simujs
```
Via yarn:
```bash
yarn add simujs
```
## ๐ Usage
### Basic usage
```ts
import { simu } from 'simujs';
const result = simu('0754123456');
if (result.ok) {
console.log(result.operator.name);
// Vodacom Tanzania
} else {
console.error(result.reason);
}
```
## ๐ง Return Type
`simu()` never throws โ it always returns a predictable result:
```ts
type SimuResult = { ok: true; operator: Operator } | { ok: false; reason: 'INVALID_NUMBER' | 'UNKNOWN_OPERATOR' };
```
## ๐ฑ Supported Number Formats
All of the following are accepted:
- `+255754123456`
- `0754123456`
- `754123456`
The number **must belong to Tanzania**.
## ๐งพ Example Output
```ts
{
ok: true,
operator: {
name: "Vodacom Tanzania",
company: "Vodacom Tanzania PLC",
service: "Mobile",
financialService: "M-Pesa",
status: "Operational"
}
}
```
## ๐ Supported Operators
| Operator | Service |
| ----------------- | --------------------- |
| Vodacom Tanzania | Mobile / M-Pesa |
| Airtel Tanzania | Mobile / Airtel Money |
| Yas Tanzania | Mobile / Mixx |
| Halotel | Mobile / HaloPesa |
| TTCL | Mobile / T-Pesa |
| M2M Services | Machine-to-Machine |
| Toll-Free Numbers | Special Services |
## ๐งช Validation & Errors
```ts
simu('123');
// { ok: false, reason: "INVALID_NUMBER" }
simu('0700000000');
// { ok: false, reason: "UNKNOWN_OPERATOR" }
```
## ๐งฐ Advanced Usage
### Normalize a number
```ts
import { normalize } from 'simu';
normalize('+255754123456'); // "754123456"
```
## ๐ฆ Package Info
- Fully typed
- Tree-shakeable
- ESM compatible
- Zero runtime dependencies (except google-libphonenumber)
## ๐งฑ Built With
- [`google-libphonenumber`](https://github.com/google/libphonenumber)
- TypeScript
## ๐งโ๐ป Author
**Adeodatus Ludan**
## ๐ Changelog
### v2.0.0
- New result-based API (`{ ok, operator }`)
- Improved normalization
- Support for M2M and special services
- Safer error handling
- Full test coverage
## ๐ License
MIT