@ruhlabs/validators 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +44 -2
- package/dist/index.cjs +79 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +40 -0
- package/dist/index.d.ts +40 -0
- package/dist/index.js +48 -0
- package/dist/index.js.map +1 -0
- package/package.json +44 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Ruh Labs
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,45 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @ruhlabs/validators
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Validators and formatters for Maldivian data. No dependencies, works in Node and the browser.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npm install @ruhlabs/validators
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
## Phone numbers
|
|
10
|
+
|
|
11
|
+
Accepts all common ways of writing a Maldivian number: `7771234`, `777-1234`, `+960 777 1234`, `00960 7771234` and so on.
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { parsePhone, isValidPhone, isMobile } from '@ruhlabs/validators';
|
|
15
|
+
|
|
16
|
+
parsePhone('+960 777 1234');
|
|
17
|
+
// {
|
|
18
|
+
// national: "7771234",
|
|
19
|
+
// e164: "+9607771234", // store this
|
|
20
|
+
// international: "+960 777-1234", // show this
|
|
21
|
+
// type: "mobile"
|
|
22
|
+
// }
|
|
23
|
+
|
|
24
|
+
parsePhone('123'); // null
|
|
25
|
+
isValidPhone('777-1234'); // true
|
|
26
|
+
isMobile('3321234'); // false (landline)
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Number types follow current allocations: numbers starting with 7 or 9 are mobile, 3 or 6 are landlines.
|
|
30
|
+
|
|
31
|
+
## National ID card numbers
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
import { isValidNationalId, normalizeNationalId } from '@ruhlabs/validators';
|
|
35
|
+
|
|
36
|
+
isValidNationalId('A123456'); // true
|
|
37
|
+
normalizeNationalId(' a 123-456 '); // "A123456"
|
|
38
|
+
normalizeNationalId('B12345'); // null
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
This checks the **format** only (A + 6 digits). It can't tell whether a card exists or who it belongs to. For real identity verification, use eFaas.
|
|
42
|
+
|
|
43
|
+
## License
|
|
44
|
+
|
|
45
|
+
MIT © Ruh Labs
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
isMobile: () => isMobile,
|
|
24
|
+
isValidNationalId: () => isValidNationalId,
|
|
25
|
+
isValidPhone: () => isValidPhone,
|
|
26
|
+
normalizeNationalId: () => normalizeNationalId,
|
|
27
|
+
parsePhone: () => parsePhone
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(index_exports);
|
|
30
|
+
|
|
31
|
+
// src/phone.ts
|
|
32
|
+
var COUNTRY_CODE = "960";
|
|
33
|
+
var TYPES = {
|
|
34
|
+
"7": "mobile",
|
|
35
|
+
"9": "mobile",
|
|
36
|
+
"3": "landline",
|
|
37
|
+
"6": "landline"
|
|
38
|
+
};
|
|
39
|
+
function parsePhone(input) {
|
|
40
|
+
let digits = input.trim();
|
|
41
|
+
if (!/^\+?[\d\s\-().]+$/.test(digits)) return null;
|
|
42
|
+
digits = digits.replace(/\D/g, "");
|
|
43
|
+
if (digits.length === 12 && digits.startsWith("00" + COUNTRY_CODE)) digits = digits.slice(5);
|
|
44
|
+
else if (digits.length === 10 && digits.startsWith(COUNTRY_CODE)) digits = digits.slice(3);
|
|
45
|
+
if (!/^\d{7}$/.test(digits)) return null;
|
|
46
|
+
const type = TYPES[digits[0]];
|
|
47
|
+
if (!type) return null;
|
|
48
|
+
return {
|
|
49
|
+
national: digits,
|
|
50
|
+
e164: `+${COUNTRY_CODE}${digits}`,
|
|
51
|
+
international: `+${COUNTRY_CODE} ${digits.slice(0, 3)}-${digits.slice(3)}`,
|
|
52
|
+
type
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
function isValidPhone(input) {
|
|
56
|
+
return parsePhone(input) !== null;
|
|
57
|
+
}
|
|
58
|
+
function isMobile(input) {
|
|
59
|
+
return parsePhone(input)?.type === "mobile";
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// src/national-id.ts
|
|
63
|
+
var NATIONAL_ID = /^A\d{6}$/;
|
|
64
|
+
function normalizeNationalId(input) {
|
|
65
|
+
const value = input.trim().replace(/[\s-]/g, "").toUpperCase();
|
|
66
|
+
return NATIONAL_ID.test(value) ? value : null;
|
|
67
|
+
}
|
|
68
|
+
function isValidNationalId(input) {
|
|
69
|
+
return normalizeNationalId(input) !== null;
|
|
70
|
+
}
|
|
71
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
72
|
+
0 && (module.exports = {
|
|
73
|
+
isMobile,
|
|
74
|
+
isValidNationalId,
|
|
75
|
+
isValidPhone,
|
|
76
|
+
normalizeNationalId,
|
|
77
|
+
parsePhone
|
|
78
|
+
});
|
|
79
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/phone.ts","../src/national-id.ts"],"sourcesContent":["export { parsePhone, isValidPhone, isMobile, type ParsedPhone, type PhoneType } from './phone.js';\nexport { normalizeNationalId, isValidNationalId } from './national-id.js';\n","export type PhoneType = 'mobile' | 'landline';\n\nexport interface ParsedPhone {\n\t/** 7-digit national number, e.g. \"7771234\" */\n\tnational: string;\n\t/** E.164 format, e.g. \"+9607771234\" */\n\te164: string;\n\t/** Human-readable format, e.g. \"+960 777-1234\" */\n\tinternational: string;\n\ttype: PhoneType;\n}\n\nconst COUNTRY_CODE = '960';\n\n/**\n * Leading digit → number type. Based on current Maldivian allocations:\n * 7xx/9xx mobile, 3xx/6xx fixed lines.\n */\nconst TYPES: Readonly<Record<string, PhoneType>> = {\n\t'7': 'mobile',\n\t'9': 'mobile',\n\t'3': 'landline',\n\t'6': 'landline'\n};\n\n/**\n * Parse a Maldivian phone number written in any common style:\n * \"7771234\", \"777 1234\", \"777-1234\", \"+960 777 1234\", \"00960 7771234\", \"960-777-1234\".\n *\n * Returns `null` if it isn't a valid Maldivian number.\n */\nexport function parsePhone(input: string): ParsedPhone | null {\n\tlet digits = input.trim();\n\tif (!/^\\+?[\\d\\s\\-().]+$/.test(digits)) return null;\n\n\tdigits = digits.replace(/\\D/g, '');\n\tif (digits.length === 12 && digits.startsWith('00' + COUNTRY_CODE)) digits = digits.slice(5);\n\telse if (digits.length === 10 && digits.startsWith(COUNTRY_CODE)) digits = digits.slice(3);\n\n\tif (!/^\\d{7}$/.test(digits)) return null;\n\tconst type = TYPES[digits[0]!];\n\tif (!type) return null;\n\n\treturn {\n\t\tnational: digits,\n\t\te164: `+${COUNTRY_CODE}${digits}`,\n\t\tinternational: `+${COUNTRY_CODE} ${digits.slice(0, 3)}-${digits.slice(3)}`,\n\t\ttype\n\t};\n}\n\n/** True if the input is a valid Maldivian phone number. */\nexport function isValidPhone(input: string): boolean {\n\treturn parsePhone(input) !== null;\n}\n\n/** True if the input is a valid Maldivian mobile number. */\nexport function isMobile(input: string): boolean {\n\treturn parsePhone(input)?.type === 'mobile';\n}\n","const NATIONAL_ID = /^A\\d{6}$/;\n\n/**\n * Normalise a Maldivian national ID card number: trims, removes spaces and\n * dashes, and uppercases the letter. \"a 123-456\" → \"A123456\".\n *\n * Returns `null` if the result isn't in the A + 6 digits format.\n */\nexport function normalizeNationalId(input: string): string | null {\n\tconst value = input.trim().replace(/[\\s-]/g, '').toUpperCase();\n\treturn NATIONAL_ID.test(value) ? value : null;\n}\n\n/**\n * True if the input has the format of a Maldivian national ID card number\n * (A followed by 6 digits).\n *\n * This only checks the format. It can't tell whether the card exists or who\n * it belongs to; for real identity verification use eFaas.\n */\nexport function isValidNationalId(input: string): boolean {\n\treturn normalizeNationalId(input) !== null;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACYA,IAAM,eAAe;AAMrB,IAAM,QAA6C;AAAA,EAClD,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AACN;AAQO,SAAS,WAAW,OAAmC;AAC7D,MAAI,SAAS,MAAM,KAAK;AACxB,MAAI,CAAC,oBAAoB,KAAK,MAAM,EAAG,QAAO;AAE9C,WAAS,OAAO,QAAQ,OAAO,EAAE;AACjC,MAAI,OAAO,WAAW,MAAM,OAAO,WAAW,OAAO,YAAY,EAAG,UAAS,OAAO,MAAM,CAAC;AAAA,WAClF,OAAO,WAAW,MAAM,OAAO,WAAW,YAAY,EAAG,UAAS,OAAO,MAAM,CAAC;AAEzF,MAAI,CAAC,UAAU,KAAK,MAAM,EAAG,QAAO;AACpC,QAAM,OAAO,MAAM,OAAO,CAAC,CAAE;AAC7B,MAAI,CAAC,KAAM,QAAO;AAElB,SAAO;AAAA,IACN,UAAU;AAAA,IACV,MAAM,IAAI,YAAY,GAAG,MAAM;AAAA,IAC/B,eAAe,IAAI,YAAY,IAAI,OAAO,MAAM,GAAG,CAAC,CAAC,IAAI,OAAO,MAAM,CAAC,CAAC;AAAA,IACxE;AAAA,EACD;AACD;AAGO,SAAS,aAAa,OAAwB;AACpD,SAAO,WAAW,KAAK,MAAM;AAC9B;AAGO,SAAS,SAAS,OAAwB;AAChD,SAAO,WAAW,KAAK,GAAG,SAAS;AACpC;;;AC3DA,IAAM,cAAc;AAQb,SAAS,oBAAoB,OAA8B;AACjE,QAAM,QAAQ,MAAM,KAAK,EAAE,QAAQ,UAAU,EAAE,EAAE,YAAY;AAC7D,SAAO,YAAY,KAAK,KAAK,IAAI,QAAQ;AAC1C;AASO,SAAS,kBAAkB,OAAwB;AACzD,SAAO,oBAAoB,KAAK,MAAM;AACvC;","names":[]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
type PhoneType = 'mobile' | 'landline';
|
|
2
|
+
interface ParsedPhone {
|
|
3
|
+
/** 7-digit national number, e.g. "7771234" */
|
|
4
|
+
national: string;
|
|
5
|
+
/** E.164 format, e.g. "+9607771234" */
|
|
6
|
+
e164: string;
|
|
7
|
+
/** Human-readable format, e.g. "+960 777-1234" */
|
|
8
|
+
international: string;
|
|
9
|
+
type: PhoneType;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Parse a Maldivian phone number written in any common style:
|
|
13
|
+
* "7771234", "777 1234", "777-1234", "+960 777 1234", "00960 7771234", "960-777-1234".
|
|
14
|
+
*
|
|
15
|
+
* Returns `null` if it isn't a valid Maldivian number.
|
|
16
|
+
*/
|
|
17
|
+
declare function parsePhone(input: string): ParsedPhone | null;
|
|
18
|
+
/** True if the input is a valid Maldivian phone number. */
|
|
19
|
+
declare function isValidPhone(input: string): boolean;
|
|
20
|
+
/** True if the input is a valid Maldivian mobile number. */
|
|
21
|
+
declare function isMobile(input: string): boolean;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Normalise a Maldivian national ID card number: trims, removes spaces and
|
|
25
|
+
* dashes, and uppercases the letter. "a 123-456" → "A123456".
|
|
26
|
+
*
|
|
27
|
+
* Returns `null` if the result isn't in the A + 6 digits format.
|
|
28
|
+
*/
|
|
29
|
+
declare function normalizeNationalId(input: string): string | null;
|
|
30
|
+
/**
|
|
31
|
+
* True if the input has the format of a Maldivian national ID card number
|
|
32
|
+
* (A followed by 6 digits).
|
|
33
|
+
*
|
|
34
|
+
* This only checks the format. It can't tell whether the card exists or who
|
|
35
|
+
* it belongs to; for real identity verification use eFaas.
|
|
36
|
+
*/
|
|
37
|
+
declare function isValidNationalId(input: string): boolean;
|
|
38
|
+
|
|
39
|
+
export { isMobile, isValidNationalId, isValidPhone, normalizeNationalId, parsePhone };
|
|
40
|
+
export type { ParsedPhone, PhoneType };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
type PhoneType = 'mobile' | 'landline';
|
|
2
|
+
interface ParsedPhone {
|
|
3
|
+
/** 7-digit national number, e.g. "7771234" */
|
|
4
|
+
national: string;
|
|
5
|
+
/** E.164 format, e.g. "+9607771234" */
|
|
6
|
+
e164: string;
|
|
7
|
+
/** Human-readable format, e.g. "+960 777-1234" */
|
|
8
|
+
international: string;
|
|
9
|
+
type: PhoneType;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Parse a Maldivian phone number written in any common style:
|
|
13
|
+
* "7771234", "777 1234", "777-1234", "+960 777 1234", "00960 7771234", "960-777-1234".
|
|
14
|
+
*
|
|
15
|
+
* Returns `null` if it isn't a valid Maldivian number.
|
|
16
|
+
*/
|
|
17
|
+
declare function parsePhone(input: string): ParsedPhone | null;
|
|
18
|
+
/** True if the input is a valid Maldivian phone number. */
|
|
19
|
+
declare function isValidPhone(input: string): boolean;
|
|
20
|
+
/** True if the input is a valid Maldivian mobile number. */
|
|
21
|
+
declare function isMobile(input: string): boolean;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Normalise a Maldivian national ID card number: trims, removes spaces and
|
|
25
|
+
* dashes, and uppercases the letter. "a 123-456" → "A123456".
|
|
26
|
+
*
|
|
27
|
+
* Returns `null` if the result isn't in the A + 6 digits format.
|
|
28
|
+
*/
|
|
29
|
+
declare function normalizeNationalId(input: string): string | null;
|
|
30
|
+
/**
|
|
31
|
+
* True if the input has the format of a Maldivian national ID card number
|
|
32
|
+
* (A followed by 6 digits).
|
|
33
|
+
*
|
|
34
|
+
* This only checks the format. It can't tell whether the card exists or who
|
|
35
|
+
* it belongs to; for real identity verification use eFaas.
|
|
36
|
+
*/
|
|
37
|
+
declare function isValidNationalId(input: string): boolean;
|
|
38
|
+
|
|
39
|
+
export { isMobile, isValidNationalId, isValidPhone, normalizeNationalId, parsePhone };
|
|
40
|
+
export type { ParsedPhone, PhoneType };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// src/phone.ts
|
|
2
|
+
var COUNTRY_CODE = "960";
|
|
3
|
+
var TYPES = {
|
|
4
|
+
"7": "mobile",
|
|
5
|
+
"9": "mobile",
|
|
6
|
+
"3": "landline",
|
|
7
|
+
"6": "landline"
|
|
8
|
+
};
|
|
9
|
+
function parsePhone(input) {
|
|
10
|
+
let digits = input.trim();
|
|
11
|
+
if (!/^\+?[\d\s\-().]+$/.test(digits)) return null;
|
|
12
|
+
digits = digits.replace(/\D/g, "");
|
|
13
|
+
if (digits.length === 12 && digits.startsWith("00" + COUNTRY_CODE)) digits = digits.slice(5);
|
|
14
|
+
else if (digits.length === 10 && digits.startsWith(COUNTRY_CODE)) digits = digits.slice(3);
|
|
15
|
+
if (!/^\d{7}$/.test(digits)) return null;
|
|
16
|
+
const type = TYPES[digits[0]];
|
|
17
|
+
if (!type) return null;
|
|
18
|
+
return {
|
|
19
|
+
national: digits,
|
|
20
|
+
e164: `+${COUNTRY_CODE}${digits}`,
|
|
21
|
+
international: `+${COUNTRY_CODE} ${digits.slice(0, 3)}-${digits.slice(3)}`,
|
|
22
|
+
type
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
function isValidPhone(input) {
|
|
26
|
+
return parsePhone(input) !== null;
|
|
27
|
+
}
|
|
28
|
+
function isMobile(input) {
|
|
29
|
+
return parsePhone(input)?.type === "mobile";
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// src/national-id.ts
|
|
33
|
+
var NATIONAL_ID = /^A\d{6}$/;
|
|
34
|
+
function normalizeNationalId(input) {
|
|
35
|
+
const value = input.trim().replace(/[\s-]/g, "").toUpperCase();
|
|
36
|
+
return NATIONAL_ID.test(value) ? value : null;
|
|
37
|
+
}
|
|
38
|
+
function isValidNationalId(input) {
|
|
39
|
+
return normalizeNationalId(input) !== null;
|
|
40
|
+
}
|
|
41
|
+
export {
|
|
42
|
+
isMobile,
|
|
43
|
+
isValidNationalId,
|
|
44
|
+
isValidPhone,
|
|
45
|
+
normalizeNationalId,
|
|
46
|
+
parsePhone
|
|
47
|
+
};
|
|
48
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/phone.ts","../src/national-id.ts"],"sourcesContent":["export type PhoneType = 'mobile' | 'landline';\n\nexport interface ParsedPhone {\n\t/** 7-digit national number, e.g. \"7771234\" */\n\tnational: string;\n\t/** E.164 format, e.g. \"+9607771234\" */\n\te164: string;\n\t/** Human-readable format, e.g. \"+960 777-1234\" */\n\tinternational: string;\n\ttype: PhoneType;\n}\n\nconst COUNTRY_CODE = '960';\n\n/**\n * Leading digit → number type. Based on current Maldivian allocations:\n * 7xx/9xx mobile, 3xx/6xx fixed lines.\n */\nconst TYPES: Readonly<Record<string, PhoneType>> = {\n\t'7': 'mobile',\n\t'9': 'mobile',\n\t'3': 'landline',\n\t'6': 'landline'\n};\n\n/**\n * Parse a Maldivian phone number written in any common style:\n * \"7771234\", \"777 1234\", \"777-1234\", \"+960 777 1234\", \"00960 7771234\", \"960-777-1234\".\n *\n * Returns `null` if it isn't a valid Maldivian number.\n */\nexport function parsePhone(input: string): ParsedPhone | null {\n\tlet digits = input.trim();\n\tif (!/^\\+?[\\d\\s\\-().]+$/.test(digits)) return null;\n\n\tdigits = digits.replace(/\\D/g, '');\n\tif (digits.length === 12 && digits.startsWith('00' + COUNTRY_CODE)) digits = digits.slice(5);\n\telse if (digits.length === 10 && digits.startsWith(COUNTRY_CODE)) digits = digits.slice(3);\n\n\tif (!/^\\d{7}$/.test(digits)) return null;\n\tconst type = TYPES[digits[0]!];\n\tif (!type) return null;\n\n\treturn {\n\t\tnational: digits,\n\t\te164: `+${COUNTRY_CODE}${digits}`,\n\t\tinternational: `+${COUNTRY_CODE} ${digits.slice(0, 3)}-${digits.slice(3)}`,\n\t\ttype\n\t};\n}\n\n/** True if the input is a valid Maldivian phone number. */\nexport function isValidPhone(input: string): boolean {\n\treturn parsePhone(input) !== null;\n}\n\n/** True if the input is a valid Maldivian mobile number. */\nexport function isMobile(input: string): boolean {\n\treturn parsePhone(input)?.type === 'mobile';\n}\n","const NATIONAL_ID = /^A\\d{6}$/;\n\n/**\n * Normalise a Maldivian national ID card number: trims, removes spaces and\n * dashes, and uppercases the letter. \"a 123-456\" → \"A123456\".\n *\n * Returns `null` if the result isn't in the A + 6 digits format.\n */\nexport function normalizeNationalId(input: string): string | null {\n\tconst value = input.trim().replace(/[\\s-]/g, '').toUpperCase();\n\treturn NATIONAL_ID.test(value) ? value : null;\n}\n\n/**\n * True if the input has the format of a Maldivian national ID card number\n * (A followed by 6 digits).\n *\n * This only checks the format. It can't tell whether the card exists or who\n * it belongs to; for real identity verification use eFaas.\n */\nexport function isValidNationalId(input: string): boolean {\n\treturn normalizeNationalId(input) !== null;\n}\n"],"mappings":";AAYA,IAAM,eAAe;AAMrB,IAAM,QAA6C;AAAA,EAClD,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AACN;AAQO,SAAS,WAAW,OAAmC;AAC7D,MAAI,SAAS,MAAM,KAAK;AACxB,MAAI,CAAC,oBAAoB,KAAK,MAAM,EAAG,QAAO;AAE9C,WAAS,OAAO,QAAQ,OAAO,EAAE;AACjC,MAAI,OAAO,WAAW,MAAM,OAAO,WAAW,OAAO,YAAY,EAAG,UAAS,OAAO,MAAM,CAAC;AAAA,WAClF,OAAO,WAAW,MAAM,OAAO,WAAW,YAAY,EAAG,UAAS,OAAO,MAAM,CAAC;AAEzF,MAAI,CAAC,UAAU,KAAK,MAAM,EAAG,QAAO;AACpC,QAAM,OAAO,MAAM,OAAO,CAAC,CAAE;AAC7B,MAAI,CAAC,KAAM,QAAO;AAElB,SAAO;AAAA,IACN,UAAU;AAAA,IACV,MAAM,IAAI,YAAY,GAAG,MAAM;AAAA,IAC/B,eAAe,IAAI,YAAY,IAAI,OAAO,MAAM,GAAG,CAAC,CAAC,IAAI,OAAO,MAAM,CAAC,CAAC;AAAA,IACxE;AAAA,EACD;AACD;AAGO,SAAS,aAAa,OAAwB;AACpD,SAAO,WAAW,KAAK,MAAM;AAC9B;AAGO,SAAS,SAAS,OAAwB;AAChD,SAAO,WAAW,KAAK,GAAG,SAAS;AACpC;;;AC3DA,IAAM,cAAc;AAQb,SAAS,oBAAoB,OAA8B;AACjE,QAAM,QAAQ,MAAM,KAAK,EAAE,QAAQ,UAAU,EAAE,EAAE,YAAY;AAC7D,SAAO,YAAY,KAAK,KAAK,IAAI,QAAQ;AAC1C;AASO,SAAS,kBAAkB,OAAwB;AACzD,SAAO,oBAAoB,KAAK,MAAM;AACvC;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,47 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ruhlabs/validators",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Validators and formatters for Maldivian phone numbers and national ID card numbers",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Ruh Labs",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/ruhlabs/devtools.git",
|
|
10
|
+
"directory": "packages/validators"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [
|
|
13
|
+
"maldives",
|
|
14
|
+
"validation",
|
|
15
|
+
"phone",
|
|
16
|
+
"national-id",
|
|
17
|
+
"ruhlabs"
|
|
18
|
+
],
|
|
19
|
+
"type": "module",
|
|
20
|
+
"main": "./dist/index.cjs",
|
|
21
|
+
"module": "./dist/index.js",
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"exports": {
|
|
24
|
+
".": {
|
|
25
|
+
"import": {
|
|
26
|
+
"types": "./dist/index.d.ts",
|
|
27
|
+
"default": "./dist/index.js"
|
|
28
|
+
},
|
|
29
|
+
"require": {
|
|
30
|
+
"types": "./dist/index.d.cts",
|
|
31
|
+
"default": "./dist/index.cjs"
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"files": [
|
|
36
|
+
"dist"
|
|
37
|
+
],
|
|
38
|
+
"sideEffects": false,
|
|
39
|
+
"publishConfig": {
|
|
40
|
+
"access": "public"
|
|
41
|
+
},
|
|
42
|
+
"scripts": {
|
|
43
|
+
"build": "tsup",
|
|
44
|
+
"test": "vitest run",
|
|
45
|
+
"typecheck": "tsc --noEmit"
|
|
46
|
+
}
|
|
6
47
|
}
|