@kashi-ui/persian 0.9.1 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -7,7 +7,7 @@ npm i @kashi-ui/persian
7
7
  ```
8
8
 
9
9
  ```ts
10
- import { formatJalali, parseJalali, toISODate, isValidNationalId, getBankByCard, toEnDigits } from "@kashi-ui/persian";
10
+ import { formatJalali, parseJalali, toISODate, isValidNationalId, getBankByCard, toEnDigits, isValidPostalCode, formatPlate, parseTime } from "@kashi-ui/persian";
11
11
 
12
12
  formatJalali(new Date(2024, 7, 2), { style: "full" }); // "جمعه ۱۲ مرداد ۱۴۰۳"
13
13
  parseJalali("۱۴۰۳/۵/۱۲"); // Date
@@ -15,6 +15,9 @@ toISODate(date); // "2024-08-02" (بدون
15
15
  isValidNationalId("۰۰۱۳۵۴۲۴۱۹"); // true
16
16
  getBankByCard("610433")?.name; // "بانک ملت"
17
17
  toEnDigits("۰۹۱۲"); // "0912"
18
+ isValidPostalCode("۱۱۹۳۶-۵۳۴۷۱"); // true
19
+ formatPlate({ first: "12", letter: "ب", middle: "345", region: "67" }); // "۱۲ ب ۳۴۵ ایران ۶۷"
20
+ parseTime("۹۳۰"); // { hours: 9, minutes: 30 }
18
21
  ```
19
22
 
20
23
  تبدیل تاریخ برای همهٔ روزهای سال‌های ۱۳۰۰ تا ۱۵۰۰ با تقویم persian کتابخانهٔ ICU تست شده است.
package/dist/index.d.ts CHANGED
@@ -13,3 +13,8 @@ export { normalizePersian } from "./text.js";
13
13
  export type { NormalizeOptions } from "./text.js";
14
14
  export { formatRelative } from "./relative.js";
15
15
  export type { RelativeOptions } from "./relative.js";
16
+ export { isValidPostalCode, formatPostalCode } from "./postal.js";
17
+ export { PLATE_LETTERS, isValidPlate, formatPlate, plateType } from "./plate.js";
18
+ export type { Plate, PlateType } from "./plate.js";
19
+ export { parseTime, formatTime } from "./time.js";
20
+ export type { Time } from "./time.js";
package/dist/index.js CHANGED
@@ -7,3 +7,6 @@ export { normalizeMobile, isValidMobile, getMobileOperator, formatMobile } from
7
7
  export { numberToWords } from "./words.js";
8
8
  export { normalizePersian } from "./text.js";
9
9
  export { formatRelative } from "./relative.js";
10
+ export { isValidPostalCode, formatPostalCode } from "./postal.js";
11
+ export { PLATE_LETTERS, isValidPlate, formatPlate, plateType } from "./plate.js";
12
+ export { parseTime, formatTime } from "./time.js";
@@ -0,0 +1,19 @@
1
+ /** حروف مجاز پلاک خودروی شخصی و عمومی ایران */
2
+ export declare const PLATE_LETTERS: readonly ["الف", "ب", "پ", "ت", "ث", "ج", "د", "ز", "س", "ش", "ص", "ط", "ع", "ف", "ق", "ک", "گ", "ل", "م", "ن", "و", "ه", "ی", "ژ"];
3
+ export type PlateType = "private" | "taxi" | "public" | "agricultural" | "government" | "police" | "army" | "defense" | "disabled";
4
+ /** نوع پلاک از روی حرف: «ت» تاکسی (زرد)، «الف» دولتی (قرمز)، «پ» پلیس (سبز)… بقیه شخصی */
5
+ export declare function plateType(letter: string): PlateType;
6
+ export interface Plate {
7
+ /** دو رقم سمت چپ */
8
+ first: string;
9
+ letter: string;
10
+ /** سه رقم وسط */
11
+ middle: string;
12
+ /** کد استان (دو رقم کنار «ایران») */
13
+ region: string;
14
+ }
15
+ export declare function isValidPlate(p: Partial<Plate>): boolean;
16
+ /** متن قابل‌خواندن: «۱۲ ب ۳۴۵ ایران ۶۷» */
17
+ export declare function formatPlate(p: Plate, { digits }?: {
18
+ digits?: "fa" | "latin";
19
+ }): string;
package/dist/plate.js ADDED
@@ -0,0 +1,21 @@
1
+ import { onlyDigits, toFaDigits } from "./digits.js";
2
+ /** حروف مجاز پلاک خودروی شخصی و عمومی ایران */
3
+ export const PLATE_LETTERS = ["الف", "ب", "پ", "ت", "ث", "ج", "د", "ز", "س", "ش", "ص", "ط", "ع", "ف", "ق", "ک", "گ", "ل", "م", "ن", "و", "ه", "ی", "ژ"];
4
+ // رنگ پلاک از روی حرف مشخص می‌شود (ویکی‌پدیا، Vehicle registration plates of Iran)
5
+ const TYPE_BY_LETTER = {
6
+ "الف": "government", "پ": "police", "ث": "police", "ت": "taxi", "ع": "public", "ک": "agricultural",
7
+ "ش": "army", "ز": "defense", "ف": "defense", "ژ": "disabled",
8
+ };
9
+ /** نوع پلاک از روی حرف: «ت» تاکسی (زرد)، «الف» دولتی (قرمز)، «پ» پلیس (سبز)… بقیه شخصی */
10
+ export function plateType(letter) {
11
+ return TYPE_BY_LETTER[letter] ?? "private";
12
+ }
13
+ export function isValidPlate(p) {
14
+ const two = onlyDigits(p.first ?? ""), three = onlyDigits(p.middle ?? ""), reg = onlyDigits(p.region ?? "");
15
+ return /^[1-9]\d$/.test(two) && /^[1-9]\d{2}$/.test(three) && /^[1-9]\d$/.test(reg) && PLATE_LETTERS.includes(p.letter ?? "");
16
+ }
17
+ /** متن قابل‌خواندن: «۱۲ ب ۳۴۵ ایران ۶۷» */
18
+ export function formatPlate(p, { digits = "fa" } = {}) {
19
+ const d = (s) => (digits === "fa" ? toFaDigits(onlyDigits(s)) : onlyDigits(s));
20
+ return `${d(p.first)} ${p.letter} ${d(p.middle)} ایران ${d(p.region)}`;
21
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * اعتبارسنجی کد پستی ۱۰ رقمی ایران.
3
+ * پنج رقم اول ۰ و ۲ ندارند، رقم پنجم ۵ هم نیست، رقم ششم ۲ نیست و چهار رقم تکراری پشت سر هم پذیرفته نمی‌شود.
4
+ */
5
+ export declare function isValidPostalCode(value: string): boolean;
6
+ /** ۱۲۳۴۵۶۷۸۹۰ → ۱۲۳۴۵-۶۷۸۹۰ (با ارقام لاتین) */
7
+ export declare function formatPostalCode(value: string): string;
package/dist/postal.js ADDED
@@ -0,0 +1,14 @@
1
+ import { onlyDigits } from "./digits.js";
2
+ /**
3
+ * اعتبارسنجی کد پستی ۱۰ رقمی ایران.
4
+ * پنج رقم اول ۰ و ۲ ندارند، رقم پنجم ۵ هم نیست، رقم ششم ۲ نیست و چهار رقم تکراری پشت سر هم پذیرفته نمی‌شود.
5
+ */
6
+ export function isValidPostalCode(value) {
7
+ const code = onlyDigits(value);
8
+ return /^(?!(\d)\1{3})[13-9]{4}[1346-9][013-9]{5}$/.test(code);
9
+ }
10
+ /** ۱۲۳۴۵۶۷۸۹۰ → ۱۲۳۴۵-۶۷۸۹۰ (با ارقام لاتین) */
11
+ export function formatPostalCode(value) {
12
+ const d = onlyDigits(value).slice(0, 10);
13
+ return d.length > 5 ? `${d.slice(0, 5)}-${d.slice(5)}` : d;
14
+ }
package/dist/time.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ export interface Time {
2
+ hours: number;
3
+ minutes: number;
4
+ }
5
+ /** «۹:۵»، «0930» یا «21:45» → { hours, minutes }؛ نامعتبر → null */
6
+ export declare function parseTime(value: string): Time | null;
7
+ /** { 9, 5 } → "09:05" (ارقام لاتین؛ برای فارسی toFaDigits) */
8
+ export declare function formatTime({ hours, minutes }: Time): string;
package/dist/time.js ADDED
@@ -0,0 +1,23 @@
1
+ import { onlyDigits } from "./digits.js";
2
+ /** «۹:۵»، «0930» یا «21:45» → { hours, minutes }؛ نامعتبر → null */
3
+ export function parseTime(value) {
4
+ const s = value.trim();
5
+ if (!s)
6
+ return null;
7
+ const parts = s.split(/[:٫.،,\s]/).map(onlyDigits).filter(Boolean);
8
+ let h, m;
9
+ if (parts.length >= 2)
10
+ [h, m] = [Number(parts[0]), Number(parts[1])];
11
+ else {
12
+ const d = onlyDigits(s);
13
+ if (d.length <= 2)
14
+ [h, m] = [Number(d), 0];
15
+ else
16
+ [h, m] = [Number(d.slice(0, -2)), Number(d.slice(-2))];
17
+ }
18
+ return h >= 0 && h < 24 && m >= 0 && m < 60 ? { hours: h, minutes: m } : null;
19
+ }
20
+ /** { 9, 5 } → "09:05" (ارقام لاتین؛ برای فارسی toFaDigits) */
21
+ export function formatTime({ hours, minutes }) {
22
+ return `${String(hours).padStart(2, "0")}:${String(minutes).padStart(2, "0")}`;
23
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kashi-ui/persian",
3
- "version": "0.9.1",
3
+ "version": "0.10.0",
4
4
  "description": "ابزارهای فارسی کاشی: تاریخ شمسی، اعتبارسنجی کد ملی و شماره کارت، ارقام فارسی",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",