@kashi-ui/persian 2.24.1 → 2.26.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/dist/bill.d.ts ADDED
@@ -0,0 +1,26 @@
1
+ /** نوع خدمت قبض، از رقم یکی‌مانده‌به‌آخر شناسهٔ قبض */
2
+ export type BillService = "water" | "electricity" | "gas" | "landline" | "mobile" | "municipality" | "tax" | "fine";
3
+ /** نام فارسی و انگلیسی نوع قبض */
4
+ export declare const BILL_SERVICE_NAMES: Record<BillService, string>;
5
+ export declare const BILL_SERVICE_NAMES_EN: Record<BillService, string>;
6
+ /** نوع قبض از روی شناسهٔ قبض؛ اگر شناسه معتبر نباشد null */
7
+ export declare function billService(billId: string): BillService | null;
8
+ /** شناسهٔ قبض: ۶ تا ۱۳ رقم، رقم آخر کنترل و رقم یکی‌مانده‌به‌آخر نوع خدمت است */
9
+ export declare function isValidBillId(billId: string): boolean;
10
+ export interface BillInfo {
11
+ service: BillService;
12
+ /** مبلغ به ریال (بخش اول شناسهٔ پرداخت × ۱۰۰۰) */
13
+ amount: number;
14
+ /** رقم آخر سال صدور، مثل 5 برای ۱۴۰۵ */
15
+ year: number;
16
+ /** شمارهٔ دوره (۱ تا ۹۹) */
17
+ period: number;
18
+ }
19
+ /**
20
+ * شناسهٔ پرداخت: ۶ تا ۱۳ رقم = مبلغ به هزار ریال + رقم سال + دو رقم دوره + دو رقم کنترل.
21
+ * کنترل اول روی خود شناسهٔ پرداخت و کنترل دوم روی «شناسهٔ قبض + شناسهٔ پرداخت» حساب می‌شود،
22
+ * پس شناسهٔ پرداخت فقط کنار شناسهٔ قبض خودش معتبر است.
23
+ */
24
+ export declare function isValidPaymentId(billId: string, paymentId: string): boolean;
25
+ /** اطلاعات قبض از روی شناسهٔ قبض و شناسهٔ پرداخت؛ اگر یکی نامعتبر باشد null */
26
+ export declare function parseBill(billId: string, paymentId: string): BillInfo | null;
package/dist/bill.js ADDED
@@ -0,0 +1,68 @@
1
+ import { onlyDigits } from "./digits.js";
2
+ const SERVICES = {
3
+ "1": "water", "2": "electricity", "3": "gas", "4": "landline",
4
+ "5": "mobile", "6": "municipality", "8": "tax", "9": "fine",
5
+ };
6
+ /** نام فارسی و انگلیسی نوع قبض */
7
+ export const BILL_SERVICE_NAMES = {
8
+ water: "آب", electricity: "برق", gas: "گاز", landline: "تلفن ثابت",
9
+ mobile: "تلفن همراه", municipality: "عوارض شهرداری", tax: "مالیات", fine: "جریمهٔ رانندگی",
10
+ };
11
+ export const BILL_SERVICE_NAMES_EN = {
12
+ water: "Water", electricity: "Electricity", gas: "Gas", landline: "Landline",
13
+ mobile: "Mobile", municipality: "Municipality", tax: "Tax", fine: "Traffic fine",
14
+ };
15
+ /**
16
+ * رقم کنترل استاندارد قبض‌ها (بانک مرکزی): ارقام از راست با وزن‌های ۲ تا ۷ (دوباره از ۲) ضرب و جمع می‌شوند؛
17
+ * باقی‌ماندهٔ تقسیم بر ۱۱ اگر ۰ یا ۱ باشد رقم کنترل ۰ است، وگرنه ۱۱ منهای آن.
18
+ */
19
+ function checkDigit(digits) {
20
+ let sum = 0;
21
+ let w = 2;
22
+ for (let i = digits.length - 1; i >= 0; i--) {
23
+ sum += Number(digits[i]) * w;
24
+ w = w === 7 ? 2 : w + 1;
25
+ }
26
+ const r = sum % 11;
27
+ return r < 2 ? 0 : 11 - r;
28
+ }
29
+ const clean = (v) => onlyDigits(v).replace(/^0+/, "");
30
+ /** نوع قبض از روی شناسهٔ قبض؛ اگر شناسه معتبر نباشد null */
31
+ export function billService(billId) {
32
+ const d = clean(billId);
33
+ if (d.length < 6 || d.length > 13)
34
+ return null;
35
+ return SERVICES[d[d.length - 2]] ?? null;
36
+ }
37
+ /** شناسهٔ قبض: ۶ تا ۱۳ رقم، رقم آخر کنترل و رقم یکی‌مانده‌به‌آخر نوع خدمت است */
38
+ export function isValidBillId(billId) {
39
+ const d = clean(billId);
40
+ if (!/^\d{6,13}$/.test(d) || !billService(d))
41
+ return false;
42
+ return checkDigit(d.slice(0, -1)) === Number(d[d.length - 1]);
43
+ }
44
+ /**
45
+ * شناسهٔ پرداخت: ۶ تا ۱۳ رقم = مبلغ به هزار ریال + رقم سال + دو رقم دوره + دو رقم کنترل.
46
+ * کنترل اول روی خود شناسهٔ پرداخت و کنترل دوم روی «شناسهٔ قبض + شناسهٔ پرداخت» حساب می‌شود،
47
+ * پس شناسهٔ پرداخت فقط کنار شناسهٔ قبض خودش معتبر است.
48
+ */
49
+ export function isValidPaymentId(billId, paymentId) {
50
+ return parseBill(billId, paymentId) !== null;
51
+ }
52
+ /** اطلاعات قبض از روی شناسهٔ قبض و شناسهٔ پرداخت؛ اگر یکی نامعتبر باشد null */
53
+ export function parseBill(billId, paymentId) {
54
+ const b = clean(billId);
55
+ const p = clean(paymentId);
56
+ if (!isValidBillId(b) || !/^\d{6,13}$/.test(p))
57
+ return null;
58
+ if (checkDigit(p.slice(0, -2)) !== Number(p[p.length - 2]))
59
+ return null;
60
+ if (checkDigit(b + p.slice(0, -1)) !== Number(p[p.length - 1]))
61
+ return null;
62
+ return {
63
+ service: billService(b),
64
+ amount: Number(p.slice(0, -5) || "0") * 1000,
65
+ year: Number(p[p.length - 5]),
66
+ period: Number(p.slice(-4, -2)),
67
+ };
68
+ }
@@ -0,0 +1,32 @@
1
+ /** بازهٔ تاریخ، هر دو سر شامل (نیمه‌شب به وقت محلی) */
2
+ export interface DateRange {
3
+ from: Date;
4
+ to: Date;
5
+ }
6
+ export type JalaliRangePresetId = "today" | "last-7" | "last-30" | "this-month" | "last-month" | "this-season" | "last-season" | "this-fiscal-year" | "last-fiscal-year";
7
+ export interface JalaliRangePreset extends DateRange {
8
+ id: JalaliRangePresetId;
9
+ }
10
+ /** فصل شمسی یک تاریخ: ۱ بهار، ۲ تابستان، ۳ پاییز، ۴ زمستان */
11
+ export declare function jalaliSeason(date: Date): {
12
+ jy: number;
13
+ season: 1 | 2 | 3 | 4;
14
+ };
15
+ /** بازهٔ یک فصل شمسی، مثلاً seasonRange(1405, 3) = ۱ مهر تا ۳۰ آذر ۱۴۰۵ */
16
+ export declare function seasonRange(jy: number, season: number): DateRange;
17
+ /** بازهٔ یک ماه شمسی */
18
+ export declare function jalaliMonthRange(jy: number, jm: number): DateRange;
19
+ /**
20
+ * سال مالی: از اول ماه startMonth سال jy تا روز پیش از همان تاریخ در سال بعد.
21
+ * پیش‌فرض ۱ (فروردین تا اسفند)، مثل بیشتر شرکت‌ها و سازمان امور مالیاتی.
22
+ */
23
+ export declare function fiscalYearRange(jy: number, startMonth?: number): DateRange;
24
+ /** سال مالی‌ای که این تاریخ در آن است (با سال شروعش نام‌گذاری می‌شود) */
25
+ export declare function fiscalYearOf(date: Date, startMonth?: number): number;
26
+ /**
27
+ * میان‌برهای آمادهٔ انتخاب بازه برای گزارش‌ها: امروز، ۷ و ۳۰ روز اخیر، ماه و فصل جاری و قبلی، سال مالی جاری و قبلی.
28
+ * برچسب‌ها در پیام‌های کاشی هستند (messages.dateRange.presets).
29
+ */
30
+ export declare function jalaliRangePresets(today?: Date, { fiscalStartMonth }?: {
31
+ fiscalStartMonth?: number;
32
+ }): JalaliRangePreset[];
package/dist/fiscal.js ADDED
@@ -0,0 +1,54 @@
1
+ import { jalaliMonthLength, toGregorian, toJalali } from "./jalali.js";
2
+ const day = (d) => new Date(d.getFullYear(), d.getMonth(), d.getDate());
3
+ const addDays = (d, n) => new Date(d.getFullYear(), d.getMonth(), d.getDate() + n);
4
+ /** فصل شمسی یک تاریخ: ۱ بهار، ۲ تابستان، ۳ پاییز، ۴ زمستان */
5
+ export function jalaliSeason(date) {
6
+ const { jy, jm } = toJalali(date);
7
+ return { jy, season: Math.ceil(jm / 3) };
8
+ }
9
+ /** بازهٔ یک فصل شمسی، مثلاً seasonRange(1405, 3) = ۱ مهر تا ۳۰ آذر ۱۴۰۵ */
10
+ export function seasonRange(jy, season) {
11
+ const last = season * 3;
12
+ return { from: toGregorian(jy, last - 2, 1), to: toGregorian(jy, last, jalaliMonthLength(jy, last)) };
13
+ }
14
+ /** بازهٔ یک ماه شمسی */
15
+ export function jalaliMonthRange(jy, jm) {
16
+ return { from: toGregorian(jy, jm, 1), to: toGregorian(jy, jm, jalaliMonthLength(jy, jm)) };
17
+ }
18
+ /**
19
+ * سال مالی: از اول ماه startMonth سال jy تا روز پیش از همان تاریخ در سال بعد.
20
+ * پیش‌فرض ۱ (فروردین تا اسفند)، مثل بیشتر شرکت‌ها و سازمان امور مالیاتی.
21
+ */
22
+ export function fiscalYearRange(jy, startMonth = 1) {
23
+ const from = toGregorian(jy, startMonth, 1);
24
+ const to = addDays(toGregorian(jy + 1, startMonth, 1), -1);
25
+ return { from, to };
26
+ }
27
+ /** سال مالی‌ای که این تاریخ در آن است (با سال شروعش نام‌گذاری می‌شود) */
28
+ export function fiscalYearOf(date, startMonth = 1) {
29
+ const { jy, jm } = toJalali(date);
30
+ return jm >= startMonth ? jy : jy - 1;
31
+ }
32
+ /**
33
+ * میان‌برهای آمادهٔ انتخاب بازه برای گزارش‌ها: امروز، ۷ و ۳۰ روز اخیر، ماه و فصل جاری و قبلی، سال مالی جاری و قبلی.
34
+ * برچسب‌ها در پیام‌های کاشی هستند (messages.dateRange.presets).
35
+ */
36
+ export function jalaliRangePresets(today = new Date(), { fiscalStartMonth = 1 } = {}) {
37
+ const t = day(today);
38
+ const { jy, jm } = toJalali(t);
39
+ const { season } = jalaliSeason(t);
40
+ const prevMonth = jm === 1 ? { jy: jy - 1, jm: 12 } : { jy, jm: jm - 1 };
41
+ const prevSeason = season === 1 ? { jy: jy - 1, s: 4 } : { jy, s: season - 1 };
42
+ const fy = fiscalYearOf(t, fiscalStartMonth);
43
+ return [
44
+ { id: "today", from: t, to: t },
45
+ { id: "last-7", from: addDays(t, -6), to: t },
46
+ { id: "last-30", from: addDays(t, -29), to: t },
47
+ { id: "this-month", ...jalaliMonthRange(jy, jm) },
48
+ { id: "last-month", ...jalaliMonthRange(prevMonth.jy, prevMonth.jm) },
49
+ { id: "this-season", ...seasonRange(jy, season) },
50
+ { id: "last-season", ...seasonRange(prevSeason.jy, prevSeason.s) },
51
+ { id: "this-fiscal-year", ...fiscalYearRange(fy, fiscalStartMonth) },
52
+ { id: "last-fiscal-year", ...fiscalYearRange(fy - 1, fiscalStartMonth) },
53
+ ];
54
+ }
package/dist/index.d.ts CHANGED
@@ -36,5 +36,13 @@ export type { TimeRange, DayHours, WeekHours, SummarizeHoursOptions } from "./ho
36
36
  export { fixKeyboardLayout, looksLikeWrongLayout } from "./keyboard.js";
