@nodibyte/bd-utils 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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Nodibyte
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,42 @@
1
- # Temporary Holding Version
1
+ # @nodibyte/bd-utils
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Bangladeshi mobile number validation and Bangla digit parsing. Zero dependencies, ~30 lines.
4
+
5
+ Users on Bangla keyboards type `০১৭১২৩৪৫৬৭৮`. Most BD phone regexes reject that. This doesn't.
6
+
7
+ ```bash
8
+ npm install @nodibyte/bd-utils
9
+ ```
10
+
11
+ ```js
12
+ import { normalizeMobile, isMobile, toE164, operator, toAsciiDigits } from '@nodibyte/bd-utils'
13
+
14
+ normalizeMobile('+880 1712-345678') // '01712345678'
15
+ normalizeMobile('০১৭১২৩৪৫৬৭৮') // '01712345678'
16
+ normalizeMobile('01212345678') // null
17
+ isMobile('01912345678') // true
18
+ toE164('01812345678') // '+8801812345678'
19
+ operator('01612345678') // 'Robi'
20
+ toAsciiDigits('৳১,২৩৪') // '৳1,234'
21
+ ```
22
+
23
+ | Function | Returns |
24
+ |---|---|
25
+ | `normalizeMobile(s)` | `01XXXXXXXXX`, or `null` if not a valid BD mobile. Accepts `+88`/`88` prefix, spaces, dashes, dots, brackets, Bangla digits. |
26
+ | `isMobile(s)` | `boolean` |
27
+ | `toE164(s)` | `+8801XXXXXXXXX` or `null` (for SMS gateways, WhatsApp links) |
28
+ | `operator(s)` | `'Grameenphone'` (013, 017), `'Banglalink'` (014, 019), `'Teletalk'` (015), `'Robi'` (016, 018), or `null`. By prefix, so a ported number shows its original operator. |
29
+ | `toAsciiDigits(s)` | Same string with ০–৯ replaced by 0–9. Run before `Number()` or `parseFloat()` on user input. |
30
+
31
+ ## Formatting? Use the platform
32
+
33
+ Showing numbers in Bangla or with lakh/crore grouping needs no library:
34
+
35
+ ```js
36
+ (1234567).toLocaleString('bn-BD') // '১২,৩৪,৫৬৭'
37
+ (1234567).toLocaleString('en-IN') // '12,34,567'
38
+ ```
39
+
40
+ ## License
41
+
42
+ MIT © [Nodibyte](https://www.nodibyte.com). Used in Nodibyte's store, pharmacy and restaurant software.
package/index.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ export type Operator = 'Grameenphone' | 'Banglalink' | 'Teletalk' | 'Robi'
2
+ export function toAsciiDigits(text: string | number): string
3
+ export function normalizeMobile(input: string): string | null
4
+ export function isMobile(input: string): boolean
5
+ export function toE164(input: string): string | null
6
+ export function operator(input: string): Operator | null
package/index.js ADDED
@@ -0,0 +1,27 @@
1
+ const BN_ZERO = 0x09e6
2
+
3
+ export function toAsciiDigits(text) {
4
+ return String(text).replace(/[০-৯]/g, (d) => String(d.charCodeAt(0) - BN_ZERO))
5
+ }
6
+
7
+ export function normalizeMobile(input) {
8
+ const digits = toAsciiDigits(input).replace(/[\s\-().]/g, '').replace(/^(?:\+?88)/, '')
9
+ return /^01[3-9]\d{8}$/.test(digits) ? digits : null
10
+ }
11
+
12
+ export function isMobile(input) {
13
+ return normalizeMobile(input) !== null
14
+ }
15
+
16
+ export function toE164(input) {
17
+ const n = normalizeMobile(input)
18
+ return n && `+88${n}`
19
+ }
20
+
21
+ const OPERATORS = { 3: 'Grameenphone', 7: 'Grameenphone', 4: 'Banglalink', 9: 'Banglalink', 5: 'Teletalk', 6: 'Robi', 8: 'Robi' }
22
+
23
+ // Prefix only: numbers ported between operators keep their old prefix.
24
+ export function operator(input) {
25
+ const n = normalizeMobile(input)
26
+ return n && OPERATORS[n[2]]
27
+ }
package/package.json CHANGED
@@ -1,6 +1,18 @@
1
1
  {
2
2
  "name": "@nodibyte/bd-utils",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "Bangladeshi mobile number validation and Bangla digit parsing. Zero dependencies.",
5
+ "type": "module",
6
+ "main": "index.js",
7
+ "types": "index.d.ts",
8
+ "exports": { ".": { "types": "./index.d.ts", "default": "./index.js" } },
9
+ "files": ["index.js", "index.d.ts"],
10
+ "scripts": { "test": "node test.js" },
11
+ "keywords": ["bangladesh", "bangla", "bengali", "mobile", "phone", "validation", "bkash", "digits"],
12
+ "author": "Nodibyte <hello@nodibyte.com> (https://www.nodibyte.com)",
13
+ "license": "MIT",
14
+ "repository": { "type": "git", "url": "git+https://github.com/nodibyte/bd-utils.git" },
15
+ "homepage": "https://github.com/nodibyte/bd-utils#readme",
16
+ "bugs": "https://github.com/nodibyte/bd-utils/issues",
17
+ "sideEffects": false
18
+ }