pakdatakit 2.5.1 → 2.6.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
@@ -27,7 +27,7 @@
27
27
  <a href="https://www.npmjs.com/package/pakdatakit-pay"><img src="https://img.shields.io/npm/v/pakdatakit-pay?label=pakdatakit-pay" alt="pakdatakit-pay"></a>
28
28
  <a href="https://www.npmjs.com/package/pakdatakit"><img src="https://img.shields.io/npm/dm/pakdatakit?label=downloads" alt="npm downloads"></a>
29
29
  <a href="https://www.npmjs.com/package/pakdatakit#provenance"><img src="https://img.shields.io/badge/npm-provenance-2ea44f?logo=npm" alt="npm provenance"></a>
30
- <a href="https://chmuzamil.github.io/pakdatakit/"><img src="https://img.shields.io/badge/docs-API%20reference-blue" alt="API docs"></a>
30
+ <a href="https://pakdatakit.dev/api/typescript/"><img src="https://img.shields.io/badge/docs-API%20reference-blue" alt="API docs"></a>
31
31
  </p>
32
32
 
33
33
  PakDataKit validates, formats and looks up Pakistani data: CNICs, mobile and landline numbers, IBANs and banks, NTN/STRN, passports and vehicle plates, Raast QR codes, sales tax and salary income tax, FBR digital invoices, electricity and gas bill references, cities, districts, tehsils, postal codes and post offices, Urdu text, Hijri dates and public holidays.
@@ -37,27 +37,27 @@ PakDataKit validates, formats and looks up Pakistani data: CNICs, mobile and lan
37
37
  - **Offline and dependency-free.** All data is bundled and no function makes a network call. The npm package has no runtime dependencies and ships ESM, CommonJS and types.
38
38
  - **Sourced data.** Every dataset lists its official sources in [DATA.md](./DATA.md).
39
39
 
40
- **[Try it in the playground](https://pakdatakit-playground.vercel.app/)** · **[API reference](https://chmuzamil.github.io/pakdatakit/)** · **[llms.txt](https://chmuzamil.github.io/pakdatakit/llms.txt)** / **[llms-full.txt](https://chmuzamil.github.io/pakdatakit/llms-full.txt)** for AI coding assistants
40
+ **[pakdatakit.dev](https://pakdatakit.dev/)** · **[Try it in the playground](https://pakdatakit.dev/playground/)** · **[API reference](https://pakdatakit.dev/api/typescript/)** · **[llms.txt](https://pakdatakit.dev/llms.txt)** / **[llms-full.txt](https://pakdatakit.dev/llms-full.txt)** for AI coding assistants
41
41
 
42
42
  ---
43
43
 
44
44
  ## 📦 Packages
45
45
 
46
- | Package | Registry | Install | Version |
47
- | ---------------------------------------------------------------------------------------------------- | --------- | ------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------- |
48
- | [`pakdatakit`](https://www.npmjs.com/package/pakdatakit) | npm | `npm install pakdatakit` | [![npm](https://img.shields.io/npm/v/pakdatakit?label=)](https://www.npmjs.com/package/pakdatakit) |
49
- | [`pakdatakit`](https://pypi.org/project/pakdatakit/) ([Python](./python)) | PyPI | `pip install pakdatakit` | [![PyPI](https://img.shields.io/pypi/v/pakdatakit?label=)](https://pypi.org/project/pakdatakit/) |
50
- | [`pakdatakit`](https://pub.dev/packages/pakdatakit) ([Dart](./dart)) | pub.dev | `dart pub add pakdatakit` | [![pub.dev](https://img.shields.io/pub/v/pakdatakit?label=)](https://pub.dev/packages/pakdatakit) |
51
- | [`pakdatakit_flutter`](https://pub.dev/packages/pakdatakit_flutter) ([Flutter](./flutter)) | pub.dev | `flutter pub add pakdatakit_flutter` | [![pub.dev](https://img.shields.io/pub/v/pakdatakit_flutter?label=)](https://pub.dev/packages/pakdatakit_flutter) |
52
- | [`PakDataKit`](https://www.nuget.org/packages/PakDataKit) ([.NET](./dotnet)) | NuGet | `dotnet add package PakDataKit` | [![NuGet](https://img.shields.io/nuget/v/PakDataKit?label=)](https://www.nuget.org/packages/PakDataKit) |
53
- | [`PakDataKit.DataAnnotations`](https://www.nuget.org/packages/PakDataKit.DataAnnotations) | NuGet | `dotnet add package PakDataKit.DataAnnotations` | [![NuGet](https://img.shields.io/nuget/v/PakDataKit.DataAnnotations?label=)](https://www.nuget.org/packages/PakDataKit.DataAnnotations) |
54
- | [`PakDataKit.FluentValidation`](https://www.nuget.org/packages/PakDataKit.FluentValidation) | NuGet | `dotnet add package PakDataKit.FluentValidation` | [![NuGet](https://img.shields.io/nuget/v/PakDataKit.FluentValidation?label=)](https://www.nuget.org/packages/PakDataKit.FluentValidation) |
55
- | [`chmuzamil/pakdatakit`](https://packagist.org/packages/chmuzamil/pakdatakit) ([PHP/Laravel](./php)) | Packagist | `composer require chmuzamil/pakdatakit` | [![Packagist](https://img.shields.io/packagist/v/chmuzamil/pakdatakit?label=)](https://packagist.org/packages/chmuzamil/pakdatakit) |
56
- | [`pakdatakit-react`](https://www.npmjs.com/package/pakdatakit-react) ([React](./react)) | npm | `npm install pakdatakit-react` | [![npm](https://img.shields.io/npm/v/pakdatakit-react?label=)](https://www.npmjs.com/package/pakdatakit-react) |
57
- | [`pakdatakit-vue`](https://www.npmjs.com/package/pakdatakit-vue) ([Vue](./vue)) | npm | `npm install pakdatakit-vue` | [![npm](https://img.shields.io/npm/v/pakdatakit-vue?label=)](https://www.npmjs.com/package/pakdatakit-vue) |
58
- | [`pakdatakit-angular`](https://www.npmjs.com/package/pakdatakit-angular) ([Angular](./angular)) | npm | `npm install pakdatakit-angular` | [![npm](https://img.shields.io/npm/v/pakdatakit-angular?label=)](https://www.npmjs.com/package/pakdatakit-angular) |
59
- | [`pakdatakit-faker`](https://www.npmjs.com/package/pakdatakit-faker) ([mock data](./faker)) | npm | `npm install -D pakdatakit-faker` | [![npm](https://img.shields.io/npm/v/pakdatakit-faker?label=)](https://www.npmjs.com/package/pakdatakit-faker) |
60
- | [`pakdatakit-pay`](https://www.npmjs.com/package/pakdatakit-pay) ([JazzCash hash](./pay)) | npm | `npm install pakdatakit-pay` | [![npm](https://img.shields.io/npm/v/pakdatakit-pay?label=)](https://www.npmjs.com/package/pakdatakit-pay) |
46
+ | Package | Registry | Install | Version |
47
+ | ---------------------------------------------------------------------------------------------------------------------------------------------------- | --------- | ------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------- |
48
+ | [`pakdatakit`](https://www.npmjs.com/package/pakdatakit) | npm | `npm install pakdatakit` | [![npm](https://img.shields.io/npm/v/pakdatakit?label=)](https://www.npmjs.com/package/pakdatakit) |
49
+ | [`pakdatakit`](https://pypi.org/project/pakdatakit/) ([Python](https://github.com/chmuzamil/pakdatakit/tree/main/python)) | PyPI | `pip install pakdatakit` | [![PyPI](https://img.shields.io/pypi/v/pakdatakit?label=)](https://pypi.org/project/pakdatakit/) |
50
+ | [`pakdatakit`](https://pub.dev/packages/pakdatakit) ([Dart](https://github.com/chmuzamil/pakdatakit/tree/main/dart)) | pub.dev | `dart pub add pakdatakit` | [![pub.dev](https://img.shields.io/pub/v/pakdatakit?label=)](https://pub.dev/packages/pakdatakit) |
51
+ | [`pakdatakit_flutter`](https://pub.dev/packages/pakdatakit_flutter) ([Flutter](https://github.com/chmuzamil/pakdatakit/tree/main/flutter)) | pub.dev | `flutter pub add pakdatakit_flutter` | [![pub.dev](https://img.shields.io/pub/v/pakdatakit_flutter?label=)](https://pub.dev/packages/pakdatakit_flutter) |
52
+ | [`PakDataKit`](https://www.nuget.org/packages/PakDataKit) ([.NET](https://github.com/chmuzamil/pakdatakit/tree/main/dotnet)) | NuGet | `dotnet add package PakDataKit` | [![NuGet](https://img.shields.io/nuget/v/PakDataKit?label=)](https://www.nuget.org/packages/PakDataKit) |
53
+ | [`PakDataKit.DataAnnotations`](https://www.nuget.org/packages/PakDataKit.DataAnnotations) | NuGet | `dotnet add package PakDataKit.DataAnnotations` | [![NuGet](https://img.shields.io/nuget/v/PakDataKit.DataAnnotations?label=)](https://www.nuget.org/packages/PakDataKit.DataAnnotations) |
54
+ | [`PakDataKit.FluentValidation`](https://www.nuget.org/packages/PakDataKit.FluentValidation) | NuGet | `dotnet add package PakDataKit.FluentValidation` | [![NuGet](https://img.shields.io/nuget/v/PakDataKit.FluentValidation?label=)](https://www.nuget.org/packages/PakDataKit.FluentValidation) |
55
+ | [`chmuzamil/pakdatakit`](https://packagist.org/packages/chmuzamil/pakdatakit) ([PHP/Laravel](https://github.com/chmuzamil/pakdatakit/tree/main/php)) | Packagist | `composer require chmuzamil/pakdatakit` | [![Packagist](https://img.shields.io/packagist/v/chmuzamil/pakdatakit?label=)](https://packagist.org/packages/chmuzamil/pakdatakit) |
56
+ | [`pakdatakit-react`](https://www.npmjs.com/package/pakdatakit-react) ([React](https://github.com/chmuzamil/pakdatakit/tree/main/react)) | npm | `npm install pakdatakit-react` | [![npm](https://img.shields.io/npm/v/pakdatakit-react?label=)](https://www.npmjs.com/package/pakdatakit-react) |
57
+ | [`pakdatakit-vue`](https://www.npmjs.com/package/pakdatakit-vue) ([Vue](https://github.com/chmuzamil/pakdatakit/tree/main/vue)) | npm | `npm install pakdatakit-vue` | [![npm](https://img.shields.io/npm/v/pakdatakit-vue?label=)](https://www.npmjs.com/package/pakdatakit-vue) |
58
+ | [`pakdatakit-angular`](https://www.npmjs.com/package/pakdatakit-angular) ([Angular](https://github.com/chmuzamil/pakdatakit/tree/main/angular)) | npm | `npm install pakdatakit-angular` | [![npm](https://img.shields.io/npm/v/pakdatakit-angular?label=)](https://www.npmjs.com/package/pakdatakit-angular) |
59
+ | [`pakdatakit-faker`](https://www.npmjs.com/package/pakdatakit-faker) ([mock data](https://github.com/chmuzamil/pakdatakit/tree/main/faker)) | npm | `npm install -D pakdatakit-faker` | [![npm](https://img.shields.io/npm/v/pakdatakit-faker?label=)](https://www.npmjs.com/package/pakdatakit-faker) |
60
+ | [`pakdatakit-pay`](https://www.npmjs.com/package/pakdatakit-pay) ([JazzCash hash](https://github.com/chmuzamil/pakdatakit/tree/main/pay)) | npm | `npm install pakdatakit-pay` | [![npm](https://img.shields.io/npm/v/pakdatakit-pay?label=)](https://www.npmjs.com/package/pakdatakit-pay) |
61
61
 
62
62
  ---
63
63
 
@@ -810,6 +810,35 @@ formatLakh(50000);
810
810
  // "Rs. 50,000"
811
811
  ```
812
812
 
813
+ ### parseAmount() / formatAmountInput()
814
+
815
+ Reads a rupee amount the way people type it in Pakistan, rounded half-up to
816
+ the paisa. Returns `null` for anything that is not exactly one non-negative
817
+ amount; it never throws.
818
+
819
+ ```ts
820
+ parseAmount(input: string): { value: number; raw: string } | null
821
+ formatAmountInput(input: string): string | null
822
+ ```
823
+
824
+ ```ts
825
+ parseAmount('Rs. 1,50,000/-'); // { value: 150000, raw: 'Rs. 1,50,000/-' }
826
+ parseAmount('2.25cr'); // { value: 22500000, raw: '2.25cr' }
827
+ parseAmount('۱٫۵ لاکھ'); // { value: 150000, ... }
828
+ parseAmount('1.005'); // { value: 1.01, ... }: exact, on the digits
829
+ parseAmount('5-10k'); // null: a range
830
+ formatAmountInput('1.5 lakh'); // "Rs. 150,000"
831
+ ```
832
+
833
+ Accepted: `150,000` and `1,50,000` grouping with decimals; Urdu and
834
+ Arabic-Indic digits; `Rs`, `Rs.`, `PKR` or `₨` before or after the number and
835
+ a trailing `/-`; `k`, `thousand(s)`, `hazar`, `ہزار`, `lakh(s)`, `lac(s)`,
836
+ `لاکھ`, `crore(s)`, `cr` and `کروڑ`, also with decimals (`1.5 lakh`);
837
+ whitespace around and between the parts. Rejected: negatives, ranges, more
838
+ than one number, leftover letters, broken or ambiguous grouping (`1,50`,
839
+ `1.500,00`) and amounts over Rs. 50 trillion. Every form is listed on
840
+ [pakdatakit.dev/docs/amount](https://pakdatakit.dev/docs/amount/).
841
+
813
842
  ---
814
843
 
815
844
  ## Amounts in Words
@@ -1209,7 +1238,7 @@ import { pk } from 'pakdatakit/superstruct';
1209
1238
  const CheckoutForm = object({ cnic: pk.cnic(), phone: optional(pk.phone()) });
1210
1239
  ```
1211
1240
 
1212
- Available schemas: `pk.cnic()`, `pk.phone()`, `pk.iban()`, `pk.ntn()`, `pk.strn()`, `pk.landline()`, `pk.passport()`, `pk.vehiclePlate()` and `pk.codPhone()` (a mobile number with no `phoneRiskSignals` flags). Every factory accepts `{ message }` to replace the default error. The Yup schemas let empty values pass so `.required()` decides whether a field is mandatory.
1241
+ Available schemas: `pk.cnic()`, `pk.phone()`, `pk.iban()`, `pk.ntn()`, `pk.strn()`, `pk.landline()`, `pk.passport()`, `pk.vehiclePlate()`, `pk.codPhone()` (a mobile number with no `phoneRiskSignals` flags) and `pk.amount()` (an amount `parseAmount()` reads, such as `1.5 lakh`; convert it with `parseAmount` on submit). Every factory accepts `{ message }` to replace the default error. The Yup schemas let empty values pass so `.required()` decides whether a field is mandatory.
1213
1242
 
1214
1243
  ### class-validator and NestJS
1215
1244
 
@@ -1232,7 +1261,7 @@ export class CreateCustomerDto {
1232
1261
  }
1233
1262
  ```
1234
1263
 
1235
- Decorators: `IsCNIC`, `IsPakPhone`, `IsPakIBAN` (named so it doesn't clash with class-validator's own `IsIBAN`), `IsNTN`, `IsSTRN`, `IsPakLandline`, `IsPakPassport`, `IsVehiclePlate` and `IsCodPhone`, also available as `pk.cnic()` and so on. They accept class-validator's options (`message`, `groups`, `each`, `always`); use `@IsOptional()` for optional fields. Values that are not strings fail.
1264
+ Decorators: `IsCNIC`, `IsPakPhone`, `IsPakIBAN` (named so it doesn't clash with class-validator's own `IsIBAN`), `IsNTN`, `IsSTRN`, `IsPakLandline`, `IsPakPassport`, `IsVehiclePlate`, `IsCodPhone` and `IsPakAmount`, also available as `pk.cnic()` and so on. They accept class-validator's options (`message`, `groups`, `each`, `always`); use `@IsOptional()` for optional fields. Values that are not strings fail.
1236
1265
 
1237
1266
  ### As-you-type helpers
1238
1267
 
@@ -0,0 +1,85 @@
1
+ // src/format.ts
2
+ var LAKH = 1e5;
3
+ var CRORE = 1e7;
4
+ var pkrFormatter = new Intl.NumberFormat("en-PK", {
5
+ maximumFractionDigits: 0
6
+ });
7
+ function assertFinite(amount) {
8
+ if (typeof amount !== "number" || !Number.isFinite(amount)) {
9
+ throw new RangeError(
10
+ `Amount must be a finite number, received ${String(amount)}`
11
+ );
12
+ }
13
+ }
14
+ function roundTo2(value) {
15
+ return Math.round(value * 100) / 100;
16
+ }
17
+ function formatPKR(amount) {
18
+ assertFinite(amount);
19
+ const rounded = Math.round(Math.abs(amount));
20
+ const sign = amount < 0 && rounded !== 0 ? "-" : "";
21
+ return `${sign}Rs. ${pkrFormatter.format(rounded)}`;
22
+ }
23
+ function formatLakh(amount) {
24
+ assertFinite(amount);
25
+ const sign = amount < 0 ? "-" : "";
26
+ const absolute = Math.abs(amount);
27
+ const crores = roundTo2(absolute / CRORE);
28
+ if (crores >= 1) {
29
+ return `${sign}${crores} Crore`;
30
+ }
31
+ const lakhs = roundTo2(absolute / LAKH);
32
+ if (lakhs >= 1) {
33
+ return `${sign}${lakhs} Lakh`;
34
+ }
35
+ return formatPKR(amount);
36
+ }
37
+ var SPACE = /[ \t\n\r\u00A0\u202F]/.source;
38
+ var TRIM = new RegExp(`^${SPACE}+|${SPACE}+$`, "g");
39
+ var CURRENCY = /(rs\.?|pkr|\u20A8)/.source;
40
+ var NUMBER = /(\d{1,3}(?:,\d{3})+|\d{1,2}(?:,\d{2})+,\d{3}|\d+)?(?:\.(\d*))?/.source;
41
+ var THOUSAND = /k|thousands?|hazar|\u06C1\u0632\u0627\u0631/.source;
42
+ var LAKH_UNIT = /lakhs?|lacs?|\u0644\u0627\u06A9\u06BE/.source;
43
+ var CRORE_UNIT = /crores?|cr|\u06A9\u0631\u0648\u0691/.source;
44
+ var AMOUNT = new RegExp(
45
+ `^(?:${CURRENCY}${SPACE}*)?${NUMBER}(?:${SPACE}*(${THOUSAND}|${LAKH_UNIT}|${CRORE_UNIT}))?(?:${SPACE}*${CURRENCY})?(?:${SPACE}*(\\/-))?$`
46
+ );
47
+ function unitExponent(unit) {
48
+ if (unit === void 0) return 0;
49
+ if (new RegExp(`^(?:${THOUSAND})$`).test(unit)) return 3;
50
+ if (new RegExp(`^(?:${LAKH_UNIT})$`).test(unit)) return 5;
51
+ return 7;
52
+ }
53
+ var MAX_PAISA = 5000000000000000n;
54
+ function parseAmount(input) {
55
+ if (typeof input !== "string") return null;
56
+ const raw = input.replace(TRIM, "");
57
+ const text = raw.replace(/[\u06F0-\u06F9]/g, (d) => String(d.charCodeAt(0) - 1776)).replace(/[\u0660-\u0669]/g, (d) => String(d.charCodeAt(0) - 1632)).replace(/\u066B/g, ".").replace(/\u066C/g, ",").replace(/[A-Z]/g, (c) => c.toLowerCase());
58
+ const match = AMOUNT.exec(text);
59
+ if (!match) return null;
60
+ const [, before, whole = "", fraction, unit, after] = match;
61
+ if (before !== void 0 && after !== void 0) return null;
62
+ if (whole === "" && (fraction === void 0 || fraction === "")) return null;
63
+ const digits = whole.replace(/,/g, "") + (fraction ?? "");
64
+ const point = whole.replace(/,/g, "").length + unitExponent(unit);
65
+ const padded = digits.padEnd(point + 3, "0");
66
+ const rupees = padded.slice(0, point) || "0";
67
+ const paisa = padded.slice(point, point + 2);
68
+ let cents = BigInt(rupees + paisa);
69
+ if (padded.charCodeAt(point + 2) >= 53) cents += 1n;
70
+ if (cents > MAX_PAISA) return null;
71
+ return { value: Number(cents) / 100, raw };
72
+ }
73
+ function formatAmountInput(input) {
74
+ const parsed = parseAmount(input);
75
+ if (parsed === null) return null;
76
+ const cents = Math.round(parsed.value * 100);
77
+ const rupees = String(Math.floor(cents / 100)).replace(
78
+ /\B(?=(\d{3})+(?!\d))/g,
79
+ ","
80
+ );
81
+ const paisa = cents % 100;
82
+ return `Rs. ${rupees}${paisa ? `.${String(paisa).padStart(2, "0")}` : ""}`;
83
+ }
84
+
85
+ export { formatAmountInput, formatLakh, formatPKR, parseAmount };
@@ -0,0 +1,90 @@
1
+ 'use strict';
2
+
3
+ // src/format.ts
4
+ var LAKH = 1e5;
5
+ var CRORE = 1e7;
6
+ var pkrFormatter = new Intl.NumberFormat("en-PK", {
7
+ maximumFractionDigits: 0
8
+ });
9
+ function assertFinite(amount) {
10
+ if (typeof amount !== "number" || !Number.isFinite(amount)) {
11
+ throw new RangeError(
12
+ `Amount must be a finite number, received ${String(amount)}`
13
+ );
14
+ }
15
+ }
16
+ function roundTo2(value) {
17
+ return Math.round(value * 100) / 100;
18
+ }
19
+ function formatPKR(amount) {
20
+ assertFinite(amount);
21
+ const rounded = Math.round(Math.abs(amount));
22
+ const sign = amount < 0 && rounded !== 0 ? "-" : "";
23
+ return `${sign}Rs. ${pkrFormatter.format(rounded)}`;
24
+ }
25
+ function formatLakh(amount) {
26
+ assertFinite(amount);
27
+ const sign = amount < 0 ? "-" : "";
28
+ const absolute = Math.abs(amount);
29
+ const crores = roundTo2(absolute / CRORE);
30
+ if (crores >= 1) {
31
+ return `${sign}${crores} Crore`;
32
+ }
33
+ const lakhs = roundTo2(absolute / LAKH);
34
+ if (lakhs >= 1) {
35
+ return `${sign}${lakhs} Lakh`;
36
+ }
37
+ return formatPKR(amount);
38
+ }
39
+ var SPACE = /[ \t\n\r\u00A0\u202F]/.source;
40
+ var TRIM = new RegExp(`^${SPACE}+|${SPACE}+$`, "g");
41
+ var CURRENCY = /(rs\.?|pkr|\u20A8)/.source;
42
+ var NUMBER = /(\d{1,3}(?:,\d{3})+|\d{1,2}(?:,\d{2})+,\d{3}|\d+)?(?:\.(\d*))?/.source;
43
+ var THOUSAND = /k|thousands?|hazar|\u06C1\u0632\u0627\u0631/.source;
44
+ var LAKH_UNIT = /lakhs?|lacs?|\u0644\u0627\u06A9\u06BE/.source;
45
+ var CRORE_UNIT = /crores?|cr|\u06A9\u0631\u0648\u0691/.source;
46
+ var AMOUNT = new RegExp(
47
+ `^(?:${CURRENCY}${SPACE}*)?${NUMBER}(?:${SPACE}*(${THOUSAND}|${LAKH_UNIT}|${CRORE_UNIT}))?(?:${SPACE}*${CURRENCY})?(?:${SPACE}*(\\/-))?$`
48
+ );
49
+ function unitExponent(unit) {
50
+ if (unit === void 0) return 0;
51
+ if (new RegExp(`^(?:${THOUSAND})$`).test(unit)) return 3;
52
+ if (new RegExp(`^(?:${LAKH_UNIT})$`).test(unit)) return 5;
53
+ return 7;
54
+ }
55
+ var MAX_PAISA = 5000000000000000n;
56
+ function parseAmount(input) {
57
+ if (typeof input !== "string") return null;
58
+ const raw = input.replace(TRIM, "");
59
+ const text = raw.replace(/[\u06F0-\u06F9]/g, (d) => String(d.charCodeAt(0) - 1776)).replace(/[\u0660-\u0669]/g, (d) => String(d.charCodeAt(0) - 1632)).replace(/\u066B/g, ".").replace(/\u066C/g, ",").replace(/[A-Z]/g, (c) => c.toLowerCase());
60
+ const match = AMOUNT.exec(text);
61
+ if (!match) return null;
62
+ const [, before, whole = "", fraction, unit, after] = match;
63
+ if (before !== void 0 && after !== void 0) return null;
64
+ if (whole === "" && (fraction === void 0 || fraction === "")) return null;
65
+ const digits = whole.replace(/,/g, "") + (fraction ?? "");
66
+ const point = whole.replace(/,/g, "").length + unitExponent(unit);
67
+ const padded = digits.padEnd(point + 3, "0");
68
+ const rupees = padded.slice(0, point) || "0";
69
+ const paisa = padded.slice(point, point + 2);
70
+ let cents = BigInt(rupees + paisa);
71
+ if (padded.charCodeAt(point + 2) >= 53) cents += 1n;
72
+ if (cents > MAX_PAISA) return null;
73
+ return { value: Number(cents) / 100, raw };
74
+ }
75
+ function formatAmountInput(input) {
76
+ const parsed = parseAmount(input);
77
+ if (parsed === null) return null;
78
+ const cents = Math.round(parsed.value * 100);
79
+ const rupees = String(Math.floor(cents / 100)).replace(
80
+ /\B(?=(\d{3})+(?!\d))/g,
81
+ ","
82
+ );
83
+ const paisa = cents % 100;
84
+ return `Rs. ${rupees}${paisa ? `.${String(paisa).padStart(2, "0")}` : ""}`;
85
+ }
86
+
87
+ exports.formatAmountInput = formatAmountInput;
88
+ exports.formatLakh = formatLakh;
89
+ exports.formatPKR = formatPKR;
90
+ exports.parseAmount = parseAmount;
@@ -6,6 +6,7 @@ import { validateIBAN } from './chunk-IBZPJS4H.js';
6
6
  import { validateLandline } from './chunk-LQHM3ADX.js';
7
7
  import { validatePassport } from './chunk-E6HSKRAE.js';
8
8
  import { validateCNIC } from './chunk-EEVNLTB4.js';
9
+ import { parseAmount } from './chunk-NDW52ZK3.js';
9
10
 
10
11
  // src/adapters/rules.ts
11
12
  var RULES = {
@@ -29,6 +30,10 @@ var RULES = {
29
30
  codPhone: {
30
31
  test: (value) => phoneRiskSignals(value).length === 0,
31
32
  message: "Enter a mobile number a courier can call"
33
+ },
34
+ amount: {
35
+ test: (value) => parseAmount(value) !== null,
36
+ message: "Enter an amount in rupees, like 150,000 or 1.5 lakh"
32
37
  }
33
38
  };
34
39
 
@@ -8,6 +8,7 @@ var chunkDHOP7LQX_cjs = require('./chunk-DHOP7LQX.cjs');
8
8
  var chunkAUQFA7EE_cjs = require('./chunk-AUQFA7EE.cjs');
9
9
  var chunk7E7L3NYS_cjs = require('./chunk-7E7L3NYS.cjs');
10
10
  var chunkHTCSHHOR_cjs = require('./chunk-HTCSHHOR.cjs');
11
+ var chunkNLSIAPZG_cjs = require('./chunk-NLSIAPZG.cjs');
11
12
 
12
13
  // src/adapters/rules.ts
13
14
  var RULES = {
@@ -31,6 +32,10 @@ var RULES = {
31
32
  codPhone: {
32
33
  test: (value) => chunkYDUXIENX_cjs.phoneRiskSignals(value).length === 0,
33
34
  message: "Enter a mobile number a courier can call"
35
+ },
36
+ amount: {
37
+ test: (value) => chunkNLSIAPZG_cjs.parseAmount(value) !== null,
38
+ message: "Enter an amount in rupees, like 150,000 or 1.5 lakh"
34
39
  }
35
40
  };
36
41
 
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var chunkXCFZKCV2_cjs = require('./chunk-XCFZKCV2.cjs');
3
+ var chunkYSRYWZCQ_cjs = require('./chunk-YSRYWZCQ.cjs');
4
4
  require('./chunk-ESKXG7Y6.cjs');
5
5
  require('./chunk-YDUXIENX.cjs');
6
6
  require('./chunk-H6M6L26S.cjs');
@@ -13,13 +13,14 @@ require('./chunk-7E7L3NYS.cjs');
13
13
  require('./chunk-QFPEFD67.cjs');
14
14
  require('./chunk-I7UUPD3G.cjs');
15
15
  require('./chunk-HTCSHHOR.cjs');
16
+ require('./chunk-NLSIAPZG.cjs');
16
17
  require('./chunk-33GOK7EE.cjs');
17
18
  require('./chunk-E6GWBOKV.cjs');
18
19
  require('./chunk-VPBMIYO2.cjs');
19
20
  var classValidator = require('class-validator');
20
21
 
21
22
  function decorator(name) {
22
- const rule = chunkXCFZKCV2_cjs.RULES[name];
23
+ const rule = chunkYSRYWZCQ_cjs.RULES[name];
23
24
  return (options = {}) => (target, propertyName) => {
24
25
  classValidator.registerDecorator({
25
26
  name: `pk-${name}`,
@@ -41,7 +42,8 @@ var pk = {
41
42
  landline: decorator("landline"),
42
43
  passport: decorator("passport"),
43
44
  vehiclePlate: decorator("vehiclePlate"),
44
- codPhone: decorator("codPhone")
45
+ codPhone: decorator("codPhone"),
46
+ amount: decorator("amount")
45
47
  };
46
48
  var IsCNIC = pk.cnic;
47
49
  var IsPakPhone = pk.phone;
@@ -52,10 +54,12 @@ var IsPakLandline = pk.landline;
52
54
  var IsPakPassport = pk.passport;
53
55
  var IsVehiclePlate = pk.vehiclePlate;
54
56
  var IsCodPhone = pk.codPhone;
57
+ var IsPakAmount = pk.amount;
55
58
 
56
59
  exports.IsCNIC = IsCNIC;
57
60
  exports.IsCodPhone = IsCodPhone;
58
61
  exports.IsNTN = IsNTN;
62
+ exports.IsPakAmount = IsPakAmount;
59
63
  exports.IsPakIBAN = IsPakIBAN;
60
64
  exports.IsPakLandline = IsPakLandline;
61
65
  exports.IsPakPassport = IsPakPassport;
@@ -33,6 +33,7 @@ declare const pk: {
33
33
  passport: (options?: DecoratorOptions) => PropertyDecorator;
34
34
  vehiclePlate: (options?: DecoratorOptions) => PropertyDecorator;
35
35
  codPhone: (options?: DecoratorOptions) => PropertyDecorator;
36
+ amount: (options?: DecoratorOptions) => PropertyDecorator;
36
37
  };
37
38
  /** Validates a CNIC. See {@link pk}. */
38
39
  declare const IsCNIC: (options?: DecoratorOptions) => PropertyDecorator;
@@ -58,6 +59,11 @@ declare const IsVehiclePlate: (options?: DecoratorOptions) => PropertyDecorator;
58
59
  * `phoneRiskSignals` flag. See {@link pk}.
59
60
  */
60
61
  declare const IsCodPhone: (options?: DecoratorOptions) => PropertyDecorator;
62
+ /**
63
+ * Validates a rupee amount as people type it (`150,000`, `Rs. 1,50,000/-`,
64
+ * `1.5 lakh`): one that `parseAmount` reads. See {@link pk}.
65
+ */
66
+ declare const IsPakAmount: (options?: DecoratorOptions) => PropertyDecorator;
61
67
 
62
- export { IsCNIC, IsCodPhone, IsNTN, IsPakIBAN, IsPakLandline, IsPakPassport, IsPakPhone, IsSTRN, IsVehiclePlate, pk };
68
+ export { IsCNIC, IsCodPhone, IsNTN, IsPakAmount, IsPakIBAN, IsPakLandline, IsPakPassport, IsPakPhone, IsSTRN, IsVehiclePlate, pk };
63
69
  export type { DecoratorOptions };
@@ -33,6 +33,7 @@ declare const pk: {
33
33
  passport: (options?: DecoratorOptions) => PropertyDecorator;
34
34
  vehiclePlate: (options?: DecoratorOptions) => PropertyDecorator;
35
35
  codPhone: (options?: DecoratorOptions) => PropertyDecorator;
36
+ amount: (options?: DecoratorOptions) => PropertyDecorator;
36
37
  };
37
38
  /** Validates a CNIC. See {@link pk}. */
38
39
  declare const IsCNIC: (options?: DecoratorOptions) => PropertyDecorator;
@@ -58,6 +59,11 @@ declare const IsVehiclePlate: (options?: DecoratorOptions) => PropertyDecorator;
58
59
  * `phoneRiskSignals` flag. See {@link pk}.
59
60
  */
60
61
  declare const IsCodPhone: (options?: DecoratorOptions) => PropertyDecorator;
62
+ /**
63
+ * Validates a rupee amount as people type it (`150,000`, `Rs. 1,50,000/-`,
64
+ * `1.5 lakh`): one that `parseAmount` reads. See {@link pk}.
65
+ */
66
+ declare const IsPakAmount: (options?: DecoratorOptions) => PropertyDecorator;
61
67
 
62
- export { IsCNIC, IsCodPhone, IsNTN, IsPakIBAN, IsPakLandline, IsPakPassport, IsPakPhone, IsSTRN, IsVehiclePlate, pk };
68
+ export { IsCNIC, IsCodPhone, IsNTN, IsPakAmount, IsPakIBAN, IsPakLandline, IsPakPassport, IsPakPhone, IsSTRN, IsVehiclePlate, pk };
63
69
  export type { DecoratorOptions };
@@ -1,4 +1,4 @@
1
- import { RULES } from './chunk-IDTRFOQW.js';
1
+ import { RULES } from './chunk-QG5T7YQ5.js';
2
2
  import './chunk-S274QFFB.js';
3
3
  import './chunk-UYFTXD4P.js';
4
4
  import './chunk-CEPNSHIC.js';
@@ -11,6 +11,7 @@ import './chunk-E6HSKRAE.js';
11
11
  import './chunk-B7DOQ5QF.js';
12
12
  import './chunk-33QMFE2Z.js';
13
13
  import './chunk-EEVNLTB4.js';
14
+ import './chunk-NDW52ZK3.js';
14
15
  import './chunk-XOTCIXY6.js';
15
16
  import './chunk-E2XU6NOW.js';
16
17
  import './chunk-ENQ7O7VW.js';
@@ -39,7 +40,8 @@ var pk = {
39
40
  landline: decorator("landline"),
40
41
  passport: decorator("passport"),
41
42
  vehiclePlate: decorator("vehiclePlate"),
42
- codPhone: decorator("codPhone")
43
+ codPhone: decorator("codPhone"),
44
+ amount: decorator("amount")
43
45
  };
44
46
  var IsCNIC = pk.cnic;
45
47
  var IsPakPhone = pk.phone;
@@ -50,5 +52,6 @@ var IsPakLandline = pk.landline;
50
52
  var IsPakPassport = pk.passport;
51
53
  var IsVehiclePlate = pk.vehiclePlate;
52
54
  var IsCodPhone = pk.codPhone;
55
+ var IsPakAmount = pk.amount;
53
56
 
54
- export { IsCNIC, IsCodPhone, IsNTN, IsPakIBAN, IsPakLandline, IsPakPassport, IsPakPhone, IsSTRN, IsVehiclePlate, pk };
57
+ export { IsCNIC, IsCodPhone, IsNTN, IsPakAmount, IsPakIBAN, IsPakLandline, IsPakPassport, IsPakPhone, IsSTRN, IsVehiclePlate, pk };
package/dist/cli.js CHANGED
@@ -2,7 +2,7 @@
2
2
  import { normalizeRomanUrdu, formatHijri, toHijri, formatPKR, formatLakh, parseAddress, getCityByPostalCode, getPostalCode, getProvince, getBankFromIBAN, validateIBAN, analyzePhone, validatePhone, validateCNIC } from 'pakdatakit';
3
3
 
4
4
  // package.json
5
- var version = "2.5.1";
5
+ var version = "2.6.0";
6
6
  var EXIT_OK = 0;
7
7
  var EXIT_NEGATIVE = 1;
8
8
  var EXIT_USAGE = 2;
package/dist/format.cjs CHANGED
@@ -1,14 +1,22 @@
1
1
  'use strict';
2
2
 
3
- var chunkLVHTH4P7_cjs = require('./chunk-LVHTH4P7.cjs');
3
+ var chunkNLSIAPZG_cjs = require('./chunk-NLSIAPZG.cjs');
4
4
 
5
5
 
6
6
 
7
+ Object.defineProperty(exports, "formatAmountInput", {
8
+ enumerable: true,
9
+ get: function () { return chunkNLSIAPZG_cjs.formatAmountInput; }
10
+ });
7
11
  Object.defineProperty(exports, "formatLakh", {
8
12
  enumerable: true,
9
- get: function () { return chunkLVHTH4P7_cjs.formatLakh; }
13
+ get: function () { return chunkNLSIAPZG_cjs.formatLakh; }
10
14
  });
11
15
  Object.defineProperty(exports, "formatPKR", {
12
16
  enumerable: true,
13
- get: function () { return chunkLVHTH4P7_cjs.formatPKR; }
17
+ get: function () { return chunkNLSIAPZG_cjs.formatPKR; }
18
+ });
19
+ Object.defineProperty(exports, "parseAmount", {
20
+ enumerable: true,
21
+ get: function () { return chunkNLSIAPZG_cjs.parseAmount; }
14
22
  });
package/dist/format.d.cts CHANGED
@@ -23,5 +23,61 @@ declare function formatPKR(amount: number): string;
23
23
  * @throws {RangeError} If `amount` is `NaN` or infinite
24
24
  */
25
25
  declare function formatLakh(amount: number): string;
26
+ /** The result of {@link parseAmount}. */
27
+ interface ParsedAmount {
28
+ /** The amount in rupees, rounded half-up to the paisa (2 decimals). */
29
+ value: number;
30
+ /** The input with surrounding whitespace removed. */
31
+ raw: string;
32
+ }
33
+ /**
34
+ * Reads a rupee amount the way people type it in Pakistan, and returns it in
35
+ * rupees, rounded half-up to the paisa. Returns `null` for anything that is
36
+ * not exactly one non-negative amount; it never throws.
37
+ *
38
+ * Accepted:
39
+ * - digits, with or without grouping: `150000`, `150,000` (international) or
40
+ * `1,50,000` (Pakistani: groups of two, then three), and decimals
41
+ * (`1,234.50`, `.5`, `5.`); a grouping must be complete and consistent;
42
+ * - Urdu (`۱۵۰۰۰۰`) and Arabic-Indic (`١٥٠٠٠٠`) digits, also mixed with
43
+ * 0-9, and the Arabic decimal and thousands separators (`٫`, `٬`);
44
+ * - one currency mark before or after the number: `Rs`, `Rs.`, `PKR` or `₨`
45
+ * (any case), and a trailing `/-` (`Rs. 5,000/-`);
46
+ * - one shorthand unit after the number, with or without a space, in any
47
+ * case: `k`, `thousand(s)`, `hazar`, `ہزار` (× 1,000); `lakh(s)`, `lac(s)`,
48
+ * `لاکھ` (× 100,000); `crore(s)`, `cr`, `کروڑ` (× 10,000,000). Decimals
49
+ * work with units: `1.5 lakh` is 150,000 and `2.25cr` is 22,500,000;
50
+ * - whitespace around and between the parts (spaces, tabs, line breaks and
51
+ * no-break spaces).
52
+ *
53
+ * Rejected (`null`): empty input, negative or signed amounts (`-500`,
54
+ * `+500`), ranges (`5-10k`), more than one number (`500 600`), two currency
55
+ * marks or two units, leftover letters (`500 rupees`, `5kk`), grouping that
56
+ * could be read two ways or is broken (`1,50`, `1.500,00`, `1,5000`), and
57
+ * amounts over Rs. 50 trillion (50 lakh crore), beyond which a number can no
58
+ * longer hold every paisa exactly.
59
+ *
60
+ * The arithmetic is done on the digits, so the result is exact: `1.005`
61
+ * rounds to 1.01 and `1.5 lakh` is exactly 150000.
62
+ *
63
+ * @param input - The amount as typed
64
+ * @returns `{ value, raw }`, or `null` if the input is not one amount
65
+ * @example
66
+ * parseAmount('Rs. 1,50,000/-'); // { value: 150000, raw: 'Rs. 1,50,000/-' }
67
+ * parseAmount('2.25cr'); // { value: 22500000, raw: '2.25cr' }
68
+ * parseAmount('5-10k'); // null
69
+ */
70
+ declare function parseAmount(input: string): ParsedAmount | null;
71
+ /**
72
+ * Writes back an amount typed in any form {@link parseAmount} accepts, for
73
+ * showing next to the field ("= Rs. 150,000"): `Rs.`, international
74
+ * grouping, and paisa only when there are any (`Rs. 1,234.50`). Returns
75
+ * `null` when `parseAmount` does; it never throws.
76
+ *
77
+ * @param input - The amount as typed
78
+ * @returns E.g. `"Rs. 150,000"` for `"1.5 lakh"`, or `null`
79
+ */
80
+ declare function formatAmountInput(input: string): string | null;
26
81
 
27
- export { formatLakh, formatPKR };
82
+ export { formatAmountInput, formatLakh, formatPKR, parseAmount };
83
+ export type { ParsedAmount };
package/dist/format.d.ts CHANGED
@@ -23,5 +23,61 @@ declare function formatPKR(amount: number): string;
23
23
  * @throws {RangeError} If `amount` is `NaN` or infinite
24
24
  */
25
25
  declare function formatLakh(amount: number): string;
26
+ /** The result of {@link parseAmount}. */
27
+ interface ParsedAmount {
28
+ /** The amount in rupees, rounded half-up to the paisa (2 decimals). */
29
+ value: number;
30
+ /** The input with surrounding whitespace removed. */
31
+ raw: string;
32
+ }
33
+ /**
34
+ * Reads a rupee amount the way people type it in Pakistan, and returns it in
35
+ * rupees, rounded half-up to the paisa. Returns `null` for anything that is
36
+ * not exactly one non-negative amount; it never throws.
37
+ *
38
+ * Accepted:
39
+ * - digits, with or without grouping: `150000`, `150,000` (international) or
40
+ * `1,50,000` (Pakistani: groups of two, then three), and decimals
41
+ * (`1,234.50`, `.5`, `5.`); a grouping must be complete and consistent;
42
+ * - Urdu (`۱۵۰۰۰۰`) and Arabic-Indic (`١٥٠٠٠٠`) digits, also mixed with
43
+ * 0-9, and the Arabic decimal and thousands separators (`٫`, `٬`);
44
+ * - one currency mark before or after the number: `Rs`, `Rs.`, `PKR` or `₨`
45
+ * (any case), and a trailing `/-` (`Rs. 5,000/-`);
46
+ * - one shorthand unit after the number, with or without a space, in any
47
+ * case: `k`, `thousand(s)`, `hazar`, `ہزار` (× 1,000); `lakh(s)`, `lac(s)`,
48
+ * `لاکھ` (× 100,000); `crore(s)`, `cr`, `کروڑ` (× 10,000,000). Decimals
49
+ * work with units: `1.5 lakh` is 150,000 and `2.25cr` is 22,500,000;
50
+ * - whitespace around and between the parts (spaces, tabs, line breaks and
51
+ * no-break spaces).
52
+ *
53
+ * Rejected (`null`): empty input, negative or signed amounts (`-500`,
54
+ * `+500`), ranges (`5-10k`), more than one number (`500 600`), two currency
55
+ * marks or two units, leftover letters (`500 rupees`, `5kk`), grouping that
56
+ * could be read two ways or is broken (`1,50`, `1.500,00`, `1,5000`), and
57
+ * amounts over Rs. 50 trillion (50 lakh crore), beyond which a number can no
58
+ * longer hold every paisa exactly.
59
+ *
60
+ * The arithmetic is done on the digits, so the result is exact: `1.005`
61
+ * rounds to 1.01 and `1.5 lakh` is exactly 150000.
62
+ *
63
+ * @param input - The amount as typed
64
+ * @returns `{ value, raw }`, or `null` if the input is not one amount
65
+ * @example
66
+ * parseAmount('Rs. 1,50,000/-'); // { value: 150000, raw: 'Rs. 1,50,000/-' }
67
+ * parseAmount('2.25cr'); // { value: 22500000, raw: '2.25cr' }
68
+ * parseAmount('5-10k'); // null
69
+ */
70
+ declare function parseAmount(input: string): ParsedAmount | null;
71
+ /**
72
+ * Writes back an amount typed in any form {@link parseAmount} accepts, for
73
+ * showing next to the field ("= Rs. 150,000"): `Rs.`, international
74
+ * grouping, and paisa only when there are any (`Rs. 1,234.50`). Returns
75
+ * `null` when `parseAmount` does; it never throws.
76
+ *
77
+ * @param input - The amount as typed
78
+ * @returns E.g. `"Rs. 150,000"` for `"1.5 lakh"`, or `null`
79
+ */
80
+ declare function formatAmountInput(input: string): string | null;
26
81
 
27
- export { formatLakh, formatPKR };
82
+ export { formatAmountInput, formatLakh, formatPKR, parseAmount };
83
+ export type { ParsedAmount };
package/dist/format.js CHANGED
@@ -1 +1 @@
1
- export { formatLakh, formatPKR } from './chunk-6TSKA2PH.js';
1
+ export { formatAmountInput, formatLakh, formatPKR, parseAmount } from './chunk-NDW52ZK3.js';
package/dist/index.cjs CHANGED
@@ -25,7 +25,7 @@ var chunkYPAWNWFD_cjs = require('./chunk-YPAWNWFD.cjs');
25
25
  var chunk5UCRHVI4_cjs = require('./chunk-5UCRHVI4.cjs');
26
26
  var chunkCF6AMRBU_cjs = require('./chunk-CF6AMRBU.cjs');
27
27
  require('./chunk-SF4ECUZ6.cjs');
28
- var chunkLVHTH4P7_cjs = require('./chunk-LVHTH4P7.cjs');
28
+ var chunkNLSIAPZG_cjs = require('./chunk-NLSIAPZG.cjs');
29
29
  var chunk33GOK7EE_cjs = require('./chunk-33GOK7EE.cjs');
30
30
  require('./chunk-E6GWBOKV.cjs');
31
31
  require('./chunk-VPBMIYO2.cjs');
@@ -345,13 +345,21 @@ Object.defineProperty(exports, "splitInclusive", {
345
345
  enumerable: true,
346
346
  get: function () { return chunkCF6AMRBU_cjs.splitInclusive; }
347
347
  });
348
+ Object.defineProperty(exports, "formatAmountInput", {
349
+ enumerable: true,
350
+ get: function () { return chunkNLSIAPZG_cjs.formatAmountInput; }
351
+ });
348
352
  Object.defineProperty(exports, "formatLakh", {
349
353
  enumerable: true,
350
- get: function () { return chunkLVHTH4P7_cjs.formatLakh; }
354
+ get: function () { return chunkNLSIAPZG_cjs.formatLakh; }
351
355
  });
352
356
  Object.defineProperty(exports, "formatPKR", {
353
357
  enumerable: true,
354
- get: function () { return chunkLVHTH4P7_cjs.formatPKR; }
358
+ get: function () { return chunkNLSIAPZG_cjs.formatPKR; }
359
+ });
360
+ Object.defineProperty(exports, "parseAmount", {
361
+ enumerable: true,
362
+ get: function () { return chunkNLSIAPZG_cjs.parseAmount; }
355
363
  });
356
364
  Object.defineProperty(exports, "getDistrictProvince", {
357
365
  enumerable: true,
package/dist/index.d.cts CHANGED
@@ -2,7 +2,7 @@ export { CNICInfo, getCNICInfo, validateCNIC } from './cnic.cjs';
2
2
  export { PhoneAnalysis, analyzePhone, formatPhone, validatePhone } from './phone.cjs';
3
3
  export { NetworkName, getNetwork } from './networks.cjs';
4
4
  export { getDistrictProvince, getDistrictsByProvince, getDivisionOfDistrict, getDivisions, getProvince, getTehsilDistrict, getTehsils, searchCities, searchDistricts } from './geo.cjs';
5
- export { formatLakh, formatPKR } from './format.cjs';
5
+ export { ParsedAmount, formatAmountInput, formatLakh, formatPKR, parseAmount } from './format.cjs';
6
6
  export { createWhatsAppLink } from './whatsapp.cjs';
7
7
  export { BankInfo, BankType, getBankFromIBAN, getBankInfo, getBanks, validateIBAN } from './iban.cjs';
8
8
  export { PostOffice, getCityByPostalCode, getPostOffice, getPostalAreas, getPostalCode, getPostalCodes, searchPostOffices, searchPostalCodes } from './postal.cjs';
package/dist/index.d.ts CHANGED
@@ -2,7 +2,7 @@ export { CNICInfo, getCNICInfo, validateCNIC } from './cnic.js';
2
2
  export { PhoneAnalysis, analyzePhone, formatPhone, validatePhone } from './phone.js';
3
3
  export { NetworkName, getNetwork } from './networks.js';
4
4
  export { getDistrictProvince, getDistrictsByProvince, getDivisionOfDistrict, getDivisions, getProvince, getTehsilDistrict, getTehsils, searchCities, searchDistricts } from './geo.js';
5
- export { formatLakh, formatPKR } from './format.js';
5
+ export { ParsedAmount, formatAmountInput, formatLakh, formatPKR, parseAmount } from './format.js';
6
6
  export { createWhatsAppLink } from './whatsapp.js';
7
7
  export { BankInfo, BankType, getBankFromIBAN, getBankInfo, getBanks, validateIBAN } from './iban.js';
8
8
  export { PostOffice, getCityByPostalCode, getPostOffice, getPostalAreas, getPostalCode, getPostalCodes, searchPostOffices, searchPostalCodes } from './postal.js';
package/dist/index.js CHANGED
@@ -23,7 +23,7 @@ export { mapCourierStatus, normalizeCityForCourier } from './chunk-4GSBHJX6.js';
23
23
  export { FBR_DI_SPEC_VERSION, buildFbrInvoice, expectedSalesTax, validateFbrInvoice } from './chunk-OTI7HY55.js';
24
24
  export { calculateSalesTax, getSalesTaxRate, splitInclusive } from './chunk-34U2ZMHR.js';
25
25
  import './chunk-5EY5DQS7.js';
26
- export { formatLakh, formatPKR } from './chunk-6TSKA2PH.js';
26
+ export { formatAmountInput, formatLakh, formatPKR, parseAmount } from './chunk-NDW52ZK3.js';
27
27
  export { getDistrictProvince, getDistrictsByProvince, getDivisionOfDistrict, getDivisions, getProvince, getTehsilDistrict, getTehsils, searchCities, searchDistricts } from './chunk-XOTCIXY6.js';
28
28
  import './chunk-E2XU6NOW.js';
29
29
  import './chunk-ENQ7O7VW.js';
package/dist/joi.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var chunkXCFZKCV2_cjs = require('./chunk-XCFZKCV2.cjs');
3
+ var chunkYSRYWZCQ_cjs = require('./chunk-YSRYWZCQ.cjs');
4
4
  require('./chunk-ESKXG7Y6.cjs');
5
5
  require('./chunk-YDUXIENX.cjs');
6
6
  require('./chunk-H6M6L26S.cjs');
@@ -13,6 +13,7 @@ require('./chunk-7E7L3NYS.cjs');
13
13
  require('./chunk-QFPEFD67.cjs');
14
14
  require('./chunk-I7UUPD3G.cjs');
15
15
  require('./chunk-HTCSHHOR.cjs');
16
+ require('./chunk-NLSIAPZG.cjs');
16
17
  require('./chunk-33GOK7EE.cjs');
17
18
  require('./chunk-E6GWBOKV.cjs');
18
19
  require('./chunk-VPBMIYO2.cjs');
@@ -23,7 +24,7 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
23
24
  var Joi__default = /*#__PURE__*/_interopDefault(Joi);
24
25
 
25
26
  function schema(name) {
26
- const rule = chunkXCFZKCV2_cjs.RULES[name];
27
+ const rule = chunkYSRYWZCQ_cjs.RULES[name];
27
28
  return (options = {}) => Joi__default.default.string().custom(
28
29
  (value, helpers) => rule.test(value) ? value : helpers.message({ custom: options.message ?? rule.message })
29
30
  );
@@ -37,7 +38,8 @@ var pk = {
37
38
  landline: schema("landline"),
38
39
  passport: schema("passport"),
39
40
  vehiclePlate: schema("vehiclePlate"),
40
- codPhone: schema("codPhone")
41
+ codPhone: schema("codPhone"),
42
+ amount: schema("amount")
41
43
  };
42
44
 
43
45
  exports.pk = pk;
package/dist/joi.d.cts CHANGED
@@ -20,6 +20,7 @@ declare const pk: {
20
20
  passport: (options?: AdapterOptions) => Joi.StringSchema<string>;
21
21
  vehiclePlate: (options?: AdapterOptions) => Joi.StringSchema<string>;
22
22
  codPhone: (options?: AdapterOptions) => Joi.StringSchema<string>;
23
+ amount: (options?: AdapterOptions) => Joi.StringSchema<string>;
23
24
  };
24
25
 
25
26
  export { AdapterOptions, pk };
package/dist/joi.d.ts CHANGED
@@ -20,6 +20,7 @@ declare const pk: {
20
20
  passport: (options?: AdapterOptions) => Joi.StringSchema<string>;
21
21
  vehiclePlate: (options?: AdapterOptions) => Joi.StringSchema<string>;
22
22
  codPhone: (options?: AdapterOptions) => Joi.StringSchema<string>;
23
+ amount: (options?: AdapterOptions) => Joi.StringSchema<string>;
23
24
  };
24
25
 
25
26
  export { AdapterOptions, pk };
package/dist/joi.js CHANGED
@@ -1,4 +1,4 @@
1
- import { RULES } from './chunk-IDTRFOQW.js';
1
+ import { RULES } from './chunk-QG5T7YQ5.js';
2
2
  import './chunk-S274QFFB.js';
3
3
  import './chunk-UYFTXD4P.js';
4
4
  import './chunk-CEPNSHIC.js';
@@ -11,6 +11,7 @@ import './chunk-E6HSKRAE.js';
11
11
  import './chunk-B7DOQ5QF.js';
12
12
  import './chunk-33QMFE2Z.js';
13
13
  import './chunk-EEVNLTB4.js';
14
+ import './chunk-NDW52ZK3.js';
14
15
  import './chunk-XOTCIXY6.js';
15
16
  import './chunk-E2XU6NOW.js';
16
17
  import './chunk-ENQ7O7VW.js';
@@ -31,7 +32,8 @@ var pk = {
31
32
  landline: schema("landline"),
32
33
  passport: schema("passport"),
33
34
  vehiclePlate: schema("vehiclePlate"),
34
- codPhone: schema("codPhone")
35
+ codPhone: schema("codPhone"),
36
+ amount: schema("amount")
35
37
  };
36
38
 
37
39
  export { pk };
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var chunkXCFZKCV2_cjs = require('./chunk-XCFZKCV2.cjs');
3
+ var chunkYSRYWZCQ_cjs = require('./chunk-YSRYWZCQ.cjs');
4
4
  require('./chunk-ESKXG7Y6.cjs');
5
5
  require('./chunk-YDUXIENX.cjs');
6
6
  require('./chunk-H6M6L26S.cjs');
@@ -13,13 +13,14 @@ require('./chunk-7E7L3NYS.cjs');
13
13
  require('./chunk-QFPEFD67.cjs');
14
14
  require('./chunk-I7UUPD3G.cjs');
15
15
  require('./chunk-HTCSHHOR.cjs');
16
+ require('./chunk-NLSIAPZG.cjs');
16
17
  require('./chunk-33GOK7EE.cjs');
17
18
  require('./chunk-E6GWBOKV.cjs');
18
19
  require('./chunk-VPBMIYO2.cjs');
19
20
  var superstruct = require('superstruct');
20
21
 
21
22
  function schema(name) {
22
- const rule = chunkXCFZKCV2_cjs.RULES[name];
23
+ const rule = chunkYSRYWZCQ_cjs.RULES[name];
23
24
  return (options = {}) => superstruct.refine(
24
25
  superstruct.string(),
25
26
  `pk-${name}`,
@@ -35,7 +36,8 @@ var pk = {
35
36
  landline: schema("landline"),
36
37
  passport: schema("passport"),
37
38
  vehiclePlate: schema("vehiclePlate"),
38
- codPhone: schema("codPhone")
39
+ codPhone: schema("codPhone"),
40
+ amount: schema("amount")
39
41
  };
40
42
 
41
43
  exports.pk = pk;
@@ -20,6 +20,7 @@ declare const pk: {
20
20
  passport: (options?: AdapterOptions) => superstruct.Struct<string, null>;
21
21
  vehiclePlate: (options?: AdapterOptions) => superstruct.Struct<string, null>;
22
22
  codPhone: (options?: AdapterOptions) => superstruct.Struct<string, null>;
23
+ amount: (options?: AdapterOptions) => superstruct.Struct<string, null>;
23
24
  };
24
25
 
25
26
  export { AdapterOptions, pk };
@@ -20,6 +20,7 @@ declare const pk: {
20
20
  passport: (options?: AdapterOptions) => superstruct.Struct<string, null>;
21
21
  vehiclePlate: (options?: AdapterOptions) => superstruct.Struct<string, null>;
22
22
  codPhone: (options?: AdapterOptions) => superstruct.Struct<string, null>;
23
+ amount: (options?: AdapterOptions) => superstruct.Struct<string, null>;
23
24
  };
24
25
 
25
26
  export { AdapterOptions, pk };
@@ -1,4 +1,4 @@
1
- import { RULES } from './chunk-IDTRFOQW.js';
1
+ import { RULES } from './chunk-QG5T7YQ5.js';
2
2
  import './chunk-S274QFFB.js';
3
3
  import './chunk-UYFTXD4P.js';
4
4
  import './chunk-CEPNSHIC.js';
@@ -11,6 +11,7 @@ import './chunk-E6HSKRAE.js';
11
11
  import './chunk-B7DOQ5QF.js';
12
12
  import './chunk-33QMFE2Z.js';
13
13
  import './chunk-EEVNLTB4.js';
14
+ import './chunk-NDW52ZK3.js';
14
15
  import './chunk-XOTCIXY6.js';
15
16
  import './chunk-E2XU6NOW.js';
16
17
  import './chunk-ENQ7O7VW.js';
@@ -33,7 +34,8 @@ var pk = {
33
34
  landline: schema("landline"),
34
35
  passport: schema("passport"),
35
36
  vehiclePlate: schema("vehiclePlate"),
36
- codPhone: schema("codPhone")
37
+ codPhone: schema("codPhone"),
38
+ amount: schema("amount")
37
39
  };
38
40
 
39
41
  export { pk };
package/dist/valibot.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var chunkXCFZKCV2_cjs = require('./chunk-XCFZKCV2.cjs');
3
+ var chunkYSRYWZCQ_cjs = require('./chunk-YSRYWZCQ.cjs');
4
4
  require('./chunk-ESKXG7Y6.cjs');
5
5
  require('./chunk-YDUXIENX.cjs');
6
6
  require('./chunk-H6M6L26S.cjs');
@@ -13,6 +13,7 @@ require('./chunk-7E7L3NYS.cjs');
13
13
  require('./chunk-QFPEFD67.cjs');
14
14
  require('./chunk-I7UUPD3G.cjs');
15
15
  require('./chunk-HTCSHHOR.cjs');
16
+ require('./chunk-NLSIAPZG.cjs');
16
17
  require('./chunk-33GOK7EE.cjs');
17
18
  require('./chunk-E6GWBOKV.cjs');
18
19
  require('./chunk-VPBMIYO2.cjs');
@@ -39,7 +40,7 @@ function _interopNamespace(e) {
39
40
  var v__namespace = /*#__PURE__*/_interopNamespace(v);
40
41
 
41
42
  function schema(name) {
42
- const rule = chunkXCFZKCV2_cjs.RULES[name];
43
+ const rule = chunkYSRYWZCQ_cjs.RULES[name];
43
44
  return (options = {}) => v__namespace.pipe(v__namespace.string(), v__namespace.check(rule.test, options.message ?? rule.message));
44
45
  }
45
46
  var pk = {
@@ -51,7 +52,8 @@ var pk = {
51
52
  landline: schema("landline"),
52
53
  passport: schema("passport"),
53
54
  vehiclePlate: schema("vehiclePlate"),
54
- codPhone: schema("codPhone")
55
+ codPhone: schema("codPhone"),
56
+ amount: schema("amount")
55
57
  };
56
58
 
57
59
  exports.pk = pk;
@@ -20,6 +20,7 @@ declare const pk: {
20
20
  passport: (options?: AdapterOptions) => v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.CheckAction<string, string>]>;
21
21
  vehiclePlate: (options?: AdapterOptions) => v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.CheckAction<string, string>]>;
22
22
  codPhone: (options?: AdapterOptions) => v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.CheckAction<string, string>]>;
23
+ amount: (options?: AdapterOptions) => v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.CheckAction<string, string>]>;
23
24
  };
24
25
 
25
26
  export { AdapterOptions, pk };
package/dist/valibot.d.ts CHANGED
@@ -20,6 +20,7 @@ declare const pk: {
20
20
  passport: (options?: AdapterOptions) => v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.CheckAction<string, string>]>;
21
21
  vehiclePlate: (options?: AdapterOptions) => v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.CheckAction<string, string>]>;
22
22
  codPhone: (options?: AdapterOptions) => v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.CheckAction<string, string>]>;
23
+ amount: (options?: AdapterOptions) => v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.CheckAction<string, string>]>;
23
24
  };
24
25
 
25
26
  export { AdapterOptions, pk };
package/dist/valibot.js CHANGED
@@ -1,4 +1,4 @@
1
- import { RULES } from './chunk-IDTRFOQW.js';
1
+ import { RULES } from './chunk-QG5T7YQ5.js';
2
2
  import './chunk-S274QFFB.js';
3
3
  import './chunk-UYFTXD4P.js';
4
4
  import './chunk-CEPNSHIC.js';
@@ -11,6 +11,7 @@ import './chunk-E6HSKRAE.js';
11
11
  import './chunk-B7DOQ5QF.js';
12
12
  import './chunk-33QMFE2Z.js';
13
13
  import './chunk-EEVNLTB4.js';
14
+ import './chunk-NDW52ZK3.js';
14
15
  import './chunk-XOTCIXY6.js';
15
16
  import './chunk-E2XU6NOW.js';
16
17
  import './chunk-ENQ7O7VW.js';
@@ -29,7 +30,8 @@ var pk = {
29
30
  landline: schema("landline"),
30
31
  passport: schema("passport"),
31
32
  vehiclePlate: schema("vehiclePlate"),
32
- codPhone: schema("codPhone")
33
+ codPhone: schema("codPhone"),
34
+ amount: schema("amount")
33
35
  };
34
36
 
35
37
  export { pk };
package/dist/yup.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var chunkXCFZKCV2_cjs = require('./chunk-XCFZKCV2.cjs');
3
+ var chunkYSRYWZCQ_cjs = require('./chunk-YSRYWZCQ.cjs');
4
4
  require('./chunk-ESKXG7Y6.cjs');
5
5
  require('./chunk-YDUXIENX.cjs');
6
6
  require('./chunk-H6M6L26S.cjs');
@@ -13,13 +13,14 @@ require('./chunk-7E7L3NYS.cjs');
13
13
  require('./chunk-QFPEFD67.cjs');
14
14
  require('./chunk-I7UUPD3G.cjs');
15
15
  require('./chunk-HTCSHHOR.cjs');
16
+ require('./chunk-NLSIAPZG.cjs');
16
17
  require('./chunk-33GOK7EE.cjs');
17
18
  require('./chunk-E6GWBOKV.cjs');
18
19
  require('./chunk-VPBMIYO2.cjs');
19
20
  var yup = require('yup');
20
21
 
21
22
  function schema(name) {
22
- const rule = chunkXCFZKCV2_cjs.RULES[name];
23
+ const rule = chunkYSRYWZCQ_cjs.RULES[name];
23
24
  return (options = {}) => yup.string().test(
24
25
  `pk-${name}`,
25
26
  options.message ?? rule.message,
@@ -36,7 +37,8 @@ var pk = {
36
37
  landline: schema("landline"),
37
38
  passport: schema("passport"),
38
39
  vehiclePlate: schema("vehiclePlate"),
39
- codPhone: schema("codPhone")
40
+ codPhone: schema("codPhone"),
41
+ amount: schema("amount")
40
42
  };
41
43
 
42
44
  exports.pk = pk;
package/dist/yup.d.cts CHANGED
@@ -20,6 +20,7 @@ declare const pk: {
20
20
  passport: (options?: AdapterOptions) => yup.StringSchema<string | undefined, yup.AnyObject, undefined, "">;
21
21
  vehiclePlate: (options?: AdapterOptions) => yup.StringSchema<string | undefined, yup.AnyObject, undefined, "">;
22
22
  codPhone: (options?: AdapterOptions) => yup.StringSchema<string | undefined, yup.AnyObject, undefined, "">;
23
+ amount: (options?: AdapterOptions) => yup.StringSchema<string | undefined, yup.AnyObject, undefined, "">;
23
24
  };
24
25
 
25
26
  export { AdapterOptions, pk };
package/dist/yup.d.ts CHANGED
@@ -20,6 +20,7 @@ declare const pk: {
20
20
  passport: (options?: AdapterOptions) => yup.StringSchema<string | undefined, yup.AnyObject, undefined, "">;
21
21
  vehiclePlate: (options?: AdapterOptions) => yup.StringSchema<string | undefined, yup.AnyObject, undefined, "">;
22
22
  codPhone: (options?: AdapterOptions) => yup.StringSchema<string | undefined, yup.AnyObject, undefined, "">;
23
+ amount: (options?: AdapterOptions) => yup.StringSchema<string | undefined, yup.AnyObject, undefined, "">;
23
24
  };
24
25
 
25
26
  export { AdapterOptions, pk };
package/dist/yup.js CHANGED
@@ -1,4 +1,4 @@
1
- import { RULES } from './chunk-IDTRFOQW.js';
1
+ import { RULES } from './chunk-QG5T7YQ5.js';
2
2
  import './chunk-S274QFFB.js';
3
3
  import './chunk-UYFTXD4P.js';
4
4
  import './chunk-CEPNSHIC.js';
@@ -11,6 +11,7 @@ import './chunk-E6HSKRAE.js';
11
11
  import './chunk-B7DOQ5QF.js';
12
12
  import './chunk-33QMFE2Z.js';
13
13
  import './chunk-EEVNLTB4.js';
14
+ import './chunk-NDW52ZK3.js';
14
15
  import './chunk-XOTCIXY6.js';
15
16
  import './chunk-E2XU6NOW.js';
16
17
  import './chunk-ENQ7O7VW.js';
@@ -34,7 +35,8 @@ var pk = {
34
35
  landline: schema("landline"),
35
36
  passport: schema("passport"),
36
37
  vehiclePlate: schema("vehiclePlate"),
37
- codPhone: schema("codPhone")
38
+ codPhone: schema("codPhone"),
39
+ amount: schema("amount")
38
40
  };
39
41
 
40
42
  export { pk };
package/dist/zod.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var chunkXCFZKCV2_cjs = require('./chunk-XCFZKCV2.cjs');
3
+ var chunkYSRYWZCQ_cjs = require('./chunk-YSRYWZCQ.cjs');
4
4
  require('./chunk-ESKXG7Y6.cjs');
5
5
  require('./chunk-YDUXIENX.cjs');
6
6
  require('./chunk-H6M6L26S.cjs');
@@ -13,13 +13,14 @@ require('./chunk-7E7L3NYS.cjs');
13
13
  require('./chunk-QFPEFD67.cjs');
14
14
  require('./chunk-I7UUPD3G.cjs');
15
15
  require('./chunk-HTCSHHOR.cjs');
16
+ require('./chunk-NLSIAPZG.cjs');
16
17
  require('./chunk-33GOK7EE.cjs');
17
18
  require('./chunk-E6GWBOKV.cjs');
18
19
  require('./chunk-VPBMIYO2.cjs');
19
20
  var zod = require('zod');
20
21
 
21
22
  function schema(name) {
22
- const rule = chunkXCFZKCV2_cjs.RULES[name];
23
+ const rule = chunkYSRYWZCQ_cjs.RULES[name];
23
24
  return (options = {}) => zod.z.string().refine(rule.test, { message: options.message ?? rule.message });
24
25
  }
25
26
  var pk = {
@@ -31,7 +32,8 @@ var pk = {
31
32
  landline: schema("landline"),
32
33
  passport: schema("passport"),
33
34
  vehiclePlate: schema("vehiclePlate"),
34
- codPhone: schema("codPhone")
35
+ codPhone: schema("codPhone"),
36
+ amount: schema("amount")
35
37
  };
36
38
 
37
39
  exports.pk = pk;
package/dist/zod.d.cts CHANGED
@@ -20,6 +20,7 @@ declare const pk: {
20
20
  passport: (options?: AdapterOptions) => z.ZodString;
21
21
  vehiclePlate: (options?: AdapterOptions) => z.ZodString;
22
22
  codPhone: (options?: AdapterOptions) => z.ZodString;
23
+ amount: (options?: AdapterOptions) => z.ZodString;
23
24
  };
24
25
 
25
26
  export { AdapterOptions, pk };
package/dist/zod.d.ts CHANGED
@@ -20,6 +20,7 @@ declare const pk: {
20
20
  passport: (options?: AdapterOptions) => z.ZodString;
21
21
  vehiclePlate: (options?: AdapterOptions) => z.ZodString;
22
22
  codPhone: (options?: AdapterOptions) => z.ZodString;
23
+ amount: (options?: AdapterOptions) => z.ZodString;
23
24
  };
24
25
 
25
26
  export { AdapterOptions, pk };
package/dist/zod.js CHANGED
@@ -1,4 +1,4 @@
1
- import { RULES } from './chunk-IDTRFOQW.js';
1
+ import { RULES } from './chunk-QG5T7YQ5.js';
2
2
  import './chunk-S274QFFB.js';
3
3
  import './chunk-UYFTXD4P.js';
4
4
  import './chunk-CEPNSHIC.js';
@@ -11,6 +11,7 @@ import './chunk-E6HSKRAE.js';
11
11
  import './chunk-B7DOQ5QF.js';
12
12
  import './chunk-33QMFE2Z.js';
13
13
  import './chunk-EEVNLTB4.js';
14
+ import './chunk-NDW52ZK3.js';
14
15
  import './chunk-XOTCIXY6.js';
15
16
  import './chunk-E2XU6NOW.js';
16
17
  import './chunk-ENQ7O7VW.js';
@@ -29,7 +30,8 @@ var pk = {
29
30
  landline: schema("landline"),
30
31
  passport: schema("passport"),
31
32
  vehiclePlate: schema("vehiclePlate"),
32
- codPhone: schema("codPhone")
33
+ codPhone: schema("codPhone"),
34
+ amount: schema("amount")
33
35
  };
34
36
 
35
37
  export { pk };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pakdatakit",
3
- "version": "2.5.1",
3
+ "version": "2.6.0",
4
4
  "description": "Pakistani data utilities for TypeScript and JavaScript: validate CNIC, mobile, IBAN, NTN/STRN, passport and vehicle numbers; Raast QR codes, banks, mobile networks, postal codes, districts, holidays, Hijri dates and amounts in words. No dependencies, with Zod, Valibot, Yup, Joi, Superstruct and class-validator adapters.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -419,7 +419,7 @@
419
419
  "commonjs"
420
420
  ],
421
421
  "author": "Muzamil Chaudhery",
422
- "homepage": "https://github.com/chmuzamil/pakdatakit#readme",
422
+ "homepage": "https://pakdatakit.dev/",
423
423
  "bugs": {
424
424
  "url": "https://github.com/chmuzamil/pakdatakit/issues"
425
425
  },
@@ -1,38 +0,0 @@
1
- // src/format.ts
2
- var LAKH = 1e5;
3
- var CRORE = 1e7;
4
- var pkrFormatter = new Intl.NumberFormat("en-PK", {
5
- maximumFractionDigits: 0
6
- });
7
- function assertFinite(amount) {
8
- if (typeof amount !== "number" || !Number.isFinite(amount)) {
9
- throw new RangeError(
10
- `Amount must be a finite number, received ${String(amount)}`
11
- );
12
- }
13
- }
14
- function roundTo2(value) {
15
- return Math.round(value * 100) / 100;
16
- }
17
- function formatPKR(amount) {
18
- assertFinite(amount);
19
- const rounded = Math.round(Math.abs(amount));
20
- const sign = amount < 0 && rounded !== 0 ? "-" : "";
21
- return `${sign}Rs. ${pkrFormatter.format(rounded)}`;
22
- }
23
- function formatLakh(amount) {
24
- assertFinite(amount);
25
- const sign = amount < 0 ? "-" : "";
26
- const absolute = Math.abs(amount);
27
- const crores = roundTo2(absolute / CRORE);
28
- if (crores >= 1) {
29
- return `${sign}${crores} Crore`;
30
- }
31
- const lakhs = roundTo2(absolute / LAKH);
32
- if (lakhs >= 1) {
33
- return `${sign}${lakhs} Lakh`;
34
- }
35
- return formatPKR(amount);
36
- }
37
-
38
- export { formatLakh, formatPKR };
@@ -1,41 +0,0 @@
1
- 'use strict';
2
-
3
- // src/format.ts
4
- var LAKH = 1e5;
5
- var CRORE = 1e7;
6
- var pkrFormatter = new Intl.NumberFormat("en-PK", {
7
- maximumFractionDigits: 0
8
- });
9
- function assertFinite(amount) {
10
- if (typeof amount !== "number" || !Number.isFinite(amount)) {
11
- throw new RangeError(
12
- `Amount must be a finite number, received ${String(amount)}`
13
- );
14
- }
15
- }
16
- function roundTo2(value) {
17
- return Math.round(value * 100) / 100;
18
- }
19
- function formatPKR(amount) {
20
- assertFinite(amount);
21
- const rounded = Math.round(Math.abs(amount));
22
- const sign = amount < 0 && rounded !== 0 ? "-" : "";
23
- return `${sign}Rs. ${pkrFormatter.format(rounded)}`;
24
- }
25
- function formatLakh(amount) {
26
- assertFinite(amount);
27
- const sign = amount < 0 ? "-" : "";
28
- const absolute = Math.abs(amount);
29
- const crores = roundTo2(absolute / CRORE);
30
- if (crores >= 1) {
31
- return `${sign}${crores} Crore`;
32
- }
33
- const lakhs = roundTo2(absolute / LAKH);
34
- if (lakhs >= 1) {
35
- return `${sign}${lakhs} Lakh`;
36
- }
37
- return formatPKR(amount);
38
- }
39
-
40
- exports.formatLakh = formatLakh;
41
- exports.formatPKR = formatPKR;