@pranamphd/digipin 0.1.0-alpha.1
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/LICENSE +176 -0
- package/README.md +49 -0
- package/dist/constants.d.ts +96 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +118 -0
- package/dist/constants.js.map +1 -0
- package/dist/decode.d.ts +24 -0
- package/dist/decode.d.ts.map +1 -0
- package/dist/decode.js +58 -0
- package/dist/decode.js.map +1 -0
- package/dist/encode.d.ts +30 -0
- package/dist/encode.d.ts.map +1 -0
- package/dist/encode.js +62 -0
- package/dist/encode.js.map +1 -0
- package/dist/errors.d.ts +57 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +71 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +38 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +37 -0
- package/dist/index.js.map +1 -0
- package/dist/location.d.ts +33 -0
- package/dist/location.d.ts.map +1 -0
- package/dist/location.js +16 -0
- package/dist/location.js.map +1 -0
- package/dist/normalize.d.ts +26 -0
- package/dist/normalize.d.ts.map +1 -0
- package/dist/normalize.js +34 -0
- package/dist/normalize.js.map +1 -0
- package/dist/validation.d.ts +48 -0
- package/dist/validation.d.ts.map +1 -0
- package/dist/validation.js +83 -0
- package/dist/validation.js.map +1 -0
- package/package.json +59 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
package/README.md
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# digipin-ts
|
|
2
|
+
|
|
3
|
+
DIGIPIN (Digital Postal Index Number) is a national-level, geo-coded addressing grid developed by the **Department of Posts, Ministry of Communications, Government of India**. It provides a deterministic and reversible method to represent geographic locations in India using a **10-character alphanumeric code derived from latitude and longitude**.
|
|
4
|
+
|
|
5
|
+
This repository contains a **TypeScript implementation of the DIGIPIN algorithm**, intended to enable consistent and correct adoption across platforms, applications, and systems.
|
|
6
|
+
|
|
7
|
+

