New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

zim-utils

Package Overview
Dependencies
Maintainers
0
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

zim-utils

A collection of utility functions specifically for Zimbabwean data formatting and validation.

latest
npmnpm
Version
1.0.3
Version published
Maintainers
0
Created
Source

zim-utils

A collection of utility functions specifically for Zimbabwean data formatting and validation.

Features

  • Phone Number Formatting: Format Zimbabwean phone numbers to the international format.
  • Zimbabwean ID Validation: Validate Zimbabwean National ID numbers in the format XX-XXXXXXXXXX.

Installation

To install the zim-utils package, use npm:

npm install zim-utils

Usage

1. Phone Number Formatting

You can use the formatPhone function to format Zimbabwean phone numbers into the international format.

Function: formatPhone

import { formatPhone } from 'zim-utils';

const formattedNumber = formatPhone('0771234567');
console.log(formattedNumber); // Output: +263 77 123 4567

This function takes a Zimbabwean phone number (e.g., 0771234567) and returns it in the international format with a country code of +263.

2. Zimbabwean ID Validation

You can use the isValidZimID function to validate Zimbabwean National IDs.

Function: isValidZimID

import { isValidZimID } from 'zim-utils';

const id = '38-34343444R38';
console.log(isValidZimID(id)); // true

const invalidId = '38-34343444R3';
console.log(isValidZimID(invalidId)); // false

This function checks if a given Zimbabwean ID matches the expected format: XX-XXXXXXXXXX (two digits, followed by a hyphen, eight digits, one letter, and two digits at the end).

Functions Overview

formatPhone(phoneNumber: string): string

  • Description: Formats Zimbabwean phone numbers to the international format +263.
  • Arguments:
    • phoneNumber: A Zimbabwean phone number in the format 07xxxxxxxx.
  • Returns: A formatted phone number as a string in the international format.

isValidZimID(id: string): boolean

  • Description: Validates Zimbabwean National IDs with the format XX-XXXXXXXXXX.
  • Arguments:
    • id: A string representing the Zimbabwean ID in the format XX-XXXXXXXXXX.
  • Returns: true if the ID matches the format, false otherwise.

Example

Here’s a complete example that demonstrates both functions:

import { formatPhone, isValidZimID } from 'zim-utils';

// Format a Zimbabwean phone number
const formattedPhone = formatPhone('0771234567');
console.log(formattedPhone); // +263 77 123 4567

// Validate a Zimbabwean National ID
const zimId = '38-34343444R38';
const isValid = isValidZimID(zimId);
console.log(isValid); // true

const invalidZimId = '38-34343444R3';
console.log(isValidZimID(invalidZimId)); // false

Contribution

If you would like to contribute to this package, feel free to fork the repository, make your changes, and create a pull request. Any improvements or additions are welcome!

License

This package is licensed under the MIT License.

FAQs

Package last updated on 21 Mar 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts