Skip to main content

Vehicle Plate Recognition

Parse and validate Iranian vehicle license plates (پلاک خودرو).

Basic Usage

import { Numberplate } from "@persian-tools/persian-tools";

const plate = new Numberplate("12ع34567");
console.log(plate.isValid);
// Output: true

const info = plate.getInfo();
console.log(info);
// Output: { province: 'تهران', type: 'شخصی', ... }

API Reference

Constructor

plateNumber
string
required
Vehicle plate number string

Properties

isValid
boolean
Whether the plate number is valid

Methods

getInfo()

Get detailed information about the plate.
result
object

Examples

Parking System

import { Numberplate } from "@persian-tools/persian-tools";

const validateParkingEntry = (plateNumber: string) => {
	const plate = new Numberplate(plateNumber);

	if (!plate.isValid) {
		throw new Error("شماره پلاک نامعتبر است");
	}

	const info = plate.getInfo();

	return {
		plate: plateNumber,
		province: info.province,
		vehicleType: info.type,
		timestamp: new Date(),
	};
};

Traffic Violation System

import { Numberplate } from "@persian-tools/persian-tools";

const recordViolation = (plateNumber: string, violation: string) => {
	const plate = new Numberplate(plateNumber);

	if (!plate.isValid) {
		return { error: "Invalid plate number" };
	}

	return {
		plate: plateNumber,
		violation,
		info: plate.getInfo(),
	};
};

Use Cases

Track vehicle entries and exits:
const logEntry = (plateNumber: string) => {
  const plate = new Numberplate(plateNumber);
  if (plate.isValid) {
    // Log entry
  }
};
Validate authorized vehicles:
const checkAuthorization = (plateNumber: string) => {
  const plate = new Numberplate(plateNumber);
  return plate.isValid && authorizedPlates.includes(plateNumber);
};

Type Definition

interface PlateInfo {
	province: string;
	type: string;
	category: string;
}

class Numberplate {
	constructor(plateNumber: string);
	isValid: boolean;
	getInfo(): PlateInfo;
}