|
|
8
|
+
|
|
9
|
+
## What this repository provides
|
|
10
|
+
|
|
11
|
+
- Deterministic conversion from **latitude / longitude → DIGIPIN**
|
|
12
|
+
- Reversible conversion from **DIGIPIN → geographic coordinates**
|
|
13
|
+
- Comprehensive tests to ensure correctness
|
|
14
|
+
- Implementation aligned with the **final DIGIPIN Technical Specification (March 2025)**
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## Specification reference
|
|
19
|
+
|
|
20
|
+
This project implements the **DIGIPIN (Digital Postal Index Number)** algorithm strictly according to the official technical specification published by the **Department of Posts, Ministry of Communications, Government of India**.
|
|
21
|
+
|
|
22
|
+
The authoritative specification is available at:
|
|
23
|
+
[https://www.indiapost.gov.in/digipin](https://www.indiapost.gov.in/digipin)
|
|
24
|
+
|
|
25
|
+
All implementations in this repository aim to faithfully reproduce the behavior described in the final DIGIPIN Technical Document (March 2025).
|
|
26
|
+
|
|
27
|
+
> This repository provides an independent implementation of the DIGIPIN specification and is not an official distribution of the Department of Posts unless explicitly stated otherwise.
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## Design principles
|
|
32
|
+
|
|
33
|
+
- **Specification-first**: Implementation strictly follows the DIGIPIN technical specification.
|
|
34
|
+
- **Deterministic**: The same input always produces the same output, regardless of language or platform.
|
|
35
|
+
- **No external dependencies**: Core logic is self-contained.
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## Status
|
|
40
|
+
|
|
41
|
+
This repository is under active development.
|
|
42
|
+
The library interfaces (function and type signatures) may evolve until the first stable release (`v1.0.0`).
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
## License
|
|
47
|
+
|
|
48
|
+
This project is licensed under the **Apache License, Version 2.0**.
|
|
49
|
+
See the [LICENSE](LICENSE) file for details.
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2026 Pranam
|
|
3
|
+
* ORCID: https://orcid.org/0009-0007-9316-3616
|
|
4
|
+
*
|
|
5
|
+
* This code is licensed under the Apache License, Version 2.0.
|
|
6
|
+
*
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* QR Code:
|
|
12
|
+
* 
|
|
13
|
+
* Scan the QR code to access my ORCID profile.
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* Geodetic coordinate limits (WGS-84 compatible).
|
|
17
|
+
*
|
|
18
|
+
* These constants define the full valid range of latitude and longitude
|
|
19
|
+
* values supported by the WGS-84 coordinate reference system.
|
|
20
|
+
*/
|
|
21
|
+
/**
|
|
22
|
+
* Minimum latitude for geodetic coordinates
|
|
23
|
+
*/
|
|
24
|
+
export declare const GEODETIC_LATITUDE_MIN: number;
|
|
25
|
+
/**
|
|
26
|
+
* Maximum latitude for geodetic coordinates
|
|
27
|
+
*/
|
|
28
|
+
export declare const GEODETIC_LATITUDE_MAX: number;
|
|
29
|
+
/**
|
|
30
|
+
* Minimum longitude for geodetic coordinates
|
|
31
|
+
*/
|
|
32
|
+
export declare const GEODETIC_LONGITUDE_MIN: number;
|
|
33
|
+
/**
|
|
34
|
+
* Maximum longitude for geodetic coordinates
|
|
35
|
+
*/
|
|
36
|
+
export declare const GEODETIC_LONGITUDE_MAX: number;
|
|
37
|
+
/**
|
|
38
|
+
* Official DIGIPIN supported territory bounds.
|
|
39
|
+
*
|
|
40
|
+
* Only geographic coordinates within these bounds are valid inputs
|
|
41
|
+
* for DIGIPIN encoding.
|
|
42
|
+
*/
|
|
43
|
+
/** Minimum latitude for DIGIPIN supported territory */
|
|
44
|
+
export declare const DIGIPIN_LATITUDE_MIN: number;
|
|
45
|
+
/** Maximum latitude for DIGIPIN supported territory */
|
|
46
|
+
export declare const DIGIPIN_LATITUDE_MAX: number;
|
|
47
|
+
/** Minimum longitude for DIGIPIN supported territory */
|
|
48
|
+
export declare const DIGIPIN_LONGITUDE_MIN: number;
|
|
49
|
+
/** Maximum longitude for DIGIPIN supported territory */
|
|
50
|
+
export declare const DIGIPIN_LONGITUDE_MAX: number;
|
|
51
|
+
/**
|
|
52
|
+
* Official DIGIPIN symbol set (base-16).
|
|
53
|
+
*
|
|
54
|
+
* The order of symbols is significant and MUST NOT be changed.
|
|
55
|
+
* This array represents the canonical DIGIPIN symbol sequence
|
|
56
|
+
* as defined by the specification.
|
|
57
|
+
*/
|
|
58
|
+
/**
|
|
59
|
+
* Flattened array of valid DIGIPIN symbols.
|
|
60
|
+
*/
|
|
61
|
+
export declare const DIGIPIN_SYMBOLS: readonly string[];
|
|
62
|
+
/**
|
|
63
|
+
* Length of a DIGIPIN code in characters.
|
|
64
|
+
*/
|
|
65
|
+
export declare const DIGIPIN_LENGTH: number;
|
|
66
|
+
/**
|
|
67
|
+
* Size of the DIGIPIN grid along one axis.
|
|
68
|
+
*
|
|
69
|
+
* DIGIPIN uses a fixed 4 × 4 hierarchical grid at each level.
|
|
70
|
+
*/
|
|
71
|
+
export declare const DIGIPIN_GRID_SIZE: number;
|
|
72
|
+
/**
|
|
73
|
+
* 2D array representing the DIGIPIN label grid.
|
|
74
|
+
*
|
|
75
|
+
* This grid defines the mapping between grid cell indices and
|
|
76
|
+
* DIGIPIN symbols.
|
|
77
|
+
*
|
|
78
|
+
* - Row index corresponds to latitude subdivision (south → north)
|
|
79
|
+
* - Column index corresponds to longitude subdivision (west → east)
|
|
80
|
+
*
|
|
81
|
+
* The structure and ordering match the official specification.
|
|
82
|
+
*/
|
|
83
|
+
export declare const DIGIPIN_LABEL_GRID: readonly (readonly string[])[];
|
|
84
|
+
/**
|
|
85
|
+
* Maximum possible positional error after DIGIPIN decoding, in degrees.
|
|
86
|
+
*
|
|
87
|
+
* This value is derived from the specification:
|
|
88
|
+
* 36° / 4¹⁰ / 2
|
|
89
|
+
*
|
|
90
|
+
* It represents the maximum deviation between the decoded centroid
|
|
91
|
+
* and any point within the corresponding DIGIPIN grid cell.
|
|
92
|
+
*
|
|
93
|
+
* This constant is primarily intended for testing and conformance checks.
|
|
94
|
+
*/
|
|
95
|
+
export declare const DIGIPIN_MAX_DECODE_ERROR_DEGREES: number;
|
|
96
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH;;;;;GAKG;AAEH;;GAEG;AACH,eAAO,MAAM,qBAAqB,EAAE,MAAY,CAAC;AACjD;;GAEG;AACH,eAAO,MAAM,qBAAqB,EAAE,MAAW,CAAC;AAChD;;GAEG;AACH,eAAO,MAAM,sBAAsB,EAAE,MAAa,CAAC;AACnD;;GAEG;AACH,eAAO,MAAM,sBAAsB,EAAE,MAAY,CAAC;AAGlD;;;;;GAKG;AAEH,uDAAuD;AACvD,eAAO,MAAM,oBAAoB,EAAE,MAAY,CAAC;AAChD,uDAAuD;AACvD,eAAO,MAAM,oBAAoB,EAAE,MAAa,CAAC;AACjD,wDAAwD;AACxD,eAAO,MAAM,qBAAqB,EAAE,MAAa,CAAC;AAClD,wDAAwD;AACxD,eAAO,MAAM,qBAAqB,EAAE,MAAa,CAAC;AAElD;;;;;;GAMG;AAEH;;GAEG;AACH,eAAO,MAAM,eAAe,EAAE,SAAS,MAAM,EAiB5C,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,cAAc,EAAE,MAAW,CAAC;AAEzC;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,EAAE,MAAU,CAAC;AAE3C;;;;;;;;;;GAUG;AACH,eAAO,MAAM,kBAAkB,EAAE,SAAS,CAAC,SAAS,MAAM,EAAE,CAAC,EAK5D,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,gCAAgC,EAAE,MAA8B,CAAC"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2026 Pranam
|
|
3
|
+
* ORCID: https://orcid.org/0009-0007-9316-3616
|
|
4
|
+
*
|
|
5
|
+
* This code is licensed under the Apache License, Version 2.0.
|
|
6
|
+
*
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* QR Code:
|
|
12
|
+
* 
|
|
13
|
+
* Scan the QR code to access my ORCID profile.
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* Geodetic coordinate limits (WGS-84 compatible).
|
|
17
|
+
*
|
|
18
|
+
* These constants define the full valid range of latitude and longitude
|
|
19
|
+
* values supported by the WGS-84 coordinate reference system.
|
|
20
|
+
*/
|
|
21
|
+
/**
|
|
22
|
+
* Minimum latitude for geodetic coordinates
|
|
23
|
+
*/
|
|
24
|
+
export const GEODETIC_LATITUDE_MIN = -90;
|
|
25
|
+
/**
|
|
26
|
+
* Maximum latitude for geodetic coordinates
|
|
27
|
+
*/
|
|
28
|
+
export const GEODETIC_LATITUDE_MAX = 90;
|
|
29
|
+
/**
|
|
30
|
+
* Minimum longitude for geodetic coordinates
|
|
31
|
+
*/
|
|
32
|
+
export const GEODETIC_LONGITUDE_MIN = -180;
|
|
33
|
+
/**
|
|
34
|
+
* Maximum longitude for geodetic coordinates
|
|
35
|
+
*/
|
|
36
|
+
export const GEODETIC_LONGITUDE_MAX = 180;
|
|
37
|
+
/**
|
|
38
|
+
* Official DIGIPIN supported territory bounds.
|
|
39
|
+
*
|
|
40
|
+
* Only geographic coordinates within these bounds are valid inputs
|
|
41
|
+
* for DIGIPIN encoding.
|
|
42
|
+
*/
|
|
43
|
+
/** Minimum latitude for DIGIPIN supported territory */
|
|
44
|
+
export const DIGIPIN_LATITUDE_MIN = 2.5;
|
|
45
|
+
/** Maximum latitude for DIGIPIN supported territory */
|
|
46
|
+
export const DIGIPIN_LATITUDE_MAX = 38.5;
|
|
47
|
+
/** Minimum longitude for DIGIPIN supported territory */
|
|
48
|
+
export const DIGIPIN_LONGITUDE_MIN = 63.5;
|
|
49
|
+
/** Maximum longitude for DIGIPIN supported territory */
|
|
50
|
+
export const DIGIPIN_LONGITUDE_MAX = 99.5;
|
|
51
|
+
/**
|
|
52
|
+
* Official DIGIPIN symbol set (base-16).
|
|
53
|
+
*
|
|
54
|
+
* The order of symbols is significant and MUST NOT be changed.
|
|
55
|
+
* This array represents the canonical DIGIPIN symbol sequence
|
|
56
|
+
* as defined by the specification.
|
|
57
|
+
*/
|
|
58
|
+
/**
|
|
59
|
+
* Flattened array of valid DIGIPIN symbols.
|
|
60
|
+
*/
|
|
61
|
+
export const DIGIPIN_SYMBOLS = [
|
|
62
|
+
"F",
|
|
63
|
+
"C",
|
|
64
|
+
"9",
|
|
65
|
+
"8",
|
|
66
|
+
"J",
|
|
67
|
+
"3",
|
|
68
|
+
"2",
|
|
69
|
+
"7",
|
|
70
|
+
"K",
|
|
71
|
+
"4",
|
|
72
|
+
"5",
|
|
73
|
+
"6",
|
|
74
|
+
"L",
|
|
75
|
+
"M",
|
|
76
|
+
"P",
|
|
77
|
+
"T",
|
|
78
|
+
];
|
|
79
|
+
/**
|
|
80
|
+
* Length of a DIGIPIN code in characters.
|
|
81
|
+
*/
|
|
82
|
+
export const DIGIPIN_LENGTH = 10;
|
|
83
|
+
/**
|
|
84
|
+
* Size of the DIGIPIN grid along one axis.
|
|
85
|
+
*
|
|
86
|
+
* DIGIPIN uses a fixed 4 × 4 hierarchical grid at each level.
|
|
87
|
+
*/
|
|
88
|
+
export const DIGIPIN_GRID_SIZE = 4;
|
|
89
|
+
/**
|
|
90
|
+
* 2D array representing the DIGIPIN label grid.
|
|
91
|
+
*
|
|
92
|
+
* This grid defines the mapping between grid cell indices and
|
|
93
|
+
* DIGIPIN symbols.
|
|
94
|
+
*
|
|
95
|
+
* - Row index corresponds to latitude subdivision (south → north)
|
|
96
|
+
* - Column index corresponds to longitude subdivision (west → east)
|
|
97
|
+
*
|
|
98
|
+
* The structure and ordering match the official specification.
|
|
99
|
+
*/
|
|
100
|
+
export const DIGIPIN_LABEL_GRID = [
|
|
101
|
+
["F", "C", "9", "8"],
|
|
102
|
+
["J", "3", "2", "7"],
|
|
103
|
+
["K", "4", "5", "6"],
|
|
104
|
+
["L", "M", "P", "T"],
|
|
105
|
+
];
|
|
106
|
+
/**
|
|
107
|
+
* Maximum possible positional error after DIGIPIN decoding, in degrees.
|
|
108
|
+
*
|
|
109
|
+
* This value is derived from the specification:
|
|
110
|
+
* 36° / 4¹⁰ / 2
|
|
111
|
+
*
|
|
112
|
+
* It represents the maximum deviation between the decoded centroid
|
|
113
|
+
* and any point within the corresponding DIGIPIN grid cell.
|
|
114
|
+
*
|
|
115
|
+
* This constant is primarily intended for testing and conformance checks.
|
|
116
|
+
*/
|
|
117
|
+
export const DIGIPIN_MAX_DECODE_ERROR_DEGREES = 0.0000171661376953125;
|
|
118
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH;;;;;GAKG;AAEH;;GAEG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAW,CAAC,EAAE,CAAC;AACjD;;GAEG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAW,EAAE,CAAC;AAChD;;GAEG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAW,CAAC,GAAG,CAAC;AACnD;;GAEG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAW,GAAG,CAAC;AAGlD;;;;;GAKG;AAEH,uDAAuD;AACvD,MAAM,CAAC,MAAM,oBAAoB,GAAW,GAAG,CAAC;AAChD,uDAAuD;AACvD,MAAM,CAAC,MAAM,oBAAoB,GAAW,IAAI,CAAC;AACjD,wDAAwD;AACxD,MAAM,CAAC,MAAM,qBAAqB,GAAW,IAAI,CAAC;AAClD,wDAAwD;AACxD,MAAM,CAAC,MAAM,qBAAqB,GAAW,IAAI,CAAC;AAElD;;;;;;GAMG;AAEH;;GAEG;AACH,MAAM,CAAC,MAAM,eAAe,GAAsB;IAChD,GAAG;IACH,GAAG;IACH,GAAG;IACH,GAAG;IACH,GAAG;IACH,GAAG;IACH,GAAG;IACH,GAAG;IACH,GAAG;IACH,GAAG;IACH,GAAG;IACH,GAAG;IACH,GAAG;IACH,GAAG;IACH,GAAG;IACH,GAAG;CACJ,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,cAAc,GAAW,EAAE,CAAC;AAEzC;;;;GAIG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAW,CAAC,CAAC;AAE3C;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAmC;IAChE,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC;IACpB,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC;IACpB,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC;IACpB,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC;CACrB,CAAC;AAEF;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,gCAAgC,GAAW,qBAAqB,CAAC"}
|
package/dist/decode.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2026 Pranam
|
|
3
|
+
* ORCID: https://orcid.org/0009-0007-9316-3616
|
|
4
|
+
*
|
|
5
|
+
* This code is licensed under the Apache License, Version 2.0.
|
|
6
|
+
*
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* QR Code:
|
|
12
|
+
* 
|
|
13
|
+
* Scan the QR code to access my ORCID profile.
|
|
14
|
+
*/
|
|
15
|
+
import type { Location } from "./location.js";
|
|
16
|
+
/**
|
|
17
|
+
* Decodes a DIGIPIN into geodetic coordinates.
|
|
18
|
+
*
|
|
19
|
+
* @param digipin - DIGIPIN string (separators allowed)
|
|
20
|
+
* @returns The geodetic coordinates of the DIGIPIN
|
|
21
|
+
* @throws Error if the DIGIPIN is invalid
|
|
22
|
+
*/
|
|
23
|
+
export declare function decode(digipin: string): Location;
|
|
24
|
+
//# sourceMappingURL=decode.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decode.d.ts","sourceRoot":"","sources":["../src/decode.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAYH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAmB9C;;;;;;GAMG;AACH,wBAAgB,MAAM,CAAC,OAAO,EAAE,MAAM,GAAG,QAAQ,CAkChD"}
|
package/dist/decode.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2026 Pranam
|
|
3
|
+
* ORCID: https://orcid.org/0009-0007-9316-3616
|
|
4
|
+
*
|
|
5
|
+
* This code is licensed under the Apache License, Version 2.0.
|
|
6
|
+
*
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* QR Code:
|
|
12
|
+
* 
|
|
13
|
+
* Scan the QR code to access my ORCID profile.
|
|
14
|
+
*/
|
|
15
|
+
import { DIGIPIN_GRID_SIZE, DIGIPIN_LABEL_GRID, DIGIPIN_LATITUDE_MIN, DIGIPIN_LATITUDE_MAX, DIGIPIN_LONGITUDE_MIN, DIGIPIN_LONGITUDE_MAX, } from "./constants.js";
|
|
16
|
+
import { DigipinError } from "./errors.js";
|
|
17
|
+
import { normalize } from "./normalize.js";
|
|
18
|
+
import { validateDigipinFormat } from "./validation.js";
|
|
19
|
+
/**
|
|
20
|
+
* Mapping from DIGIPIN symbol to its grid position.
|
|
21
|
+
*
|
|
22
|
+
* Key: DIGIPIN symbol
|
|
23
|
+
* Value: [row, column]
|
|
24
|
+
*/
|
|
25
|
+
const DIGIPIN_SYMBOL_POSITION_MAP = new Map(DIGIPIN_LABEL_GRID.flatMap((row, rowIndex) => row.map((symbol, columnIndex) => [symbol, [rowIndex, columnIndex]])));
|
|
26
|
+
/**
|
|
27
|
+
* Decodes a DIGIPIN into geodetic coordinates.
|
|
28
|
+
*
|
|
29
|
+
* @param digipin - DIGIPIN string (separators allowed)
|
|
30
|
+
* @returns The geodetic coordinates of the DIGIPIN
|
|
31
|
+
* @throws Error if the DIGIPIN is invalid
|
|
32
|
+
*/
|
|
33
|
+
export function decode(digipin) {
|
|
34
|
+
const normalized = normalize(digipin);
|
|
35
|
+
validateDigipinFormat(normalized);
|
|
36
|
+
let latitudeMin = DIGIPIN_LATITUDE_MIN;
|
|
37
|
+
let latitudeMax = DIGIPIN_LATITUDE_MAX;
|
|
38
|
+
let longitudeMin = DIGIPIN_LONGITUDE_MIN;
|
|
39
|
+
let longitudeMax = DIGIPIN_LONGITUDE_MAX;
|
|
40
|
+
for (const symbol of normalized) {
|
|
41
|
+
const position = DIGIPIN_SYMBOL_POSITION_MAP.get(symbol);
|
|
42
|
+
if (position === undefined) {
|
|
43
|
+
throw DigipinError.invalidDigipinFormat();
|
|
44
|
+
}
|
|
45
|
+
const [row, column] = position;
|
|
46
|
+
const latitudeStep = (latitudeMax - latitudeMin) / DIGIPIN_GRID_SIZE;
|
|
47
|
+
const longitudeStep = (longitudeMax - longitudeMin) / DIGIPIN_GRID_SIZE;
|
|
48
|
+
latitudeMax -= row * latitudeStep;
|
|
49
|
+
latitudeMin = latitudeMax - latitudeStep;
|
|
50
|
+
longitudeMin += column * longitudeStep;
|
|
51
|
+
longitudeMax = longitudeMin + longitudeStep;
|
|
52
|
+
}
|
|
53
|
+
return {
|
|
54
|
+
latitude: (latitudeMin + latitudeMax) / 2,
|
|
55
|
+
longitude: (longitudeMin + longitudeMax) / 2,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=decode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decode.js","sourceRoot":"","sources":["../src/decode.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EACL,iBAAiB,EACjB,kBAAkB,EAClB,oBAAoB,EACpB,oBAAoB,EACpB,qBAAqB,EACrB,qBAAqB,GACtB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAExD;;;;;GAKG;AACH,MAAM,2BAA2B,GAG7B,IAAI,GAAG,CACT,kBAAkB,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,QAAQ,EAAE,EAAE,CAC3C,GAAG,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,WAAW,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAU,CAAC,CAC7E,CACF,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,UAAU,MAAM,CAAC,OAAe;IACpC,MAAM,UAAU,GAAW,SAAS,CAAC,OAAO,CAAC,CAAC;IAC9C,qBAAqB,CAAC,UAAU,CAAC,CAAC;IAElC,IAAI,WAAW,GAAW,oBAAoB,CAAC;IAC/C,IAAI,WAAW,GAAW,oBAAoB,CAAC;IAC/C,IAAI,YAAY,GAAW,qBAAqB,CAAC;IACjD,IAAI,YAAY,GAAW,qBAAqB,CAAC;IAEjD,KAAK,MAAM,MAAM,IAAI,UAAU,EAAE,CAAC;QAChC,MAAM,QAAQ,GAAG,2BAA2B,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QAEzD,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;YAC3B,MAAM,YAAY,CAAC,oBAAoB,EAAE,CAAC;QAC5C,CAAC;QAED,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,GAAG,QAAQ,CAAC;QAE/B,MAAM,YAAY,GAChB,CAAC,WAAW,GAAG,WAAW,CAAC,GAAG,iBAAiB,CAAC;QAClD,MAAM,aAAa,GACjB,CAAC,YAAY,GAAG,YAAY,CAAC,GAAG,iBAAiB,CAAC;QAEpD,WAAW,IAAI,GAAG,GAAG,YAAY,CAAC;QAClC,WAAW,GAAG,WAAW,GAAG,YAAY,CAAC;QAEzC,YAAY,IAAI,MAAM,GAAG,aAAa,CAAC;QACvC,YAAY,GAAG,YAAY,GAAG,aAAa,CAAC;IAC9C,CAAC;IAED,OAAO;QACL,QAAQ,EAAE,CAAC,WAAW,GAAG,WAAW,CAAC,GAAG,CAAC;QACzC,SAAS,EAAE,CAAC,YAAY,GAAG,YAAY,CAAC,GAAG,CAAC;KAC7C,CAAC;AACJ,CAAC"}
|
package/dist/encode.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2026 Pranam
|
|
3
|
+
* ORCID: https://orcid.org/0009-0007-9316-3616
|
|
4
|
+
*
|
|
5
|
+
* This code is licensed under the Apache License, Version 2.0.
|
|
6
|
+
*
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* QR Code:
|
|
12
|
+
* 
|
|
13
|
+
* Scan the QR code to access my ORCID profile.
|
|
14
|
+
*/
|
|
15
|
+
import type { Location } from "./location.js";
|
|
16
|
+
/**
|
|
17
|
+
* Encode geographic coordinates into a canonical DIGIPIN.
|
|
18
|
+
*
|
|
19
|
+
* This function implements the official DIGIPIN hierarchical 4 × 4 grid
|
|
20
|
+
* encoding algorithm exactly as defined by the specification.
|
|
21
|
+
*
|
|
22
|
+
* The returned DIGIPIN contains no separators and is always
|
|
23
|
+
* exactly DIGIPIN_LENGTH characters long.
|
|
24
|
+
*
|
|
25
|
+
* @param location - Geographic location containing latitude and longitude
|
|
26
|
+
* @returns Encoded DIGIPIN string
|
|
27
|
+
* @throws Error if the geodetic coordinates are invalid or if the location is outside the supported territory
|
|
28
|
+
*/
|
|
29
|
+
export declare function encode(location: Location): string;
|
|
30
|
+
//# sourceMappingURL=encode.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encode.d.ts","sourceRoot":"","sources":["../src/encode.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAiBH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAY9C;;;;;;;;;;;;GAYG;AACH,wBAAgB,MAAM,CAAC,QAAQ,EAAE,QAAQ,GAAG,MAAM,CA0CjD"}
|
package/dist/encode.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2026 Pranam
|
|
3
|
+
* ORCID: https://orcid.org/0009-0007-9316-3616
|
|
4
|
+
*
|
|
5
|
+
* This code is licensed under the Apache License, Version 2.0.
|
|
6
|
+
*
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* QR Code:
|
|
12
|
+
* 
|
|
13
|
+
* Scan the QR code to access my ORCID profile.
|
|
14
|
+
*/
|
|
15
|
+
import { DIGIPIN_LATITUDE_MIN, DIGIPIN_LATITUDE_MAX, DIGIPIN_LONGITUDE_MIN, DIGIPIN_LONGITUDE_MAX, DIGIPIN_GRID_SIZE, DIGIPIN_LENGTH, DIGIPIN_LABEL_GRID, } from "./constants.js";
|
|
16
|
+
import { validateGeodeticCoordinates, validateDigipinTerritory, } from "./validation.js";
|
|
17
|
+
function getSymbolAt(row, column) {
|
|
18
|
+
const symbol = DIGIPIN_LABEL_GRID[row]?.[column];
|
|
19
|
+
if (symbol === undefined) {
|
|
20
|
+
throw new Error("Internal DIGIPIN grid invariant violated.");
|
|
21
|
+
}
|
|
22
|
+
return symbol;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Encode geographic coordinates into a canonical DIGIPIN.
|
|
26
|
+
*
|
|
27
|
+
* This function implements the official DIGIPIN hierarchical 4 × 4 grid
|
|
28
|
+
* encoding algorithm exactly as defined by the specification.
|
|
29
|
+
*
|
|
30
|
+
* The returned DIGIPIN contains no separators and is always
|
|
31
|
+
* exactly DIGIPIN_LENGTH characters long.
|
|
32
|
+
*
|
|
33
|
+
* @param location - Geographic location containing latitude and longitude
|
|
34
|
+
* @returns Encoded DIGIPIN string
|
|
35
|
+
* @throws Error if the geodetic coordinates are invalid or if the location is outside the supported territory
|
|
36
|
+
*/
|
|
37
|
+
export function encode(location) {
|
|
38
|
+
validateGeodeticCoordinates(location);
|
|
39
|
+
validateDigipinTerritory(location);
|
|
40
|
+
let latitudeMin = DIGIPIN_LATITUDE_MIN;
|
|
41
|
+
let latitudeMax = DIGIPIN_LATITUDE_MAX;
|
|
42
|
+
let longitudeMin = DIGIPIN_LONGITUDE_MIN;
|
|
43
|
+
let longitudeMax = DIGIPIN_LONGITUDE_MAX;
|
|
44
|
+
let digipin = "";
|
|
45
|
+
for (let level = 0; level < DIGIPIN_LENGTH; level++) {
|
|
46
|
+
const latitudeStep = (latitudeMax - latitudeMin) / DIGIPIN_GRID_SIZE;
|
|
47
|
+
const longitudeStep = (longitudeMax - longitudeMin) / DIGIPIN_GRID_SIZE;
|
|
48
|
+
let rowIndex = Math.floor((latitudeMax - location.latitude) / latitudeStep);
|
|
49
|
+
let columnIndex = Math.floor((location.longitude - longitudeMin) / longitudeStep);
|
|
50
|
+
// Clamp row and column indices to valid grid bounds
|
|
51
|
+
rowIndex = Math.min(rowIndex, DIGIPIN_GRID_SIZE - 1);
|
|
52
|
+
columnIndex = Math.min(columnIndex, DIGIPIN_GRID_SIZE - 1);
|
|
53
|
+
const symbol = getSymbolAt(rowIndex, columnIndex);
|
|
54
|
+
digipin += symbol;
|
|
55
|
+
latitudeMax -= rowIndex * latitudeStep;
|
|
56
|
+
latitudeMin = latitudeMax - latitudeStep;
|
|
57
|
+
longitudeMin += columnIndex * longitudeStep;
|
|
58
|
+
longitudeMax = longitudeMin + longitudeStep;
|
|
59
|
+
}
|
|
60
|
+
return digipin;
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=encode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encode.js","sourceRoot":"","sources":["../src/encode.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EACL,oBAAoB,EACpB,oBAAoB,EACpB,qBAAqB,EACrB,qBAAqB,EACrB,iBAAiB,EACjB,cAAc,EACd,kBAAkB,GACnB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EACL,2BAA2B,EAC3B,wBAAwB,GACzB,MAAM,iBAAiB,CAAC;AAIzB,SAAS,WAAW,CAAC,GAAW,EAAE,MAAc;IAC9C,MAAM,MAAM,GAAG,kBAAkB,CAAC,GAAG,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC;IAEjD,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QACzB,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC;IAC/D,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,MAAM,CAAC,QAAkB;IACvC,2BAA2B,CAAC,QAAQ,CAAC,CAAC;IACtC,wBAAwB,CAAC,QAAQ,CAAC,CAAC;IAEnC,IAAI,WAAW,GAAW,oBAAoB,CAAC;IAC/C,IAAI,WAAW,GAAW,oBAAoB,CAAC;IAC/C,IAAI,YAAY,GAAW,qBAAqB,CAAC;IACjD,IAAI,YAAY,GAAW,qBAAqB,CAAC;IAEjD,IAAI,OAAO,GAAW,EAAE,CAAC;IAEzB,KAAK,IAAI,KAAK,GAAW,CAAC,EAAE,KAAK,GAAG,cAAc,EAAE,KAAK,EAAE,EAAE,CAAC;QAC5D,MAAM,YAAY,GAChB,CAAC,WAAW,GAAG,WAAW,CAAC,GAAG,iBAAiB,CAAC;QAElD,MAAM,aAAa,GACjB,CAAC,YAAY,GAAG,YAAY,CAAC,GAAG,iBAAiB,CAAC;QAEpD,IAAI,QAAQ,GAAW,IAAI,CAAC,KAAK,CAC/B,CAAC,WAAW,GAAG,QAAQ,CAAC,QAAQ,CAAC,GAAG,YAAY,CACjD,CAAC;QAEF,IAAI,WAAW,GAAW,IAAI,CAAC,KAAK,CAClC,CAAC,QAAQ,CAAC,SAAS,GAAG,YAAY,CAAC,GAAG,aAAa,CACpD,CAAC;QAEF,oDAAoD;QACpD,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,iBAAiB,GAAG,CAAC,CAAC,CAAC;QACrD,WAAW,GAAG,IAAI,CAAC,GAAG,CAAC,WAAW,EAAE,iBAAiB,GAAG,CAAC,CAAC,CAAC;QAE3D,MAAM,MAAM,GAAW,WAAW,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC;QAE1D,OAAO,IAAI,MAAM,CAAC;QAElB,WAAW,IAAI,QAAQ,GAAG,YAAY,CAAC;QACvC,WAAW,GAAG,WAAW,GAAG,YAAY,CAAC;QAEzC,YAAY,IAAI,WAAW,GAAG,aAAa,CAAC;QAC5C,YAAY,GAAG,YAAY,GAAG,aAAa,CAAC;IAC9C,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2026 Pranam
|
|
3
|
+
* ORCID: https://orcid.org/0009-0007-9316-3616
|
|
4
|
+
*
|
|
5
|
+
* This code is licensed under the Apache License, Version 2.0.
|
|
6
|
+
*
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* QR Code:
|
|
12
|
+
* 
|
|
13
|
+
* Scan the QR code to access my ORCID profile.
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* Custom error class for DIGIPIN-related errors.
|
|
17
|
+
* @category Errors
|
|
18
|
+
*
|
|
19
|
+
*/
|
|
20
|
+
export declare class DigipinError extends Error {
|
|
21
|
+
/**
|
|
22
|
+
* Error code indicating the type of DIGIPIN error.
|
|
23
|
+
*/
|
|
24
|
+
readonly code: "InvalidLatitude" | "InvalidLongitude" | "OutsideSupportedTerritory" | "InvalidDigipinLength" | "InvalidDigipinFormat";
|
|
25
|
+
/**
|
|
26
|
+
* Creates a new DigipinError instance.
|
|
27
|
+
* @param code Error code indicating the type of error
|
|
28
|
+
* @param message Human-readable error message
|
|
29
|
+
*/
|
|
30
|
+
constructor(code: DigipinError["code"], message: string);
|
|
31
|
+
/**
|
|
32
|
+
* Creates an error for invalid latitude values.
|
|
33
|
+
* @returns DigipinError instance for invalid latitude
|
|
34
|
+
*/
|
|
35
|
+
static invalidLatitude(): DigipinError;
|
|
36
|
+
/**
|
|
37
|
+
* Creates an error for invalid longitude values.
|
|
38
|
+
* @returns DigipinError instance for invalid longitude
|
|
39
|
+
*/
|
|
40
|
+
static invalidLongitude(): DigipinError;
|
|
41
|
+
/**
|
|
42
|
+
* Creates an error for locations outside the DIGIPIN supported territory.
|
|
43
|
+
* @returns DigipinError instance for locations outside the supported territory
|
|
44
|
+
*/
|
|
45
|
+
static outsideSupportedTerritory(): DigipinError;
|
|
46
|
+
/**
|
|
47
|
+
* Creates an error for DIGIPINs with invalid length.
|
|
48
|
+
* @returns DigipinError instance for invalid DIGIPIN length
|
|
49
|
+
*/
|
|
50
|
+
static invalidDigipinLength(): DigipinError;
|
|
51
|
+
/**
|
|
52
|
+
* Creates an error for DIGIPINs with invalid format or symbols.
|
|
53
|
+
* @returns DigipinError instance for invalid DIGIPIN format
|
|
54
|
+
*/
|
|
55
|
+
static invalidDigipinFormat(): DigipinError;
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH;;;;GAIG;AACH,qBAAa,YAAa,SAAQ,KAAK;IACrC;;OAEG;IACH,SAAgB,IAAI,EAChB,iBAAiB,GACjB,kBAAkB,GAClB,2BAA2B,GAC3B,sBAAsB,GACtB,sBAAsB,CAAC;IAE3B;;;;OAIG;gBACgB,IAAI,EAAE,YAAY,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,MAAM;IAM9D;;;OAGG;IACH,MAAM,CAAC,eAAe,IAAI,YAAY;IAMtC;;;OAGG;IACH,MAAM,CAAC,gBAAgB,IAAI,YAAY;IAMvC;;;OAGG;IACH,MAAM,CAAC,yBAAyB,IAAI,YAAY;IAMhD;;;OAGG;IACH,MAAM,CAAC,oBAAoB,IAAI,YAAY;IAO3C;;;OAGG;IACH,MAAM,CAAC,oBAAoB,IAAI,YAAY;CAM5C"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2026 Pranam
|
|
3
|
+
* ORCID: https://orcid.org/0009-0007-9316-3616
|
|
4
|
+
*
|
|
5
|
+
* This code is licensed under the Apache License, Version 2.0.
|
|
6
|
+
*
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* QR Code:
|
|
12
|
+
* 
|
|
13
|
+
* Scan the QR code to access my ORCID profile.
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* Custom error class for DIGIPIN-related errors.
|
|
17
|
+
* @category Errors
|
|
18
|
+
*
|
|
19
|
+
*/
|
|
20
|
+
export class DigipinError extends Error {
|
|
21
|
+
/**
|
|
22
|
+
* Error code indicating the type of DIGIPIN error.
|
|
23
|
+
*/
|
|
24
|
+
code;
|
|
25
|
+
/**
|
|
26
|
+
* Creates a new DigipinError instance.
|
|
27
|
+
* @param code Error code indicating the type of error
|
|
28
|
+
* @param message Human-readable error message
|
|
29
|
+
*/
|
|
30
|
+
constructor(code, message) {
|
|
31
|
+
super(message);
|
|
32
|
+
this.name = "DigipinError";
|
|
33
|
+
this.code = code;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Creates an error for invalid latitude values.
|
|
37
|
+
* @returns DigipinError instance for invalid latitude
|
|
38
|
+
*/
|
|
39
|
+
static invalidLatitude() {
|
|
40
|
+
return new DigipinError("InvalidLatitude", "Latitude is outside geodetic bounds.");
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Creates an error for invalid longitude values.
|
|
44
|
+
* @returns DigipinError instance for invalid longitude
|
|
45
|
+
*/
|
|
46
|
+
static invalidLongitude() {
|
|
47
|
+
return new DigipinError("InvalidLongitude", "Longitude is outside geodetic bounds.");
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Creates an error for locations outside the DIGIPIN supported territory.
|
|
51
|
+
* @returns DigipinError instance for locations outside the supported territory
|
|
52
|
+
*/
|
|
53
|
+
static outsideSupportedTerritory() {
|
|
54
|
+
return new DigipinError("OutsideSupportedTerritory", "Location is outside the DIGIPIN supported territory.");
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Creates an error for DIGIPINs with invalid length.
|
|
58
|
+
* @returns DigipinError instance for invalid DIGIPIN length
|
|
59
|
+
*/
|
|
60
|
+
static invalidDigipinLength() {
|
|
61
|
+
return new DigipinError("InvalidDigipinLength", "DIGIPIN does not conform to required length.");
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Creates an error for DIGIPINs with invalid format or symbols.
|
|
65
|
+
* @returns DigipinError instance for invalid DIGIPIN format
|
|
66
|
+
*/
|
|
67
|
+
static invalidDigipinFormat() {
|
|
68
|
+
return new DigipinError("InvalidDigipinFormat", "DIGIPIN contains invalid symbols or format.");
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH;;;;GAIG;AACH,MAAM,OAAO,YAAa,SAAQ,KAAK;IACrC;;OAEG;IACa,IAAI,CAKO;IAE3B;;;;OAIG;IACH,YAAmB,IAA0B,EAAE,OAAe;QAC5D,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;QAC3B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,eAAe;QACpB,OAAO,IAAI,YAAY,CACrB,iBAAiB,EACjB,sCAAsC,CACvC,CAAC;IACJ,CAAC;IACD;;;OAGG;IACH,MAAM,CAAC,gBAAgB;QACrB,OAAO,IAAI,YAAY,CACrB,kBAAkB,EAClB,uCAAuC,CACxC,CAAC;IACJ,CAAC;IACD;;;OAGG;IACH,MAAM,CAAC,yBAAyB;QAC9B,OAAO,IAAI,YAAY,CACrB,2BAA2B,EAC3B,sDAAsD,CACvD,CAAC;IACJ,CAAC;IACD;;;OAGG;IACH,MAAM,CAAC,oBAAoB;QACzB,OAAO,IAAI,YAAY,CACrB,sBAAsB,EACtB,8CAA8C,CAC/C,CAAC;IACJ,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,oBAAoB;QACzB,OAAO,IAAI,YAAY,CACrB,sBAAsB,EACtB,6CAA6C,CAC9C,CAAC;IACJ,CAAC;CACF"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2026 Pranam
|
|
3
|
+
* ORCID: https://orcid.org/0009-0007-9316-3616
|
|
4
|
+
*
|
|
5
|
+
* This code is licensed under the Apache License, Version 2.0.
|
|
6
|
+
*
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* QR Code:
|
|
12
|
+
* 
|
|
13
|
+
* Scan the QR code to access my ORCID profile.
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* This library provides functions to encode geodetic coordinates into 10 character DIGIPINs
|
|
17
|
+
* and decode DIGIPINs back into geodetic coordinates.
|
|
18
|
+
* The DIGIPIN system divides the Earth's surface into a grid of cells, each represented by a unique 10 character code.
|
|
19
|
+
* The library includes functions for normalization and validation of DIGIPINs.
|
|
20
|
+
* It is implemented in TypeScript and can be used in both Node.js and browser environments.
|
|
21
|
+
*
|
|
22
|
+
* @packageDocumentation
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* import { encode, decode } from "@pranamphd/digipin";
|
|
27
|
+
*
|
|
28
|
+
* const digipin = encode(28.6139, 77.209); // Encode coordinates to DIGIPIN
|
|
29
|
+
* console.log(digipin); // Example output: "39J438TJC7"
|
|
30
|
+
*
|
|
31
|
+
* const location = decode(digipin); // Decode DIGIPIN back to coordinates
|
|
32
|
+
* console.log(location); // Example output: { latitude: 28.6139, longitude: 77.209 }
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export { encode } from "./encode.js";
|
|
36
|
+
export { decode } from "./decode.js";
|
|
37
|
+
export type { Location } from "./location.js";
|
|
38
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,YAAY,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2026 Pranam
|
|
3
|
+
* ORCID: https://orcid.org/0009-0007-9316-3616
|
|
4
|
+
*
|
|
5
|
+
* This code is licensed under the Apache License, Version 2.0.
|
|
6
|
+
*
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* QR Code:
|
|
12
|
+
* 
|
|
13
|
+
* Scan the QR code to access my ORCID profile.
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* This library provides functions to encode geodetic coordinates into 10 character DIGIPINs
|
|
17
|
+
* and decode DIGIPINs back into geodetic coordinates.
|
|
18
|
+
* The DIGIPIN system divides the Earth's surface into a grid of cells, each represented by a unique 10 character code.
|
|
19
|
+
* The library includes functions for normalization and validation of DIGIPINs.
|
|
20
|
+
* It is implemented in TypeScript and can be used in both Node.js and browser environments.
|
|
21
|
+
*
|
|
22
|
+
* @packageDocumentation
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* import { encode, decode } from "@pranamphd/digipin";
|
|
27
|
+
*
|
|
28
|
+
* const digipin = encode(28.6139, 77.209); // Encode coordinates to DIGIPIN
|
|
29
|
+
* console.log(digipin); // Example output: "39J438TJC7"
|
|
30
|
+
*
|
|
31
|
+
* const location = decode(digipin); // Decode DIGIPIN back to coordinates
|
|
32
|
+
* console.log(location); // Example output: { latitude: 28.6139, longitude: 77.209 }
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export { encode } from "./encode.js";
|
|
36
|
+
export { decode } from "./decode.js";
|
|
37
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2026 Pranam
|
|
3
|
+
* ORCID: https://orcid.org/0009-0007-9316-3616
|
|
4
|
+
*
|
|
5
|
+
* This code is licensed under the Apache License, Version 2.0.
|
|
6
|
+
*
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* QR Code:
|
|
12
|
+
* 
|
|
13
|
+
* Scan the QR code to access my ORCID profile.
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* Represents a geographic location expressed as latitude and longitude.
|
|
17
|
+
*
|
|
18
|
+
* Both values are expressed in decimal degrees using the WGS-84
|
|
19
|
+
* coordinate reference system.
|
|
20
|
+
*
|
|
21
|
+
* This type is used as the return value of DIGIPIN decoding operations.
|
|
22
|
+
*/
|
|
23
|
+
export type Location = {
|
|
24
|
+
/**
|
|
25
|
+
* Latitude in decimal degrees.
|
|
26
|
+
*/
|
|
27
|
+
latitude: number;
|
|
28
|
+
/**
|
|
29
|
+
* Longitude in decimal degrees.
|
|
30
|
+
*/
|
|
31
|
+
longitude: number;
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=location.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"location.d.ts","sourceRoot":"","sources":["../src/location.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH;;;;;;;GAOG;AACH,MAAM,MAAM,QAAQ,GAAG;IACrB;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;CACnB,CAAA"}
|
package/dist/location.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2026 Pranam
|
|
3
|
+
* ORCID: https://orcid.org/0009-0007-9316-3616
|
|
4
|
+
*
|
|
5
|
+
* This code is licensed under the Apache License, Version 2.0.
|
|
6
|
+
*
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* QR Code:
|
|
12
|
+
* 
|
|
13
|
+
* Scan the QR code to access my ORCID profile.
|
|
14
|
+
*/
|
|
15
|
+
export {};
|
|
16
|
+
//# sourceMappingURL=location.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"location.js","sourceRoot":"","sources":["../src/location.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2026 Pranam
|
|
3
|
+
* ORCID: https://orcid.org/0009-0007-9316-3616
|
|
4
|
+
*
|
|
5
|
+
* This code is licensed under the Apache License, Version 2.0.
|
|
6
|
+
*
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* QR Code:
|
|
12
|
+
* 
|
|
13
|
+
* Scan the QR code to access my ORCID profile.
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* Normalize a DIGIPIN string.
|
|
17
|
+
*
|
|
18
|
+
* Normalization applies the following rules:
|
|
19
|
+
* - Removes '-' separator characters
|
|
20
|
+
* - Converts all characters to uppercase
|
|
21
|
+
*
|
|
22
|
+
* @param digipin - DIGIPIN string to normalize
|
|
23
|
+
* @returns Normalized DIGIPIN string
|
|
24
|
+
*/
|
|
25
|
+
export declare function normalize(digipin: string): string;
|
|
26
|
+
//# sourceMappingURL=normalize.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalize.d.ts","sourceRoot":"","sources":["../src/normalize.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH;;;;;;;;;GASG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAUjD"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2026 Pranam
|
|
3
|
+
* ORCID: https://orcid.org/0009-0007-9316-3616
|
|
4
|
+
*
|
|
5
|
+
* This code is licensed under the Apache License, Version 2.0.
|
|
6
|
+
*
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* QR Code:
|
|
12
|
+
* 
|
|
13
|
+
* Scan the QR code to access my ORCID profile.
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* Normalize a DIGIPIN string.
|
|
17
|
+
*
|
|
18
|
+
* Normalization applies the following rules:
|
|
19
|
+
* - Removes '-' separator characters
|
|
20
|
+
* - Converts all characters to uppercase
|
|
21
|
+
*
|
|
22
|
+
* @param digipin - DIGIPIN string to normalize
|
|
23
|
+
* @returns Normalized DIGIPIN string
|
|
24
|
+
*/
|
|
25
|
+
export function normalize(digipin) {
|
|
26
|
+
let normalizedDigipin = "";
|
|
27
|
+
for (const character of digipin) {
|
|
28
|
+
if (character !== "-") {
|
|
29
|
+
normalizedDigipin += character.toUpperCase();
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return normalizedDigipin;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=normalize.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalize.js","sourceRoot":"","sources":["../src/normalize.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH;;;;;;;;;GASG;AACH,MAAM,UAAU,SAAS,CAAC,OAAe;IACvC,IAAI,iBAAiB,GAAW,EAAE,CAAC;IAEnC,KAAK,MAAM,SAAS,IAAI,OAAO,EAAE,CAAC;QAChC,IAAI,SAAS,KAAK,GAAG,EAAE,CAAC;YACtB,iBAAiB,IAAI,SAAS,CAAC,WAAW,EAAE,CAAC;QAC/C,CAAC;IACH,CAAC;IAED,OAAO,iBAAiB,CAAC;AAC3B,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2026 Pranam
|
|
3
|
+
* ORCID: https://orcid.org/0009-0007-9316-3616
|
|
4
|
+
*
|
|
5
|
+
* This code is licensed under the Apache License, Version 2.0.
|
|
6
|
+
*
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* QR Code:
|
|
12
|
+
* 
|
|
13
|
+
* Scan the QR code to access my ORCID profile.
|
|
14
|
+
*/
|
|
15
|
+
import type { Location } from "./location.js";
|
|
16
|
+
/**
|
|
17
|
+
* Validate geodetic latitude and longitude.
|
|
18
|
+
*
|
|
19
|
+
* This function checks whether the provided coordinates fall within
|
|
20
|
+
* the valid WGS-84 geodetic bounds.
|
|
21
|
+
*
|
|
22
|
+
* @param location - Geographic location containing latitude and longitude
|
|
23
|
+
* @throws Error if geodetic coordinates are out of bounds
|
|
24
|
+
*/
|
|
25
|
+
export declare function validateGeodeticCoordinates(location: Location): void;
|
|
26
|
+
/**
|
|
27
|
+
* Validate that a geographic location lies within the DIGIPIN
|
|
28
|
+
* supported territory.
|
|
29
|
+
*
|
|
30
|
+
* @param location - Geographic location containing latitude and longitude
|
|
31
|
+
* @throws Outside supported territory error if location is out of supported bounds
|
|
32
|
+
*/
|
|
33
|
+
export declare function validateDigipinTerritory(location: Location): void;
|
|
34
|
+
/**
|
|
35
|
+
* Validate the format of a DIGIPIN string.
|
|
36
|
+
*
|
|
37
|
+
* This function checks:
|
|
38
|
+
* - Exact DIGIPIN length
|
|
39
|
+
* - Allowed DIGIPIN symbol set
|
|
40
|
+
*
|
|
41
|
+
* The input must already be normalized (no separators, uppercase).
|
|
42
|
+
*
|
|
43
|
+
* @param digipin - DIGIPIN string to validate
|
|
44
|
+
* @throws Invalid DIGIPIN length error if length is incorrect
|
|
45
|
+
* @throws Invalid DIGIPIN format error if invalid symbols are found
|
|
46
|
+
*/
|
|
47
|
+
export declare function validateDigipinFormat(digipin: string): void;
|
|
48
|
+
//# sourceMappingURL=validation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../src/validation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAeH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAc9C;;;;;;;;GAQG;AACH,wBAAgB,2BAA2B,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAgBpE;AACD;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI,CASjE;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAU3D"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2026 Pranam
|
|
3
|
+
* ORCID: https://orcid.org/0009-0007-9316-3616
|
|
4
|
+
*
|
|
5
|
+
* This code is licensed under the Apache License, Version 2.0.
|
|
6
|
+
*
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* QR Code:
|
|
12
|
+
* 
|
|
13
|
+
* Scan the QR code to access my ORCID profile.
|
|
14
|
+
*/
|
|
15
|
+
import { GEODETIC_LATITUDE_MIN, GEODETIC_LATITUDE_MAX, GEODETIC_LONGITUDE_MIN, GEODETIC_LONGITUDE_MAX, DIGIPIN_LATITUDE_MIN, DIGIPIN_LATITUDE_MAX, DIGIPIN_LONGITUDE_MIN, DIGIPIN_LONGITUDE_MAX, DIGIPIN_LENGTH, DIGIPIN_SYMBOLS, } from "./constants.js";
|
|
16
|
+
import { DigipinError } from "./errors.js";
|
|
17
|
+
/**
|
|
18
|
+
* Check if a value is within a range.
|
|
19
|
+
*
|
|
20
|
+
* @param value - The value to check
|
|
21
|
+
* @param min - The minimum allowed value
|
|
22
|
+
* @param max - The maximum allowed value
|
|
23
|
+
* @returns True if the value is within the range, false otherwise
|
|
24
|
+
*/
|
|
25
|
+
function isWithin(value, min, max) {
|
|
26
|
+
return value >= min && value <= max;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Validate geodetic latitude and longitude.
|
|
30
|
+
*
|
|
31
|
+
* This function checks whether the provided coordinates fall within
|
|
32
|
+
* the valid WGS-84 geodetic bounds.
|
|
33
|
+
*
|
|
34
|
+
* @param location - Geographic location containing latitude and longitude
|
|
35
|
+
* @throws Error if geodetic coordinates are out of bounds
|
|
36
|
+
*/
|
|
37
|
+
export function validateGeodeticCoordinates(location) {
|
|
38
|
+
if (!isWithin(location.latitude, GEODETIC_LATITUDE_MIN, GEODETIC_LATITUDE_MAX)) {
|
|
39
|
+
throw DigipinError.invalidLatitude();
|
|
40
|
+
}
|
|
41
|
+
if (!isWithin(location.longitude, GEODETIC_LONGITUDE_MIN, GEODETIC_LONGITUDE_MAX)) {
|
|
42
|
+
throw DigipinError.invalidLongitude();
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Validate that a geographic location lies within the DIGIPIN
|
|
47
|
+
* supported territory.
|
|
48
|
+
*
|
|
49
|
+
* @param location - Geographic location containing latitude and longitude
|
|
50
|
+
* @throws Outside supported territory error if location is out of supported bounds
|
|
51
|
+
*/
|
|
52
|
+
export function validateDigipinTerritory(location) {
|
|
53
|
+
if (location.latitude < DIGIPIN_LATITUDE_MIN ||
|
|
54
|
+
location.latitude > DIGIPIN_LATITUDE_MAX ||
|
|
55
|
+
location.longitude < DIGIPIN_LONGITUDE_MIN ||
|
|
56
|
+
location.longitude > DIGIPIN_LONGITUDE_MAX) {
|
|
57
|
+
throw DigipinError.outsideSupportedTerritory();
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Validate the format of a DIGIPIN string.
|
|
62
|
+
*
|
|
63
|
+
* This function checks:
|
|
64
|
+
* - Exact DIGIPIN length
|
|
65
|
+
* - Allowed DIGIPIN symbol set
|
|
66
|
+
*
|
|
67
|
+
* The input must already be normalized (no separators, uppercase).
|
|
68
|
+
*
|
|
69
|
+
* @param digipin - DIGIPIN string to validate
|
|
70
|
+
* @throws Invalid DIGIPIN length error if length is incorrect
|
|
71
|
+
* @throws Invalid DIGIPIN format error if invalid symbols are found
|
|
72
|
+
*/
|
|
73
|
+
export function validateDigipinFormat(digipin) {
|
|
74
|
+
if (digipin.length !== DIGIPIN_LENGTH) {
|
|
75
|
+
throw DigipinError.invalidDigipinLength();
|
|
76
|
+
}
|
|
77
|
+
for (const character of digipin) {
|
|
78
|
+
if (!DIGIPIN_SYMBOLS.includes(character)) {
|
|
79
|
+
throw DigipinError.invalidDigipinFormat();
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=validation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.js","sourceRoot":"","sources":["../src/validation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EACL,qBAAqB,EACrB,qBAAqB,EACrB,sBAAsB,EACtB,sBAAsB,EACtB,oBAAoB,EACpB,oBAAoB,EACpB,qBAAqB,EACrB,qBAAqB,EACrB,cAAc,EACd,eAAe,GAChB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAG3C;;;;;;;GAOG;AACH,SAAS,QAAQ,CAAC,KAAa,EAAE,GAAW,EAAE,GAAW;IACvD,OAAO,KAAK,IAAI,GAAG,IAAI,KAAK,IAAI,GAAG,CAAC;AACtC,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,2BAA2B,CAAC,QAAkB;IAC5D,IACE,CAAC,QAAQ,CAAC,QAAQ,CAAC,QAAQ,EAAE,qBAAqB,EAAE,qBAAqB,CAAC,EAC1E,CAAC;QACD,MAAM,YAAY,CAAC,eAAe,EAAE,CAAC;IACvC,CAAC;IAED,IACE,CAAC,QAAQ,CACP,QAAQ,CAAC,SAAS,EAClB,sBAAsB,EACtB,sBAAsB,CACvB,EACD,CAAC;QACD,MAAM,YAAY,CAAC,gBAAgB,EAAE,CAAC;IACxC,CAAC;AACH,CAAC;AACD;;;;;;GAMG;AACH,MAAM,UAAU,wBAAwB,CAAC,QAAkB;IACzD,IACE,QAAQ,CAAC,QAAQ,GAAG,oBAAoB;QACxC,QAAQ,CAAC,QAAQ,GAAG,oBAAoB;QACxC,QAAQ,CAAC,SAAS,GAAG,qBAAqB;QAC1C,QAAQ,CAAC,SAAS,GAAG,qBAAqB,EAC1C,CAAC;QACD,MAAM,YAAY,CAAC,yBAAyB,EAAE,CAAC;IACjD,CAAC;AACH,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,qBAAqB,CAAC,OAAe;IACnD,IAAI,OAAO,CAAC,MAAM,KAAK,cAAc,EAAE,CAAC;QACtC,MAAM,YAAY,CAAC,oBAAoB,EAAE,CAAC;IAC5C,CAAC;IAED,KAAK,MAAM,SAAS,IAAI,OAAO,EAAE,CAAC;QAChC,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC;YACzC,MAAM,YAAY,CAAC,oBAAoB,EAAE,CAAC;QAC5C,CAAC;IACH,CAAC;AACH,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pranamphd/digipin",
|
|
3
|
+
"version": "0.1.0-alpha.1",
|
|
4
|
+
"description": "TypeScript library for encoding and decoding India's DIGIPIN (Digital Postal Index Number).",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"digipin",
|
|
7
|
+
"india",
|
|
8
|
+
"postal",
|
|
9
|
+
"gis",
|
|
10
|
+
"geolocation",
|
|
11
|
+
"pincode",
|
|
12
|
+
"library"
|
|
13
|
+
],
|
|
14
|
+
"homepage": "https://github.com/pranamphd/digipin-ts#readme",
|
|
15
|
+
"bugs": {
|
|
16
|
+
"url": "https://github.com/pranamphd/digipin-ts/issues"
|
|
17
|
+
},
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "git+https://github.com/pranamphd/digipin-ts.git"
|
|
21
|
+
},
|
|
22
|
+
"license": "Apache-2.0",
|
|
23
|
+
"author": "Pranam <pranam@pranam.phd>",
|
|
24
|
+
"type": "module",
|
|
25
|
+
"main": "./dist/index.js",
|
|
26
|
+
"types": "./dist/index.d.ts",
|
|
27
|
+
"exports": {
|
|
28
|
+
".": {
|
|
29
|
+
"types": "./dist/index.d.ts",
|
|
30
|
+
"default": "./dist/index.js"
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"files": [
|
|
34
|
+
"dist",
|
|
35
|
+
"README.md",
|
|
36
|
+
"LICENSE"
|
|
37
|
+
],
|
|
38
|
+
"scripts": {
|
|
39
|
+
"clean": "rm -rf dist",
|
|
40
|
+
"build": "tsc -p tsconfig.json",
|
|
41
|
+
"lint": "eslint . --max-warnings 0",
|
|
42
|
+
"lint:fix": "eslint . --fix",
|
|
43
|
+
"typecheck": "tsc -p tsconfig.test.json",
|
|
44
|
+
"test": "vitest run",
|
|
45
|
+
"test:watch": "vitest",
|
|
46
|
+
"test:coverage": "vitest run --coverage",
|
|
47
|
+
"check": "npm run lint && npm run typecheck && npm run test"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@eslint/js": "^9.39.2",
|
|
51
|
+
"@vitest/coverage-v8": "^4.0.17",
|
|
52
|
+
"eslint": "^9.39.2",
|
|
53
|
+
"globals": "^17.0.0",
|
|
54
|
+
"jiti": "^2.6.1",
|
|
55
|
+
"typescript": "^5.9.3",
|
|
56
|
+
"typescript-eslint": "^8.53.0",
|
|
57
|
+
"vitest": "^4.0.17"
|
|
58
|
+
}
|
|
59
|
+
}
|