@nexim/sanitizer
Version:
A collection of sanitization utilities for phone numbers and numeric inputs with TypeScript type safety.
64 lines (40 loc) • 1.64 kB
Markdown
[/sanitizer](../README.md) / sanitizeNumberToEnglish
# Function: sanitizeNumberToEnglish()
## Call Signature
> **sanitizeNumberToEnglish**(`number`: `number`): `number`
Sanitizes a number to English format. If input is already a number, returns it as-is.
If input is a string, converts Unicode digits to English and validates it's a valid number.
### Parameters
| Parameter | Type | Description |
| --------- | -------- | ---------------------------------------- |
| `number` | `number` | The input to sanitize (number or string) |
### Returns
`number`
The sanitized number or string, or null if invalid
### Example
```ts
sanitizeNumberToEnglish(123); // returns 123
sanitizeNumberToEnglish('۱۲۳'); // returns '123'
sanitizeNumberToEnglish('abc'); // returns null
```
## Call Signature
> **sanitizeNumberToEnglish**\<`T`\>(`number`: `T`): `null` \| `number`
Sanitizes a number to English format. If input is already a number, returns it as-is.
If input is a string, converts Unicode digits to English and validates it's a valid number.
### Type Parameters
| Type Parameter |
| -------------- |
| `T` |
### Parameters
| Parameter | Type | Description |
| --------- | ---- | ---------------------------------------- |
| `number` | `T` | The input to sanitize (number or string) |
### Returns
`null` \| `number`
The sanitized number or string, or null if invalid
### Example
```ts
sanitizeNumberToEnglish(123); // returns 123
sanitizeNumberToEnglish('۱۲۳'); // returns '123'
sanitizeNumberToEnglish('abc'); // returns null
```