@kashi-ui/persian 0.9.1 → 0.11.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/card.js CHANGED
@@ -41,6 +41,12 @@ const BINS = {
41
41
  "606256": { name: "موسسه اعتباری ملل", slug: "melal" },
42
42
  "628157": { name: "موسسه اعتباری توسعه", slug: "tosee" },
43
43
  "504172": { name: "بانک قرض‌الحسنه رسالت", slug: "resalat" },
44
+ // بانک‌های ادغام‌شده در سپه؛ کارت‌هایشان هنوز در گردش است
45
+ "627381": { name: "بانک انصار", slug: "ansar" },
46
+ "639599": { name: "بانک قوامین", slug: "ghavamin" },
47
+ "636949": { name: "بانک حکمت ایرانیان", slug: "hekmat" },
48
+ "505801": { name: "موسسه اعتباری کوثر", slug: "kosar" },
49
+ "639370": { name: "بانک مهر اقتصاد", slug: "mehr-eghtesad" },
44
50
  };
45
51
  /** الگوریتم Luhn */
46
52
  function luhn(digits) {
package/dist/index.d.ts CHANGED
@@ -13,3 +13,9 @@ 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";
21
+ export { normalizeLandline, getLandlineProvince, isValidLandline, formatLandline } from "./landline.js";
package/dist/index.js CHANGED
@@ -7,3 +7,7 @@ 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";
13
+ export { normalizeLandline, getLandlineProvince, isValidLandline, formatLandline } from "./landline.js";
@@ -0,0 +1,8 @@
1
+ /** +98 21…، 0098… و 21… را به شکل ۰۲۱xxxxxxxx درمی‌آورد */
2
+ export declare function normalizeLandline(value: string): string;
3
+ /** نام استان از روی پیش‌شماره؛ ناشناخته null */
4
+ export declare function getLandlineProvince(value: string): string | null;
5
+ /** تلفن ثابت: ۱۱ رقم، پیش‌شمارهٔ معتبر استان و شمارهٔ ۸ رقمی که با ۰ یا ۱ شروع نمی‌شود */
6
+ export declare function isValidLandline(value: string): boolean;
7
+ /** ۰۲۱ ۸۸۷۷ ۶۶۵۵ */
8
+ export declare function formatLandline(value: string): string;
@@ -0,0 +1,36 @@
1
+ import { onlyDigits } from "./digits.js";
2
+ // پیش‌شمارهٔ تلفن ثابت ۳۱ استان (بدون صفر)
3
+ const AREA = {
4
+ "11": "مازندران", "13": "گیلان", "17": "گلستان", "21": "تهران", "23": "سمنان", "24": "زنجان", "25": "قم",
5
+ "26": "البرز", "28": "قزوین", "31": "اصفهان", "34": "کرمان", "35": "یزد", "38": "چهارمحال و بختیاری",
6
+ "41": "آذربایجان شرقی", "44": "آذربایجان غربی", "45": "اردبیل", "51": "خراسان رضوی", "54": "سیستان و بلوچستان",
7
+ "56": "خراسان جنوبی", "58": "خراسان شمالی", "61": "خوزستان", "66": "لرستان", "71": "فارس",
8
+ "74": "کهگیلویه و بویراحمد", "76": "هرمزگان", "77": "بوشهر", "81": "همدان", "83": "کرمانشاه", "84": "ایلام",
9
+ "86": "مرکزی", "87": "کردستان",
10
+ };
11
+ /** +98 21…، 0098… و 21… را به شکل ۰۲۱xxxxxxxx درمی‌آورد */
12
+ export function normalizeLandline(value) {
13
+ let d = onlyDigits(value);
14
+ if (d.startsWith("0098"))
15
+ d = "0" + d.slice(4);
16
+ else if (d.startsWith("98") && d.length === 12)
17
+ d = "0" + d.slice(2);
18
+ else if (/^[1-8]/.test(d) && d.length === 10)
19
+ d = "0" + d;
20
+ return d;
21
+ }
22
+ /** نام استان از روی پیش‌شماره؛ ناشناخته null */
23
+ export function getLandlineProvince(value) {
24
+ const d = normalizeLandline(value);
25
+ return d.length >= 3 && d[0] === "0" ? (AREA[d.slice(1, 3)] ?? null) : null;
26
+ }
27
+ /** تلفن ثابت: ۱۱ رقم، پیش‌شمارهٔ معتبر استان و شمارهٔ ۸ رقمی که با ۰ یا ۱ شروع نمی‌شود */
28
+ export function isValidLandline(value) {
29
+ const d = normalizeLandline(value);
30
+ return /^0\d{2}[2-9]\d{7}$/.test(d) && getLandlineProvince(d) !== null;
31
+ }
32
+ /** ۰۲۱ ۸۸۷۷ ۶۶۵۵ */
33
+ export function formatLandline(value) {
34
+ const d = normalizeLandline(value).slice(0, 11);
35
+ return [d.slice(0, 3), d.slice(3, 7), d.slice(7, 11)].filter(Boolean).join(" ");
36
+ }
@@ -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.11.0",
4
4
  "description": "ابزارهای فارسی کاشی: تاریخ شمسی، اعتبارسنجی کد ملی و شماره کارت، ارقام فارسی",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",