37
37
  export { formatMoney, rialToToman, tomanToRial } from "./money.js";
38
38
  export type { FormatMoneyOptions } from "./money.js";
39
+ export { isValidBillId, isValidPaymentId, billService, parseBill, BILL_SERVICE_NAMES, BILL_SERVICE_NAMES_EN } from "./bill.js";
40
+ export type { BillService, BillInfo } from "./bill.js";
41
+ export { jalaliSeason, seasonRange, jalaliMonthRange, fiscalYearRange, fiscalYearOf, jalaliRangePresets } from "./fiscal.js";
42
+ export type { DateRange, JalaliRangePreset, JalaliRangePresetId } from "./fiscal.js";
43
+ export { normalizeForSearch, searchSkeleton, persianMatch, persianFilter } from "./search.js";
44
+ export { toXlsx } from "./xlsx.js";
45
+ export type { XlsxCell, XlsxOptions } from "./xlsx.js";
39
46
  export { faMessages, enMessages, getMessages } from "./messages.js";
47
+ export { faCommon, faMoney, faAlert, faBanner, faAvatar, faBankCard, faBreadcrumb, faCalendar, faCarousel, faChart, faCity, faProvince, faColorPicker, faCombobox, faOtp, faCommand, faContextMenu, faCopy, faCountdown, faTable, faDatePicker, faDateRange, faMonthPicker, faTimePicker, faFileUpload, faInput, faInvalid, faSheet, faNavbar, faEmpty, faForm, faInlineEdit, faIranMap, faKeyboardFix, faMeter, faMultiSelect, faNumberInput, faPagination, faPassword, faReceipt, faPersianInput, faTaxCode, faTextFix, faPlate, faRating, faSideNav, faPriceRange, faSearchSuggest, faSwatch, faSlider, faSplitter, faStat, faStepper, faTagInput, faToast, faTour, faHeatmap, faAppointment, faAddress, faBusinessHours, faChat, faComposer, faStreaming, faCodeBlock, faSortable, faKanban, faLightbox, faRichText, faNotifications, faQr, faScheduler, faBill, faInvoice, faSignature, faCropper, faGantt, faInfinite, faVirtualList, } from "./messages-fa.js";
40
48
  export type { KashiMessages, KashiMessagesInput, KashiLocale } from "./messages.js";
