bayda-maghreb 1.0.0 → 1.0.1

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.
Files changed (2) hide show
  1. package/index.js +14 -19
  2. package/package.json +9 -2
package/index.js CHANGED
@@ -1,18 +1,18 @@
1
+ import path from 'path';
2
+ import { fileURLToPath } from 'url';
3
+ const __filename = fileURLToPath(import.meta.url);
4
+ const __dirname = path.dirname(__filename);
1
5
  import fs from 'fs';
2
6
  import { dialects } from './src/dialect-registry.js';
3
7
 
4
8
  function load(entry) {
5
- const dialect = JSON.parse(fs.readFileSync(`./data/dialects/${entry.file}`, 'utf8'));
9
+ const p = path.join(__dirname, 'data/dialects', entry.file);
10
+ const dialect = JSON.parse(fs.readFileSync(p, 'utf8'));
6
11
  const problems = [];
7
- if (dialect.code!== entry.code) problems.push(`code في الملف (${dialect.code}) لا يطابق السجل (${entry.code})`);
8
- if (!dialect.name) problems.push('name مفقود');
9
- if (!dialect.script) problems.push('script مفقود');
10
- const kw = dialect.keywords;
11
- if (!kw || typeof kw!== 'object' ||!Object.keys(kw).length) problems.push('keywords فارغة أو مفقودة');
12
- else for (const [word, target] of Object.entries(kw)) {
13
- if (!/^[\p{L}\p{M}\p{N}_ ]+$/u.test(word)) problems.push(`كلمة غير مقبولة: ${word}`);
14
- if (typeof target!== 'string' ||!target) problems.push(`هدف غير صالح: ${word}`);
15
- }
12
+ if (dialect.code!== entry.code) problems.push(`code mismatch`);
13
+ if (!dialect.name) problems.push('name missing');
14
+ if (!dialect.script) problems.push('script missing');
15
+ if (!dialect.keywords ||!Object.keys(dialect.keywords).length) problems.push('keywords empty');
16
16
  return { dialect, problems };
17
17
  }
18
18
 
@@ -23,17 +23,12 @@ if (arg === '--test') {
23
23
  try {
24
24
  const { problems } = load(e);
25
25
  console.log(problems.length? `❌ ${e.code}` : `✅ ${e.code}`);
26
- problems.forEach(p => console.log(' -', p));
27
- bad += problems.length;
26
+ if(problems.length) bad++;
28
27
  } catch (err) { console.log(`❌ ${e.code}: ${err.message}`); bad++; }
29
28
  }
30
29
  process.exit(bad? 1 : 0);
31
30
  }
32
31
  const entry = dialects.find(d => d.code === arg);
33
- if (!entry) { console.error(`❌ لهجة غير معروفة: ${arg}\nالمتاح: ${dialects.map(d => d.code).join(', ')}`); process.exit(1); }
34
- try {
35
- const { dialect, problems } = load(entry);
36
- console.log(`✅ تم تحميل لهجة: ${dialect.name}`);
37
- console.log('الكلمات:', Object.keys(dialect.keywords).slice(0, 5));
38
- problems.forEach(p => console.error('⚠️', p));
39
- } catch (e) { console.error('❌ خطأ:', e.message); process.exit(1); }
32
+ if (!entry) { console.error(`❌ ${arg} not found`); process.exit(1); }
33
+ const { dialect } = load(entry);
34
+ console.log(`✅ loaded: ${dialect.name} - ${Object.keys(dialect.keywords).length} words`);
package/package.json CHANGED
@@ -1,10 +1,17 @@
1
1
  {
2
2
  "name": "bayda-maghreb",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Bayda Maghreb - Tunisian, Algerian, Moroccan, Libyan, Mauritanian Arabic and Franco transliteration",
5
5
  "type": "module",
6
6
  "main": "index.js",
7
- "keywords": ["arabic", "darija", "tunisian", "maghreb", "transliteration", "franco"],
7
+ "keywords": [
8
+ "arabic",
9
+ "darija",
10
+ "tunisian",
11
+ "maghreb",
12
+ "transliteration",
13
+ "franco"
14
+ ],
8
15
  "author": "ajilis",
9
16
  "license": "MIT",
10
17
  "scripts": {