bayda-maghreb 1.0.1 → 1.0.2
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/index.js +46 -27
- package/package.json +2 -1
- package/test.mjs +9 -0
package/index.js
CHANGED
|
@@ -1,34 +1,53 @@
|
|
|
1
|
-
import path from 'path'
|
|
2
|
-
import { fileURLToPath } from 'url'
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import path from 'path'
|
|
2
|
+
import { fileURLToPath } from 'url'
|
|
3
|
+
import fs from 'fs'
|
|
4
|
+
import { dialects } from './src/dialect-registry.js'
|
|
5
|
+
|
|
6
|
+
const __filename = fileURLToPath(import.meta.url)
|
|
7
|
+
const __dirname = path.dirname(__filename)
|
|
7
8
|
|
|
8
9
|
function load(entry) {
|
|
9
|
-
const p = path.join(__dirname, 'data/dialects', entry.file)
|
|
10
|
-
const dialect = JSON.parse(fs.readFileSync(p, 'utf8'))
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
10
|
+
const p = path.join(__dirname, 'data/dialects', entry.file)
|
|
11
|
+
const dialect = JSON.parse(fs.readFileSync(p, 'utf8'))
|
|
12
|
+
return dialect
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function getDialect(code = 'kab') {
|
|
16
|
+
const entry = dialects.find(d => d.code === code)
|
|
17
|
+
if (!entry) throw new Error(`${code} not found`)
|
|
18
|
+
return load(entry)
|
|
17
19
|
}
|
|
18
20
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
export function getAllDialects() {
|
|
22
|
+
return dialects.map(e => load(e))
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export { dialects }
|
|
26
|
+
|
|
27
|
+
// باش يبقى يخدم كيما قبل كي تعمل node index.js kab
|
|
28
|
+
const arg = process.argv[2] || 'kab'
|
|
29
|
+
if (process.argv[1] && process.argv[1].endsWith('index.js')) {
|
|
30
|
+
if (arg === '--test') {
|
|
31
|
+
let bad = 0
|
|
32
|
+
for (const e of dialects) {
|
|
33
|
+
try {
|
|
34
|
+
const d = load(e)
|
|
35
|
+
console.log(`✅ ${e.code} - ${Object.keys(d.keywords).length} words`)
|
|
36
|
+
} catch (err) {
|
|
37
|
+
console.log(`❌ ${e.code}: ${err.message}`); bad++
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
process.exit(bad ? 1 : 0)
|
|
41
|
+
} else {
|
|
23
42
|
try {
|
|
24
|
-
const
|
|
25
|
-
console.log(
|
|
26
|
-
|
|
27
|
-
|
|
43
|
+
const d = getDialect(arg)
|
|
44
|
+
console.log(`✅ loaded: ${d.name} - ${Object.keys(d.keywords).length} words`)
|
|
45
|
+
} catch (e) {
|
|
46
|
+
console.error(`❌ ${e.message}`); process.exit(1)
|
|
47
|
+
}
|
|
28
48
|
}
|
|
29
|
-
process.exit(bad? 1 : 0);
|
|
30
49
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
50
|
+
|
|
51
|
+
// export default باش يخدم مع require و import
|
|
52
|
+
export default { getDialect, getAllDialects, dialects }
|
|
53
|
+
export const kab = getDialect('kab')
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bayda-maghreb",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Bayda Maghreb - Tunisian, Algerian, Moroccan, Libyan, Mauritanian Arabic and Franco transliteration",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.js",
|
|
@@ -18,3 +18,4 @@
|
|
|
18
18
|
"test": "node index.js --test"
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
|
+
|
package/test.mjs
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { kab, getDialect, getAllDialects } from './index.js'
|
|
2
|
+
|
|
3
|
+
const kabData = getDialect('kab')
|
|
4
|
+
console.log('✅ kab:', kabData.name, '-', Object.keys(kabData.keywords).length, 'words')
|
|
5
|
+
|
|
6
|
+
const dzData = getDialect('dz')
|
|
7
|
+
console.log('✅ dz:', dzData.name, '-', Object.keys(dzData.keywords).length, 'words')
|
|
8
|
+
|
|
9
|
+
console.log('✅ كلهم:', getAllDialects().length, 'لهجات')
|