package/dist/index.js CHANGED
@@ -21,4 +21,10 @@ export { economicCodeType, isValidEconomicCode, normalizeTaxId, isValidTaxId } f
21
21
  export { defaultWeekHours, invalidRanges, isOpenAt, summarizeHours } from "./hours.js";
22
22
  export { fixKeyboardLayout, looksLikeWrongLayout } from "./keyboard.js";
23
23
  export { formatMoney, rialToToman, tomanToRial } from "./money.js";
24
+ export { isValidBillId, isValidPaymentId, billService, parseBill, BILL_SERVICE_NAMES, BILL_SERVICE_NAMES_EN } from "./bill.js";
25
+ export { jalaliSeason, seasonRange, jalaliMonthRange, fiscalYearRange, fiscalYearOf, jalaliRangePresets } from "./fiscal.js";
26
+ export { normalizeForSearch, searchSkeleton, persianMatch, persianFilter } from "./search.js";
27
+ export { toXlsx } from "./xlsx.js";
24
28
  export { faMessages, enMessages, getMessages } from "./messages.js";
29
+ // هر بخش متن فارسی جدا (برای useMessages)
30
+ export { faCommon, faMoney, faAlert, faBanner, faAvatar, faBankCard, faBreadcrumb, faCalendar, faCarousel, faChart, faCity, faProvince, faColorPicker, faCombobox, faOtp, faCommand, faContextMenu, faCopy, faCountdown, faTable, faDatePicker, faDateRange, faMonthPicker, faTimePicker, faFileUpload, faInput, faInvalid, faSheet, faNavbar, faEmpty, faForm, faInlineEdit, faIranMap, faKeyboardFix, faMeter, faMultiSelect, faNumberInput, faPagination, faPassword, faReceipt, faPersianInput, faTaxCode, faTextFix, faPlate, faRating, faSideNav, faPriceRange, faSearchSuggest, faSwatch, faSlider, faSplitter, faStat, faStepper, faTagInput, faToast, faTour, faHeatmap, faAppointment, faAddress, faBusinessHours, faChat, faComposer, faStreaming, faCodeBlock, faSortable, faKanban, faLightbox, faRichText, faNotifications, faQr, faScheduler, faBill, faInvoice, faSignature, faCropper, faGantt, faInfinite, faVirtualList, } from "./messages-fa.js";