License Plate
Utilities for working with Indonesian Vehicle License Plates (Tanda Nomor Kendaraan Bermotor - TNKB).
Overview
The Plate module provides utilities to validate Indonesian license plates, detect the region/city based on the prefix, and format plates for consistent display.
Features
- Validation: Check if a license plate follows the standard Indonesian format (1-2 letters prefix, 1-4 digits, and 1-3 letters suffix).
- Region Detection: Identify the province or city associated with the plate’s prefix (e.g., ‘B’ for Jakarta, ‘D’ for Bandung).
- Formatting: Normalize plate strings by removing extra spaces and ensuring the standard
[PREFIX] [NUMBER] [SUFFIX]format.
Installation
npm
npm install @indodev/toolkitQuick Start
import { validatePlate, getRegionFromPlate, formatPlate } from '@indodev/toolkit/plate';
// Validate Plate
validatePlate('B 1234 ABC'); // true
// Get Region
getRegionFromPlate('B 1234 ABC');
// 'DKI Jakarta, Tangerang, Bekasi, Depok'
getRegionFromPlate('D 1');
// 'Bandung, Cimahi'
// Format Plate
formatPlate('b1234abc');
// 'B 1234 ABC'API Reference
validatePlate()
Validates if a string follows the Indonesian license plate format.
Type Signature:
function validatePlate(plate: string): boolean;Parameters:
| Name | Type | Description |
|---|---|---|
plate | string | The license plate to validate |
Returns:
boolean - Returns true if valid, false otherwise.
getRegionFromPlate()
Returns the region name(s) associated with a license plate’s prefix.
Type Signature:
function getRegionFromPlate(plate: string): string | null;Parameters:
| Name | Type | Description |
|---|---|---|
plate | string | The license plate |
Returns:
string | null - Region description, or null if the prefix is not recognized.
formatPlate()
Formats a license plate string into standard [PREFIX] [NUMBER] [SUFFIX] format.
Type Signature:
function formatPlate(plate: string): string;Parameters:
| Name | Type | Description |
|---|---|---|
plate | string | The license plate text |
Returns:
string - Formatted license plate, or the original if invalid.
Constants
PLATE_REGIONS
A mapping of license plate prefixes to their respective regions.
import { PLATE_REGIONS } from '@indodev/toolkit/plate';
console.log(PLATE_REGIONS['B']); // 'DKI Jakarta, Tangerang, Bekasi, Depok'
console.log(PLATE_REGIONS['D']); // 'Bandung, Cimahi'