Skip to content

Commit 782f013

Browse files
committed
initial commit
0 parents  commit 782f013

File tree

8 files changed

+139
-0
lines changed

8 files changed

+139
-0
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
pnpm-lock.yaml
3+
dist

.prettierrc

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"bracketSameLine": true,
3+
"arrowParens": "always",
4+
"bracketSpacing": true,
5+
"endOfLine": "lf",
6+
"semi": false,
7+
"useTabs": true,
8+
"tabWidth": 4,
9+
"singleQuote": true
10+
}

package.json

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "arabic",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "dist/index.js",
6+
"types": "dist/index.d.ts",
7+
"files": [
8+
"dist"
9+
],
10+
"scripts": {
11+
"build": "tsc"
12+
},
13+
"keywords": [],
14+
"author": "",
15+
"license": "MIT",
16+
"devDependencies": {
17+
"typescript": "^5.8.2"
18+
}
19+
}

src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './util.ts'

src/regex.ts

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export const harakat = /[\u064b-\u064f\u0650-\u0652]/g
2+
3+
// yes. both of these numbering systems are arabic.
4+
export const western_arabic_digits = /[\u0030-\u0039]/g
5+
export const eastern_arabic_digits = /[\u0660-\u0669]/g

src/util.ts

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import {
2+
eastern_arabic_digits,
3+
harakat,
4+
western_arabic_digits,
5+
} from './regex.ts'
6+
7+
const w_digits = '0123456789'
8+
const e_digits = '٠١٢٣٤٥٦٧٨٩'
9+
10+
/**
11+
* Remove harakat (also know as "tashkeel") from Arabic text.
12+
*/
13+
export function remove_harakat(string: string) {
14+
return string.replace(harakat, '')
15+
}
16+
17+
/**
18+
* Convert eastern arabic digits (١٢٣) to western arabic digits (123)
19+
*/
20+
export function to_western_digits(string: string | number): string {
21+
return String(string).replace(
22+
eastern_arabic_digits,
23+
(digit: string): string => {
24+
return w_digits[e_digits.indexOf(digit)]
25+
}
26+
)
27+
}
28+
29+
/**
30+
* Convert western arabic digits (123) to eastern arabic digits (١٢٣)
31+
*/
32+
export function to_eastern_digits(string: string | number): string {
33+
return String(string).replace(
34+
western_arabic_digits,
35+
(digit: string): string => {
36+
return e_digits[w_digits.indexOf(digit)]
37+
}
38+
)
39+
}

test.js

Whitespace-only changes.

tsconfig.json

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{
2+
"compilerOptions": {
3+
/* Language and Environment */
4+
"target": "ES6", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
5+
6+
/* Modules */
7+
"module": "ESNext", /* Specify what module code is generated. */
8+
"rewriteRelativeImportExtensions": true, /* Rewrite '.ts', '.tsx', '.mts', and '.cts' file extensions in relative import paths to their JavaScript equivalent in output files. */
9+
10+
/* JavaScript Support */
11+
// "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
12+
// "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
13+
// "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
14+
15+
/* Emit */
16+
"declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
17+
// "declarationMap": true, /* Create sourcemaps for d.ts files. */
18+
// "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
19+
// "sourceMap": true, /* Create source map files for emitted JavaScript files. */
20+
// "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
21+
// "noEmit": true, /* Disable emitting files from a compilation. */
22+
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
23+
"outDir": "./dist", /* Specify an output folder for all emitted files. */
24+
25+
/* Interop Constraints */
26+
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
27+
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
28+
29+
/* Type Checking */
30+
"strict": true, /* Enable all strict type-checking options. */
31+
// "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
32+
// "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
33+
// "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
34+
// "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
35+
// "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
36+
// "strictBuiltinIteratorReturn": true, /* Built-in iterators are instantiated with a 'TReturn' type of 'undefined' instead of 'any'. */
37+
// "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
38+
// "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */
39+
// "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
40+
// "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */
41+
// "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */
42+
// "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
43+
// "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
44+
// "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
45+
// "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
46+
// "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
47+
// "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */
48+
// "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
49+
// "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
50+
51+
/* Completeness */
52+
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
53+
"skipLibCheck": true /* Skip type checking all .d.ts files. */
54+
},
55+
"include": [
56+
"src/**/*.ts"
57+
],
58+
"exclude": [
59+
"node_modules",
60+
"dist"
61+
]
62+
}

0 commit comments

Comments
 (0)