@temboplus/frontend-core 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 +7 -0
- package/README.md +72 -0
- package/esm/_dnt.test_shims.d.ts.map +1 -0
- package/esm/deps/deno.land/std@0.217.0/assert/_constants.d.ts.map +1 -0
- package/esm/deps/deno.land/std@0.217.0/assert/_diff.d.ts.map +1 -0
- package/esm/deps/deno.land/std@0.217.0/assert/_format.d.ts.map +1 -0
- package/esm/deps/deno.land/std@0.217.0/assert/assert.d.ts.map +1 -0
- package/esm/deps/deno.land/std@0.217.0/assert/assert_almost_equals.d.ts.map +1 -0
- package/esm/deps/deno.land/std@0.217.0/assert/assert_array_includes.d.ts.map +1 -0
- package/esm/deps/deno.land/std@0.217.0/assert/assert_equals.d.ts.map +1 -0
- package/esm/deps/deno.land/std@0.217.0/assert/assert_exists.d.ts.map +1 -0
- package/esm/deps/deno.land/std@0.217.0/assert/assert_false.d.ts.map +1 -0
- package/esm/deps/deno.land/std@0.217.0/assert/assert_greater.d.ts.map +1 -0
- package/esm/deps/deno.land/std@0.217.0/assert/assert_greater_or_equal.d.ts.map +1 -0
- package/esm/deps/deno.land/std@0.217.0/assert/assert_instance_of.d.ts.map +1 -0
- package/esm/deps/deno.land/std@0.217.0/assert/assert_is_error.d.ts.map +1 -0
- package/esm/deps/deno.land/std@0.217.0/assert/assert_less.d.ts.map +1 -0
- package/esm/deps/deno.land/std@0.217.0/assert/assert_less_or_equal.d.ts.map +1 -0
- package/esm/deps/deno.land/std@0.217.0/assert/assert_match.d.ts.map +1 -0
- package/esm/deps/deno.land/std@0.217.0/assert/assert_not_equals.d.ts.map +1 -0
- package/esm/deps/deno.land/std@0.217.0/assert/assert_not_instance_of.d.ts.map +1 -0
- package/esm/deps/deno.land/std@0.217.0/assert/assert_not_match.d.ts.map +1 -0
- package/esm/deps/deno.land/std@0.217.0/assert/assert_not_strict_equals.d.ts.map +1 -0
- package/esm/deps/deno.land/std@0.217.0/assert/assert_object_match.d.ts.map +1 -0
- package/esm/deps/deno.land/std@0.217.0/assert/assert_rejects.d.ts.map +1 -0
- package/esm/deps/deno.land/std@0.217.0/assert/assert_strict_equals.d.ts.map +1 -0
- package/esm/deps/deno.land/std@0.217.0/assert/assert_string_includes.d.ts.map +1 -0
- package/esm/deps/deno.land/std@0.217.0/assert/assert_throws.d.ts.map +1 -0
- package/esm/deps/deno.land/std@0.217.0/assert/assertion_error.d.ts.map +1 -0
- package/esm/deps/deno.land/std@0.217.0/assert/equal.d.ts.map +1 -0
- package/esm/deps/deno.land/std@0.217.0/assert/fail.d.ts.map +1 -0
- package/esm/deps/deno.land/std@0.217.0/assert/mod.d.ts.map +1 -0
- package/esm/deps/deno.land/std@0.217.0/assert/unimplemented.d.ts.map +1 -0
- package/esm/deps/deno.land/std@0.217.0/assert/unreachable.d.ts.map +1 -0
- package/esm/deps/deno.land/std@0.217.0/fmt/colors.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/almost_equals.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/array_includes.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/assert.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/assertion_error.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/equal.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/equals.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/exists.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/fail.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/false.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/greater.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/greater_or_equal.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/instance_of.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/is_error.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/less.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/less_or_equal.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/match.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/mod.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/not_equals.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/not_instance_of.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/not_match.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/not_strict_equals.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/object_match.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/rejects.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/strict_equals.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/string_includes.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/throws.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/unimplemented.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/assert/1.0.10/unreachable.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/internal/1.0.5/build_message.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/internal/1.0.5/diff.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/internal/1.0.5/diff_str.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/internal/1.0.5/format.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/internal/1.0.5/styles.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/internal/1.0.5/types.d.ts.map +1 -0
- package/esm/mod.d.ts +3 -0
- package/esm/mod.d.ts.map +1 -0
- package/esm/mod.js +2 -0
- package/esm/package.json +3 -0
- package/esm/src/models/amount/amount.d.ts +55 -0
- package/esm/src/models/amount/amount.d.ts.map +1 -0
- package/esm/src/models/amount/amount.js +229 -0
- package/esm/src/models/amount/amount.test.d.ts.map +1 -0
- package/esm/src/models/amount/antd_validator.d.ts +40 -0
- package/esm/src/models/amount/antd_validator.d.ts.map +1 -0
- package/esm/src/models/amount/antd_validator.js +58 -0
- package/esm/src/models/amount/antd_validator.test.d.ts.map +1 -0
- package/esm/src/models/amount/index.d.ts +3 -0
- package/esm/src/models/amount/index.d.ts.map +1 -0
- package/esm/src/models/amount/index.js +2 -0
- package/esm/src/models/bank/antd_validator.d.ts +11 -0
- package/esm/src/models/bank/antd_validator.d.ts.map +1 -0
- package/esm/src/models/bank/antd_validator.js +26 -0
- package/esm/src/models/bank/antd_validator.test.d.ts.map +1 -0
- package/esm/src/models/bank/bank.d.ts +125 -0
- package/esm/src/models/bank/bank.d.ts.map +1 -0
- package/esm/src/models/bank/bank.js +229 -0
- package/esm/src/models/bank/bank.test.d.ts.map +1 -0
- package/esm/src/models/bank/banks.d.ts +7 -0
- package/esm/src/models/bank/banks.d.ts.map +1 -0
- package/esm/src/models/bank/banks.js +197 -0
- package/esm/src/models/bank/index.d.ts +4 -0
- package/esm/src/models/bank/index.d.ts.map +1 -0
- package/esm/src/models/bank/index.js +3 -0
- package/esm/src/models/bank/utils.d.ts +25 -0
- package/esm/src/models/bank/utils.d.ts.map +1 -0
- package/esm/src/models/bank/utils.js +35 -0
- package/esm/src/models/index.d.ts +4 -0
- package/esm/src/models/index.d.ts.map +1 -0
- package/esm/src/models/index.js +3 -0
- package/esm/src/models/phone_number/antd_validator.d.ts +77 -0
- package/esm/src/models/phone_number/antd_validator.d.ts.map +1 -0
- package/esm/src/models/phone_number/antd_validator.js +90 -0
- package/esm/src/models/phone_number/antdvalidator.test.d.ts.map +1 -0
- package/esm/src/models/phone_number/index.d.ts +4 -0
- package/esm/src/models/phone_number/index.d.ts.map +1 -0
- package/esm/src/models/phone_number/index.js +3 -0
- package/esm/src/models/phone_number/phone_number.d.ts +117 -0
- package/esm/src/models/phone_number/phone_number.d.ts.map +1 -0
- package/esm/src/models/phone_number/phone_number.js +231 -0
- package/esm/src/models/phone_number/phone_number.test.d.ts.map +1 -0
- package/esm/src/models/phone_number/telecom.d.ts +25 -0
- package/esm/src/models/phone_number/telecom.d.ts.map +1 -0
- package/esm/src/models/phone_number/telecom.js +44 -0
- package/esm/src/utils/id.d.ts +12 -0
- package/esm/src/utils/id.d.ts.map +1 -0
- package/esm/src/utils/id.js +19 -0
- package/esm/src/utils/index.d.ts +4 -0
- package/esm/src/utils/index.d.ts.map +1 -0
- package/esm/src/utils/index.js +3 -0
- package/esm/src/utils/text.d.ts +32 -0
- package/esm/src/utils/text.d.ts.map +1 -0
- package/esm/src/utils/text.js +68 -0
- package/esm/src/utils/text.test.d.ts.map +1 -0
- package/esm/src/utils/time.d.ts +21 -0
- package/esm/src/utils/time.d.ts.map +1 -0
- package/esm/src/utils/time.js +34 -0
- package/package.json +35 -0
- package/script/_dnt.test_shims.d.ts.map +1 -0
- package/script/deps/deno.land/std@0.217.0/assert/_constants.d.ts.map +1 -0
- package/script/deps/deno.land/std@0.217.0/assert/_diff.d.ts.map +1 -0
- package/script/deps/deno.land/std@0.217.0/assert/_format.d.ts.map +1 -0
- package/script/deps/deno.land/std@0.217.0/assert/assert.d.ts.map +1 -0
- package/script/deps/deno.land/std@0.217.0/assert/assert_almost_equals.d.ts.map +1 -0
- package/script/deps/deno.land/std@0.217.0/assert/assert_array_includes.d.ts.map +1 -0
- package/script/deps/deno.land/std@0.217.0/assert/assert_equals.d.ts.map +1 -0
- package/script/deps/deno.land/std@0.217.0/assert/assert_exists.d.ts.map +1 -0
- package/script/deps/deno.land/std@0.217.0/assert/assert_false.d.ts.map +1 -0
- package/script/deps/deno.land/std@0.217.0/assert/assert_greater.d.ts.map +1 -0
- package/script/deps/deno.land/std@0.217.0/assert/assert_greater_or_equal.d.ts.map +1 -0
- package/script/deps/deno.land/std@0.217.0/assert/assert_instance_of.d.ts.map +1 -0
- package/script/deps/deno.land/std@0.217.0/assert/assert_is_error.d.ts.map +1 -0
- package/script/deps/deno.land/std@0.217.0/assert/assert_less.d.ts.map +1 -0
- package/script/deps/deno.land/std@0.217.0/assert/assert_less_or_equal.d.ts.map +1 -0
- package/script/deps/deno.land/std@0.217.0/assert/assert_match.d.ts.map +1 -0
- package/script/deps/deno.land/std@0.217.0/assert/assert_not_equals.d.ts.map +1 -0
- package/script/deps/deno.land/std@0.217.0/assert/assert_not_instance_of.d.ts.map +1 -0
- package/script/deps/deno.land/std@0.217.0/assert/assert_not_match.d.ts.map +1 -0
- package/script/deps/deno.land/std@0.217.0/assert/assert_not_strict_equals.d.ts.map +1 -0
- package/script/deps/deno.land/std@0.217.0/assert/assert_object_match.d.ts.map +1 -0
- package/script/deps/deno.land/std@0.217.0/assert/assert_rejects.d.ts.map +1 -0
- package/script/deps/deno.land/std@0.217.0/assert/assert_strict_equals.d.ts.map +1 -0
- package/script/deps/deno.land/std@0.217.0/assert/assert_string_includes.d.ts.map +1 -0
- package/script/deps/deno.land/std@0.217.0/assert/assert_throws.d.ts.map +1 -0
- package/script/deps/deno.land/std@0.217.0/assert/assertion_error.d.ts.map +1 -0
- package/script/deps/deno.land/std@0.217.0/assert/equal.d.ts.map +1 -0
- package/script/deps/deno.land/std@0.217.0/assert/fail.d.ts.map +1 -0
- package/script/deps/deno.land/std@0.217.0/assert/mod.d.ts.map +1 -0
- package/script/deps/deno.land/std@0.217.0/assert/unimplemented.d.ts.map +1 -0
- package/script/deps/deno.land/std@0.217.0/assert/unreachable.d.ts.map +1 -0
- package/script/deps/deno.land/std@0.217.0/fmt/colors.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.10/almost_equals.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.10/array_includes.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.10/assert.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.10/assertion_error.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.10/equal.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.10/equals.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.10/exists.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.10/fail.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.10/false.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.10/greater.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.10/greater_or_equal.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.10/instance_of.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.10/is_error.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.10/less.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.10/less_or_equal.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.10/match.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.10/mod.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.10/not_equals.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.10/not_instance_of.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.10/not_match.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.10/not_strict_equals.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.10/object_match.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.10/rejects.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.10/strict_equals.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.10/string_includes.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.10/throws.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.10/unimplemented.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/assert/1.0.10/unreachable.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/internal/1.0.5/build_message.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/internal/1.0.5/diff.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/internal/1.0.5/diff_str.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/internal/1.0.5/format.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/internal/1.0.5/styles.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/internal/1.0.5/types.d.ts.map +1 -0
- package/script/mod.d.ts +3 -0
- package/script/mod.d.ts.map +1 -0
- package/script/mod.js +18 -0
- package/script/package.json +3 -0
- package/script/src/models/amount/amount.d.ts +55 -0
- package/script/src/models/amount/amount.d.ts.map +1 -0
- package/script/src/models/amount/amount.js +233 -0
- package/script/src/models/amount/amount.test.d.ts.map +1 -0
- package/script/src/models/amount/antd_validator.d.ts +40 -0
- package/script/src/models/amount/antd_validator.d.ts.map +1 -0
- package/script/src/models/amount/antd_validator.js +62 -0
- package/script/src/models/amount/antd_validator.test.d.ts.map +1 -0
- package/script/src/models/amount/index.d.ts +3 -0
- package/script/src/models/amount/index.d.ts.map +1 -0
- package/script/src/models/amount/index.js +18 -0
- package/script/src/models/bank/antd_validator.d.ts +11 -0
- package/script/src/models/bank/antd_validator.d.ts.map +1 -0
- package/script/src/models/bank/antd_validator.js +30 -0
- package/script/src/models/bank/antd_validator.test.d.ts.map +1 -0
- package/script/src/models/bank/bank.d.ts +125 -0
- package/script/src/models/bank/bank.d.ts.map +1 -0
- package/script/src/models/bank/bank.js +236 -0
- package/script/src/models/bank/bank.test.d.ts.map +1 -0
- package/script/src/models/bank/banks.d.ts +7 -0
- package/script/src/models/bank/banks.d.ts.map +1 -0
- package/script/src/models/bank/banks.js +199 -0
- package/script/src/models/bank/index.d.ts +4 -0
- package/script/src/models/bank/index.d.ts.map +1 -0
- package/script/src/models/bank/index.js +19 -0
- package/script/src/models/bank/utils.d.ts +25 -0
- package/script/src/models/bank/utils.d.ts.map +1 -0
- package/script/src/models/bank/utils.js +41 -0
- package/script/src/models/index.d.ts +4 -0
- package/script/src/models/index.d.ts.map +1 -0
- package/script/src/models/index.js +19 -0
- package/script/src/models/phone_number/antd_validator.d.ts +77 -0
- package/script/src/models/phone_number/antd_validator.d.ts.map +1 -0
- package/script/src/models/phone_number/antd_validator.js +94 -0
- package/script/src/models/phone_number/antdvalidator.test.d.ts.map +1 -0
- package/script/src/models/phone_number/index.d.ts +4 -0
- package/script/src/models/phone_number/index.d.ts.map +1 -0
- package/script/src/models/phone_number/index.js +19 -0
- package/script/src/models/phone_number/phone_number.d.ts +117 -0
- package/script/src/models/phone_number/phone_number.d.ts.map +1 -0
- package/script/src/models/phone_number/phone_number.js +235 -0
- package/script/src/models/phone_number/phone_number.test.d.ts.map +1 -0
- package/script/src/models/phone_number/telecom.d.ts +25 -0
- package/script/src/models/phone_number/telecom.d.ts.map +1 -0
- package/script/src/models/phone_number/telecom.js +47 -0
- package/script/src/utils/id.d.ts +12 -0
- package/script/src/utils/id.d.ts.map +1 -0
- package/script/src/utils/id.js +23 -0
- package/script/src/utils/index.d.ts +4 -0
- package/script/src/utils/index.d.ts.map +1 -0
- package/script/src/utils/index.js +19 -0
- package/script/src/utils/text.d.ts +32 -0
- package/script/src/utils/text.d.ts.map +1 -0
- package/script/src/utils/text.js +75 -0
- package/script/src/utils/text.test.d.ts.map +1 -0
- package/script/src/utils/time.d.ts +21 -0
- package/script/src/utils/time.d.ts.map +1 -0
- package/script/src/utils/time.js +39 -0
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PHONENUMBER_VALIDATOR = exports.TZ_PHONE_NUMBER_REGEX = void 0;
|
|
4
|
+
const phone_number_js_1 = require("./phone_number.js");
|
|
5
|
+
/**
|
|
6
|
+
* Validates a Tanzanian phone number according to specified format rules.
|
|
7
|
+
* This validator is designed for Ant Design Form components and performs the following validations:
|
|
8
|
+
* 1. Required field validation (if specified in rules)
|
|
9
|
+
* 2. Format validation for valid Tanzanian phone numbers using TZ_PHONE_NUMBER_REGEX
|
|
10
|
+
*
|
|
11
|
+
* The validator accepts phone numbers in the following formats:
|
|
12
|
+
* Format 1: With prefix
|
|
13
|
+
* - Starting with 255, 0, or +255
|
|
14
|
+
* - Followed by valid operator codes:
|
|
15
|
+
* • Vodacom: 74, 75, 76, 78, 79
|
|
16
|
+
* • Tigo: 65, 67, 71
|
|
17
|
+
* • Airtel: 68, 69, 77
|
|
18
|
+
* • Halotel: 61, 62
|
|
19
|
+
* - Followed by 7 digits
|
|
20
|
+
*
|
|
21
|
+
* Format 2: Without prefix
|
|
22
|
+
* - Starting directly with operator code (listed above)
|
|
23
|
+
* - Followed by 7 digits
|
|
24
|
+
*
|
|
25
|
+
* @param {RuleObject} rule - Ant Design rule object containing validation rules
|
|
26
|
+
* @param {string | null | undefined} value - The phone number to validate
|
|
27
|
+
* @returns {Promise<void>} Resolves if validation passes, rejects with Error if validation fails
|
|
28
|
+
* @throws {Error} Throws an error with a descriptive message for validation failures:
|
|
29
|
+
* - "Phone number is required." - When field is required but empty/null/undefined
|
|
30
|
+
* - "Invalid phone number format." - When value doesn't match expected TZ phone number format
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* // Usage in Ant Design form rules:
|
|
34
|
+
* const rules = [
|
|
35
|
+
* {
|
|
36
|
+
* required: true,
|
|
37
|
+
* validator: PHONENUMBER_VALIDATOR
|
|
38
|
+
* }
|
|
39
|
+
* ];
|
|
40
|
+
*
|
|
41
|
+
* // Valid inputs:
|
|
42
|
+
* // "+255742345678" -> International format with plus (Vodacom)
|
|
43
|
+
* // "255652345678" -> International format without plus (Tigo)
|
|
44
|
+
* // "0712345678" -> Local format with leading zero (Tigo)
|
|
45
|
+
* // "652345678" -> Local format without prefix (Tigo)
|
|
46
|
+
*
|
|
47
|
+
* // Invalid inputs:
|
|
48
|
+
* // "+255722345678" -> Invalid operator code (72)
|
|
49
|
+
* // "652345" -> Too short
|
|
50
|
+
* // "6523456789" -> Too long
|
|
51
|
+
* // "abc65234567" -> Non-numeric characters
|
|
52
|
+
* // "" -> Empty when required
|
|
53
|
+
* // undefined -> Missing when required
|
|
54
|
+
* // null -> Null when required
|
|
55
|
+
*
|
|
56
|
+
* @notes
|
|
57
|
+
* The validator uses TZ_PHONE_NUMBER_REGEX which matches:
|
|
58
|
+
* ^(?:255|0|\+255)(74|75|76|78|79|68|69|71|65|67|77|62|61)\d{7}$|^(?:74|75|76|78|79|68|69|71|65|67|77|62|61)\d{7}$
|
|
59
|
+
*
|
|
60
|
+
* This breaks down to:
|
|
61
|
+
* ^ -> Start of string
|
|
62
|
+
* (?:255|0|\+255) -> Country code group: 255, 0, or +255
|
|
63
|
+
* ( -> Start operator code group
|
|
64
|
+
* 74|75|76|78|79 -> Vodacom prefixes
|
|
65
|
+
* |68|69|71 -> Tigo prefixes
|
|
66
|
+
* |65|67|77 -> Airtel prefixes
|
|
67
|
+
* |62|61 -> Halotel prefixes
|
|
68
|
+
* ) -> End operator code group
|
|
69
|
+
* \d{7} -> Exactly 7 digits
|
|
70
|
+
* $ -> End of string
|
|
71
|
+
* | -> OR
|
|
72
|
+
* ^ -> Start of string (alternative format)
|
|
73
|
+
* (same operator codes as above)
|
|
74
|
+
* \d{7} -> Exactly 7 digits
|
|
75
|
+
* $ -> End of string
|
|
76
|
+
*/
|
|
77
|
+
exports.TZ_PHONE_NUMBER_REGEX = /^(?:255|0|\+255)(74|75|76|78|79|68|69|71|65|67|77|62|61)\d{7}$|^(?:74|75|76|78|79|68|69|71|65|67|77|62|61)\d{7}$/;
|
|
78
|
+
const PHONENUMBER_VALIDATOR = (rule, value) => {
|
|
79
|
+
const phoneString = value?.toString().trim();
|
|
80
|
+
// If field is empty/undefined/null
|
|
81
|
+
if (!phoneString) {
|
|
82
|
+
// Only throw if the field is required
|
|
83
|
+
if (rule.required) {
|
|
84
|
+
return Promise.reject(new Error("Phone number is required."));
|
|
85
|
+
}
|
|
86
|
+
// If field is not required and empty, validation passes
|
|
87
|
+
return Promise.resolve(undefined);
|
|
88
|
+
}
|
|
89
|
+
const phone = phone_number_js_1.PhoneNumber.from(phoneString);
|
|
90
|
+
if (phone)
|
|
91
|
+
return Promise.resolve(phone);
|
|
92
|
+
return Promise.reject(new Error("Invalid phone number format."));
|
|
93
|
+
};
|
|
94
|
+
exports.PHONENUMBER_VALIDATOR = PHONENUMBER_VALIDATOR;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"antdvalidator.test.d.ts","sourceRoot":"","sources":["../../../../src/src/models/phone_number/antdvalidator.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/src/models/phone_number/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./antd_validator.js"), exports);
|
|
18
|
+
__exportStar(require("./phone_number.js"), exports);
|
|
19
|
+
__exportStar(require("./telecom.js"), exports);
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview
|
|
3
|
+
*
|
|
4
|
+
* # Tanzania Phone Number Management System
|
|
5
|
+
*
|
|
6
|
+
* ## Problem Statement
|
|
7
|
+
* Tanzania's phone number system requires specific validation and formatting rules:
|
|
8
|
+
*
|
|
9
|
+
* 1. Phone numbers can be entered in multiple formats:
|
|
10
|
+
* - International format: "+255712345678"
|
|
11
|
+
* - Local format with country code: "255712345678"
|
|
12
|
+
* - Local format with leading zero: "0712345678"
|
|
13
|
+
* - Compact format: "712345678"
|
|
14
|
+
*
|
|
15
|
+
* 2. Valid numbers must:
|
|
16
|
+
* - Have exactly 9 digits after removing prefixes
|
|
17
|
+
* - Start with a valid telecom provider prefix
|
|
18
|
+
* - Contain only numeric characters
|
|
19
|
+
*
|
|
20
|
+
* 3. Each telecom provider has specific prefixes:
|
|
21
|
+
* - Vodacom: 71, 74, 75, etc.
|
|
22
|
+
* - Airtel: 68, 69, etc.
|
|
23
|
+
* - Tigo: 65, 67, etc.
|
|
24
|
+
*
|
|
25
|
+
* ## Solution
|
|
26
|
+
* The PhoneNumber class provides:
|
|
27
|
+
* 1. Parsing and validation of different input formats
|
|
28
|
+
* 2. Standardized storage in compact format
|
|
29
|
+
* 3. Formatting options for display and API use
|
|
30
|
+
* 4. Telecom provider identification
|
|
31
|
+
*/
|
|
32
|
+
import { type Telecom } from "./telecom.js";
|
|
33
|
+
/**
|
|
34
|
+
* Enumeration for various mobile number formats.
|
|
35
|
+
* @enum {string}
|
|
36
|
+
*/
|
|
37
|
+
export declare enum MobileNumberFormat {
|
|
38
|
+
s255 = "255",// Mobile numbers prefixed with 255
|
|
39
|
+
sp255 = "+255",// Mobile numbers prefixed with +255
|
|
40
|
+
s0 = "0",// Mobile numbers prefixed with 0
|
|
41
|
+
none = ""
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Represents a TZ phone number
|
|
45
|
+
*/
|
|
46
|
+
export declare class PhoneNumber {
|
|
47
|
+
/**
|
|
48
|
+
* Stores the phone number in a compact format excluding country code and the initial '0'.
|
|
49
|
+
*/
|
|
50
|
+
compactNumber: string;
|
|
51
|
+
/**
|
|
52
|
+
* Constructs a new `PhoneNumber` instance.
|
|
53
|
+
*
|
|
54
|
+
* @param compactNumber - The phone number in a compact format (e.g., "712345678").
|
|
55
|
+
*/
|
|
56
|
+
constructor(compactNumber: string);
|
|
57
|
+
/**
|
|
58
|
+
* Formats the compact phone number with the specified `MobileNumberFormat`.
|
|
59
|
+
*
|
|
60
|
+
* @param format - The desired phone number format (e.g., `+255` or `255`).
|
|
61
|
+
* @returns The phone number formatted as a string.
|
|
62
|
+
*/
|
|
63
|
+
getNumberWithFormat(format: MobileNumberFormat): string;
|
|
64
|
+
/**
|
|
65
|
+
* Returns the formatted label of the phone number using the `s255` format.
|
|
66
|
+
*
|
|
67
|
+
* @returns The phone number label in `255` format.
|
|
68
|
+
*/
|
|
69
|
+
get label(): string;
|
|
70
|
+
/**
|
|
71
|
+
* Derives the telecom details associated with the phone number by checking its prefix.
|
|
72
|
+
*
|
|
73
|
+
* @returns The `Telecom` object that matches the phone number prefix.
|
|
74
|
+
*/
|
|
75
|
+
get telecom(): Telecom;
|
|
76
|
+
/**
|
|
77
|
+
* Creates a `PhoneNumber` instance from a given string.
|
|
78
|
+
*
|
|
79
|
+
* @param s - The input phone number string in various formats (e.g., "+255712345678", "0712345678").
|
|
80
|
+
* @returns A `PhoneNumber` instance if valid, otherwise `undefined`.
|
|
81
|
+
*/
|
|
82
|
+
static from(s: string): PhoneNumber | undefined;
|
|
83
|
+
/**
|
|
84
|
+
* Checks if a string can be constructed into a valid phone number object.
|
|
85
|
+
* @param {string | undefined} input - The string to validate as a phone number.
|
|
86
|
+
* @returns {boolean} - Returns true if the input can be constructed into a valid phone number object,
|
|
87
|
+
* false if the input is undefined, empty, or cannot be parsed.
|
|
88
|
+
*/
|
|
89
|
+
static canConstruct(input?: string | null): boolean;
|
|
90
|
+
/**
|
|
91
|
+
* Checks if an unknown value contains valid data to construct a PhoneNumber instance.
|
|
92
|
+
* Validates the structural integrity of the phone number object.
|
|
93
|
+
*
|
|
94
|
+
* @param {unknown} obj - The value to validate.
|
|
95
|
+
* @returns {obj is PhoneNumber} Type predicate indicating if the value has a valid phone number structure.
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* const maybePhone = JSON.parse(someData);
|
|
99
|
+
* if (PhoneNumber.is(maybePhone)) {
|
|
100
|
+
* // maybePhone is typed as PhoneNumber
|
|
101
|
+
* console.log(maybePhone.label);
|
|
102
|
+
* }
|
|
103
|
+
*
|
|
104
|
+
* @remarks
|
|
105
|
+
* Validates:
|
|
106
|
+
* - Has required compactNumber property
|
|
107
|
+
* - compactNumber is a 9-digit string
|
|
108
|
+
* - Prefix matches a valid telecom provider
|
|
109
|
+
*/
|
|
110
|
+
static is(obj: unknown): obj is PhoneNumber;
|
|
111
|
+
/**
|
|
112
|
+
* Checks the validity of the phone number data
|
|
113
|
+
* @returns true if the phone number information is available and valid
|
|
114
|
+
*/
|
|
115
|
+
validate(): boolean;
|
|
116
|
+
}
|
|
117
|
+
//# sourceMappingURL=phone_number.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"phone_number.d.ts","sourceRoot":"","sources":["../../../../src/src/models/phone_number/phone_number.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,OAAO,EAAE,KAAK,OAAO,EAAkB,MAAM,cAAc,CAAC;AAE5D;;;GAGG;AACH,oBAAY,kBAAkB;IAC5B,IAAI,QAAQ,CAAE,mCAAmC;IACjD,KAAK,SAAS,CAAE,oCAAoC;IACpD,EAAE,MAAM,CAAE,iCAAiC;IAC3C,IAAI,KAAK;CACV;AAED;;GAEG;AACH,qBAAa,WAAW;IACtB;;OAEG;IACH,aAAa,EAAE,MAAM,CAAC;IAEtB;;;;OAIG;gBACS,aAAa,EAAE,MAAM;IAIjC;;;;;OAKG;IACH,mBAAmB,CAAC,MAAM,EAAE,kBAAkB,GAAG,MAAM;IAIvD;;;;OAIG;IACH,IAAI,KAAK,IAAI,MAAM,CAElB;IAED;;;;OAIG;IACH,IAAI,OAAO,IAAI,OAAO,CAMrB;IAED;;;;;OAKG;WACW,IAAI,CAAC,CAAC,EAAE,MAAM,GAAG,WAAW,GAAG,SAAS;IAqCtD;;;;;OAKG;WACW,YAAY,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO;IAW1D;;;;;;;;;;;;;;;;;;;OAmBG;WACW,EAAE,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,WAAW;IAYlD;;;OAGG;IACI,QAAQ,IAAI,OAAO;CAO3B"}
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @fileoverview
|
|
4
|
+
*
|
|
5
|
+
* # Tanzania Phone Number Management System
|
|
6
|
+
*
|
|
7
|
+
* ## Problem Statement
|
|
8
|
+
* Tanzania's phone number system requires specific validation and formatting rules:
|
|
9
|
+
*
|
|
10
|
+
* 1. Phone numbers can be entered in multiple formats:
|
|
11
|
+
* - International format: "+255712345678"
|
|
12
|
+
* - Local format with country code: "255712345678"
|
|
13
|
+
* - Local format with leading zero: "0712345678"
|
|
14
|
+
* - Compact format: "712345678"
|
|
15
|
+
*
|
|
16
|
+
* 2. Valid numbers must:
|
|
17
|
+
* - Have exactly 9 digits after removing prefixes
|
|
18
|
+
* - Start with a valid telecom provider prefix
|
|
19
|
+
* - Contain only numeric characters
|
|
20
|
+
*
|
|
21
|
+
* 3. Each telecom provider has specific prefixes:
|
|
22
|
+
* - Vodacom: 71, 74, 75, etc.
|
|
23
|
+
* - Airtel: 68, 69, etc.
|
|
24
|
+
* - Tigo: 65, 67, etc.
|
|
25
|
+
*
|
|
26
|
+
* ## Solution
|
|
27
|
+
* The PhoneNumber class provides:
|
|
28
|
+
* 1. Parsing and validation of different input formats
|
|
29
|
+
* 2. Standardized storage in compact format
|
|
30
|
+
* 3. Formatting options for display and API use
|
|
31
|
+
* 4. Telecom provider identification
|
|
32
|
+
*/
|
|
33
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
34
|
+
exports.PhoneNumber = exports.MobileNumberFormat = void 0;
|
|
35
|
+
const telecom_js_1 = require("./telecom.js");
|
|
36
|
+
/**
|
|
37
|
+
* Enumeration for various mobile number formats.
|
|
38
|
+
* @enum {string}
|
|
39
|
+
*/
|
|
40
|
+
var MobileNumberFormat;
|
|
41
|
+
(function (MobileNumberFormat) {
|
|
42
|
+
MobileNumberFormat["s255"] = "255";
|
|
43
|
+
MobileNumberFormat["sp255"] = "+255";
|
|
44
|
+
MobileNumberFormat["s0"] = "0";
|
|
45
|
+
MobileNumberFormat["none"] = "";
|
|
46
|
+
})(MobileNumberFormat || (exports.MobileNumberFormat = MobileNumberFormat = {}));
|
|
47
|
+
/**
|
|
48
|
+
* Represents a TZ phone number
|
|
49
|
+
*/
|
|
50
|
+
class PhoneNumber {
|
|
51
|
+
/**
|
|
52
|
+
* Constructs a new `PhoneNumber` instance.
|
|
53
|
+
*
|
|
54
|
+
* @param compactNumber - The phone number in a compact format (e.g., "712345678").
|
|
55
|
+
*/
|
|
56
|
+
constructor(compactNumber) {
|
|
57
|
+
/**
|
|
58
|
+
* Stores the phone number in a compact format excluding country code and the initial '0'.
|
|
59
|
+
*/
|
|
60
|
+
Object.defineProperty(this, "compactNumber", {
|
|
61
|
+
enumerable: true,
|
|
62
|
+
configurable: true,
|
|
63
|
+
writable: true,
|
|
64
|
+
value: void 0
|
|
65
|
+
});
|
|
66
|
+
this.compactNumber = compactNumber;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Formats the compact phone number with the specified `MobileNumberFormat`.
|
|
70
|
+
*
|
|
71
|
+
* @param format - The desired phone number format (e.g., `+255` or `255`).
|
|
72
|
+
* @returns The phone number formatted as a string.
|
|
73
|
+
*/
|
|
74
|
+
getNumberWithFormat(format) {
|
|
75
|
+
return `${format}${this.compactNumber}`;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Returns the formatted label of the phone number using the `s255` format.
|
|
79
|
+
*
|
|
80
|
+
* @returns The phone number label in `255` format.
|
|
81
|
+
*/
|
|
82
|
+
get label() {
|
|
83
|
+
return this.getNumberWithFormat(MobileNumberFormat.s255);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Derives the telecom details associated with the phone number by checking its prefix.
|
|
87
|
+
*
|
|
88
|
+
* @returns The `Telecom` object that matches the phone number prefix.
|
|
89
|
+
*/
|
|
90
|
+
get telecom() {
|
|
91
|
+
const id = this.compactNumber.substring(0, 2);
|
|
92
|
+
const result = Object.values(telecom_js_1.telecomDetails).find((e) => e.prefixes.includes(id));
|
|
93
|
+
return result;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Creates a `PhoneNumber` instance from a given string.
|
|
97
|
+
*
|
|
98
|
+
* @param s - The input phone number string in various formats (e.g., "+255712345678", "0712345678").
|
|
99
|
+
* @returns A `PhoneNumber` instance if valid, otherwise `undefined`.
|
|
100
|
+
*/
|
|
101
|
+
static from(s) {
|
|
102
|
+
try {
|
|
103
|
+
const number = removeSpaces(s.trim());
|
|
104
|
+
if (number.length === 0)
|
|
105
|
+
return;
|
|
106
|
+
const isOnlyDigits = isOnlyDigitsOrPlus(number);
|
|
107
|
+
if (!isOnlyDigits)
|
|
108
|
+
return;
|
|
109
|
+
let compactNumber;
|
|
110
|
+
// Extract the compact number by removing country or local dialing prefixes.
|
|
111
|
+
if (number.startsWith("+255")) {
|
|
112
|
+
compactNumber = number.substring(4);
|
|
113
|
+
}
|
|
114
|
+
else if (number.startsWith("255")) {
|
|
115
|
+
compactNumber = number.substring(3);
|
|
116
|
+
}
|
|
117
|
+
else if (number.startsWith("0")) {
|
|
118
|
+
compactNumber = number.substring(1);
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
compactNumber = number;
|
|
122
|
+
}
|
|
123
|
+
// Validate that the compact number length is correct.
|
|
124
|
+
if (compactNumber.length !== 9)
|
|
125
|
+
return;
|
|
126
|
+
// Check if the compact number matches any telecom provider prefix.
|
|
127
|
+
const id = compactNumber.substring(0, 2);
|
|
128
|
+
const telecom = Object.values(telecom_js_1.telecomDetails).find((e) => e.prefixes.includes(id));
|
|
129
|
+
if (!telecom)
|
|
130
|
+
return;
|
|
131
|
+
return new PhoneNumber(compactNumber);
|
|
132
|
+
}
|
|
133
|
+
catch (_) {
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Checks if a string can be constructed into a valid phone number object.
|
|
139
|
+
* @param {string | undefined} input - The string to validate as a phone number.
|
|
140
|
+
* @returns {boolean} - Returns true if the input can be constructed into a valid phone number object,
|
|
141
|
+
* false if the input is undefined, empty, or cannot be parsed.
|
|
142
|
+
*/
|
|
143
|
+
static canConstruct(input) {
|
|
144
|
+
if (!input || typeof input !== "string")
|
|
145
|
+
return false;
|
|
146
|
+
const text = removeSpaces(input.trim());
|
|
147
|
+
if (text.length === 0)
|
|
148
|
+
return false;
|
|
149
|
+
const phone = PhoneNumber.from(text);
|
|
150
|
+
return phone !== undefined;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Checks if an unknown value contains valid data to construct a PhoneNumber instance.
|
|
154
|
+
* Validates the structural integrity of the phone number object.
|
|
155
|
+
*
|
|
156
|
+
* @param {unknown} obj - The value to validate.
|
|
157
|
+
* @returns {obj is PhoneNumber} Type predicate indicating if the value has a valid phone number structure.
|
|
158
|
+
*
|
|
159
|
+
* @example
|
|
160
|
+
* const maybePhone = JSON.parse(someData);
|
|
161
|
+
* if (PhoneNumber.is(maybePhone)) {
|
|
162
|
+
* // maybePhone is typed as PhoneNumber
|
|
163
|
+
* console.log(maybePhone.label);
|
|
164
|
+
* }
|
|
165
|
+
*
|
|
166
|
+
* @remarks
|
|
167
|
+
* Validates:
|
|
168
|
+
* - Has required compactNumber property
|
|
169
|
+
* - compactNumber is a 9-digit string
|
|
170
|
+
* - Prefix matches a valid telecom provider
|
|
171
|
+
*/
|
|
172
|
+
static is(obj) {
|
|
173
|
+
if (!obj || typeof obj !== "object")
|
|
174
|
+
return false;
|
|
175
|
+
const maybePhone = obj;
|
|
176
|
+
// Check if compactNumber exists and is string
|
|
177
|
+
if (typeof maybePhone.compactNumber !== "string")
|
|
178
|
+
return false;
|
|
179
|
+
const compactNumber = maybePhone.compactNumber;
|
|
180
|
+
return PhoneNumber.canConstruct(compactNumber);
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Checks the validity of the phone number data
|
|
184
|
+
* @returns true if the phone number information is available and valid
|
|
185
|
+
*/
|
|
186
|
+
validate() {
|
|
187
|
+
try {
|
|
188
|
+
return PhoneNumber.canConstruct(this.compactNumber);
|
|
189
|
+
}
|
|
190
|
+
catch (_) {
|
|
191
|
+
return false;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
exports.PhoneNumber = PhoneNumber;
|
|
196
|
+
/**
|
|
197
|
+
* Removes all whitespace characters from the given string.
|
|
198
|
+
*
|
|
199
|
+
* This function replaces all occurrences of spaces, tabs, and other
|
|
200
|
+
* whitespace characters (including multiple spaces) in the input string
|
|
201
|
+
* with an empty string, effectively removing them.
|
|
202
|
+
*
|
|
203
|
+
* @param {string} input - The input string from which spaces should be removed.
|
|
204
|
+
* @returns {string} A new string with all whitespace characters removed.
|
|
205
|
+
*
|
|
206
|
+
* @example
|
|
207
|
+
* removeSpaces(" Hello World "); // Returns: "HelloWorld"
|
|
208
|
+
* removeSpaces("NoSpacesHere"); // Returns: "NoSpacesHere"
|
|
209
|
+
* removeSpaces(" "); // Returns: ""
|
|
210
|
+
*/
|
|
211
|
+
function removeSpaces(input) {
|
|
212
|
+
return input.replace(/\s+/g, "");
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Checks if a given string contains only digits or a `+` prefix followed by digits.
|
|
216
|
+
*
|
|
217
|
+
* This function validates that the input string:
|
|
218
|
+
* - Can optionally start with a `+` sign.
|
|
219
|
+
* - Must have one or more digits after the optional `+`.
|
|
220
|
+
* - Does not contain any other characters besides digits and the `+` prefix.
|
|
221
|
+
*
|
|
222
|
+
* @param {string} input - The input string to validate.
|
|
223
|
+
* @returns {boolean} `true` if the string contains only digits or a `+` prefix followed by digits; otherwise, `false`.
|
|
224
|
+
*
|
|
225
|
+
* @example
|
|
226
|
+
* isOnlyDigitsOrPlus("12345"); // Returns: true
|
|
227
|
+
* isOnlyDigitsOrPlus("+12345"); // Returns: true
|
|
228
|
+
* isOnlyDigitsOrPlus("123a45"); // Returns: false
|
|
229
|
+
* isOnlyDigitsOrPlus("+"); // Returns: false
|
|
230
|
+
* isOnlyDigitsOrPlus(""); // Returns: false
|
|
231
|
+
*/
|
|
232
|
+
function isOnlyDigitsOrPlus(input) {
|
|
233
|
+
const digitWithPlusRegex = /^\+?\d+$/;
|
|
234
|
+
return digitWithPlusRegex.test(input);
|
|
235
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"phone_number.test.d.ts","sourceRoot":"","sources":["../../../../src/src/models/phone_number/phone_number.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Enumeration for telecom identifiers.
|
|
3
|
+
* @enum {string}
|
|
4
|
+
*/
|
|
5
|
+
export declare enum TelecomID {
|
|
6
|
+
vodacom = "vodacom",
|
|
7
|
+
airtel = "airtel",
|
|
8
|
+
tigo = "tigo",
|
|
9
|
+
halotel = "halotel"
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Interface representing a telecom provider.
|
|
13
|
+
*/
|
|
14
|
+
export interface Telecom {
|
|
15
|
+
id: TelecomID;
|
|
16
|
+
prefixes: string[];
|
|
17
|
+
label: string;
|
|
18
|
+
company: string;
|
|
19
|
+
color: string;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Details for each telecom provider including prefixes and branding information.
|
|
23
|
+
*/
|
|
24
|
+
export declare const telecomDetails: Record<TelecomID, Telecom>;
|
|
25
|
+
//# sourceMappingURL=telecom.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"telecom.d.ts","sourceRoot":"","sources":["../../../../src/src/models/phone_number/telecom.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,oBAAY,SAAS;IACnB,OAAO,YAAY;IACnB,MAAM,WAAW;IACjB,IAAI,SAAS;IACb,OAAO,YAAY;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,OAAO;IACtB,EAAE,EAAE,SAAS,CAAC;IACd,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;GAEG;AACH,eAAO,MAAM,cAAc,EAAE,MAAM,CAAC,SAAS,EAAE,OAAO,CA6BrD,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.telecomDetails = exports.TelecomID = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Enumeration for telecom identifiers.
|
|
6
|
+
* @enum {string}
|
|
7
|
+
*/
|
|
8
|
+
var TelecomID;
|
|
9
|
+
(function (TelecomID) {
|
|
10
|
+
TelecomID["vodacom"] = "vodacom";
|
|
11
|
+
TelecomID["airtel"] = "airtel";
|
|
12
|
+
TelecomID["tigo"] = "tigo";
|
|
13
|
+
TelecomID["halotel"] = "halotel";
|
|
14
|
+
})(TelecomID || (exports.TelecomID = TelecomID = {}));
|
|
15
|
+
/**
|
|
16
|
+
* Details for each telecom provider including prefixes and branding information.
|
|
17
|
+
*/
|
|
18
|
+
exports.telecomDetails = {
|
|
19
|
+
vodacom: {
|
|
20
|
+
id: TelecomID.vodacom,
|
|
21
|
+
prefixes: ["74", "75", "76"],
|
|
22
|
+
label: "Vodacom",
|
|
23
|
+
company: "M-Pesa",
|
|
24
|
+
color: "red",
|
|
25
|
+
},
|
|
26
|
+
airtel: {
|
|
27
|
+
id: TelecomID.airtel,
|
|
28
|
+
prefixes: ["78", "79", "68", "69"],
|
|
29
|
+
label: "Airtel",
|
|
30
|
+
company: "Airtel-Money",
|
|
31
|
+
color: "volcano",
|
|
32
|
+
},
|
|
33
|
+
tigo: {
|
|
34
|
+
id: TelecomID.tigo,
|
|
35
|
+
prefixes: ["71", "65", "67", "77"],
|
|
36
|
+
label: "Tigo",
|
|
37
|
+
company: "Tigo-Pesa",
|
|
38
|
+
color: "blue",
|
|
39
|
+
},
|
|
40
|
+
halotel: {
|
|
41
|
+
id: TelecomID.halotel,
|
|
42
|
+
prefixes: ["62", "61"],
|
|
43
|
+
label: "Halotel",
|
|
44
|
+
company: "Halo-Pesa",
|
|
45
|
+
color: "orange",
|
|
46
|
+
},
|
|
47
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates a unique UUID (version 4).
|
|
3
|
+
* @returns {string} - A randomly generated UUID string.
|
|
4
|
+
*/
|
|
5
|
+
export declare function generateUniqueUUID(): string;
|
|
6
|
+
/**
|
|
7
|
+
* Generates a UUID (version 5) based on the input string and a predefined namespace.
|
|
8
|
+
* @param {string} data - The input string to generate the UUID from.
|
|
9
|
+
* @returns {string} - A UUID string generated from the input string.
|
|
10
|
+
*/
|
|
11
|
+
export declare function generateUuidBasedOn(data: string): string;
|
|
12
|
+
//# sourceMappingURL=id.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"id.d.ts","sourceRoot":"","sources":["../../../src/src/utils/id.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,wBAAgB,kBAAkB,IAAI,MAAM,CAE3C;AAKD;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAExD"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateUniqueUUID = generateUniqueUUID;
|
|
4
|
+
exports.generateUuidBasedOn = generateUuidBasedOn;
|
|
5
|
+
const uuid_1 = require("uuid");
|
|
6
|
+
const uuid_2 = require("uuid");
|
|
7
|
+
/**
|
|
8
|
+
* Generates a unique UUID (version 4).
|
|
9
|
+
* @returns {string} - A randomly generated UUID string.
|
|
10
|
+
*/
|
|
11
|
+
function generateUniqueUUID() {
|
|
12
|
+
return (0, uuid_1.v4)();
|
|
13
|
+
}
|
|
14
|
+
// Predefined namespace
|
|
15
|
+
const NAMESPACE = uuid_2.v5.DNS;
|
|
16
|
+
/**
|
|
17
|
+
* Generates a UUID (version 5) based on the input string and a predefined namespace.
|
|
18
|
+
* @param {string} data - The input string to generate the UUID from.
|
|
19
|
+
* @returns {string} - A UUID string generated from the input string.
|
|
20
|
+
*/
|
|
21
|
+
function generateUuidBasedOn(data) {
|
|
22
|
+
return (0, uuid_2.v5)(data, NAMESPACE);
|
|
23
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./id.js"), exports);
|
|
18
|
+
__exportStar(require("./time.js"), exports);
|
|
19
|
+
__exportStar(require("./text.js"), exports);
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Capitalizes the first letter of a string and converts the rest of the string to lowercase.
|
|
3
|
+
* @param {string} str - The input string.
|
|
4
|
+
* @returns {string} - The formatted string with the first letter capitalized.
|
|
5
|
+
*/
|
|
6
|
+
export declare function capitalizeFirstLetter(str: string): string;
|
|
7
|
+
/**
|
|
8
|
+
* Combines a first name and a last name into a full name.
|
|
9
|
+
* @param {string} firstName - The first name.
|
|
10
|
+
* @param {string} lastName - The last name.
|
|
11
|
+
* @returns {string} - The full name formatted as "FirstName LastName".
|
|
12
|
+
*/
|
|
13
|
+
export declare function getFullName(firstName: string, lastName: string): string;
|
|
14
|
+
/**
|
|
15
|
+
* Generates a URL-friendly slug from a given text.
|
|
16
|
+
* @param {string} text - The input string.
|
|
17
|
+
* @returns {string} - The generated slug with lowercase alphanumeric characters and hyphens.
|
|
18
|
+
*/
|
|
19
|
+
export declare function generateSlug(text: string): string;
|
|
20
|
+
/**
|
|
21
|
+
* Abbreviates a full name into a first name and the initial of the last name.
|
|
22
|
+
* @param {string} fullName - The input full name.
|
|
23
|
+
* @returns {string} - The abbreviated name in the format "FirstName L.".
|
|
24
|
+
*/
|
|
25
|
+
export declare function abbreviateName(fullName: string): string;
|
|
26
|
+
/**
|
|
27
|
+
* Extracts the initials from a full name.
|
|
28
|
+
* @param {string} fullName - The input full name.
|
|
29
|
+
* @returns {string} - The initials in uppercase format.
|
|
30
|
+
*/
|
|
31
|
+
export declare function getInitialsFrom(fullName: string): string;
|
|
32
|
+
//# sourceMappingURL=text.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"text.d.ts","sourceRoot":"","sources":["../../../src/src/utils/text.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CASzD;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAEvE;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAOjD;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAYvD;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAcxD"}
|