{"_id":"@catexl/parser","name":"@catexl/parser","dist-tags":{"latest":"0.1.0"},"versions":{"0.1.0":{"name":"@catexl/parser","type":"module","version":"0.1.0","description":"JavaScript/TypeScript SDK for CatEx - Category Translation Exchange Format (WASM-powered)","license":"MIT","repository":{"type":"git","url":"git+https://github.com/Nehonix-Team/catex.git","directory":"js-bindings"},"homepage":"https://github.com/Nehonix-Team/catex","bugs":{"url":"https://github.com/Nehonix-Team/catex/issues"},"keywords":["catex","parser","wasm","translation","i18n","categories","typescript","javascript"],"author":{"name":"Nehonix Team"},"collaborators":["Nehonix Team"],"main":"catex_wasm.js","types":"catex_wasm.d.ts","sideEffects":["./snippets/*"],"_id":"@catexl/parser@0.1.0","gitHead":"4c9cbd2da8188f65c3f3ab4f43b7c832f00b2b23","_nodeVersion":"22.19.0","_npmVersion":"10.9.3","dist":{"integrity":"sha512-Y7RKDLH9HmzxB6fsJdtSJkLMZdZ6qjGd1iUII2rpBwSMBsaXoehPWeYcAx54QDHjOMO2tCghwgFiKsFOdsfRbA==","shasum":"253c6673bca12631013d6700bf78e791a2ff61de","tarball":"https://registry.npmjs.org/@catexl/parser/-/parser-0.1.0.tgz","fileCount":6,"unpackedSize":78257,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIAqmyXmW+xVTb9Bvglrf/eyVxwngtZh85ZykHOMsB4hkAiBHT0+YVRtyIutHSAL/l3d1oX6kq6N8FWPdRD/8R3JuBg=="}]},"_npmUser":{"name":"catexl","email":"loankl1728@gmail.com"},"directories":{},"maintainers":[{"name":"catexl","email":"loankl1728@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/parser_0.1.0_1761942591637_0.2428618343598643"},"_hasShrinkwrap":false}},"time":{"created":"2025-10-31T20:29:51.583Z","0.1.0":"2025-10-31T20:29:51.825Z","modified":"2025-10-31T20:29:52.084Z"},"maintainers":[{"name":"catexl","email":"loankl1728@gmail.com"}],"description":"JavaScript/TypeScript SDK for CatEx - Category Translation Exchange Format (WASM-powered)","homepage":"https://github.com/Nehonix-Team/catex","keywords":["catex","parser","wasm","translation","i18n","categories","typescript","javascript"],"repository":{"type":"git","url":"git+https://github.com/Nehonix-Team/catex.git","directory":"js-bindings"},"author":{"name":"Nehonix Team"},"bugs":{"url":"https://github.com/Nehonix-Team/catex/issues"},"license":"MIT","readme":"# @catex/parser\n\nJavaScript/TypeScript SDK for CatEx (Category Translation Exchange Format) - powered by WebAssembly for high performance.\n\n## Installation\n\n```bash\nnpm install @catex/parser\n# or\nyarn add @catex/parser\n# or\nbun add @catex/parser\n```\n\n## Quick Start\n\n```typescript\nimport { parse, validate } from '@catex/parser';\n\nconst content = `\n# Product categories\nphones|téléphone|phone|smartphone\nlaptops|ordinateur|laptop|computer\n`;\n\n// Parse .cat file content\nconst categories = parse(content);\nconsole.log(categories);\n\n// Validate content\nconst errors = validate(content);\nif (errors.length > 0) {\n  console.error('Validation errors:', errors);\n}\n```\n\n## API\n\n### `parse(content: string): Category[]`\n\nParse CatEx file content and return an array of categories.\n\n```typescript\nconst categories = parse(content);\n// Returns: [\n//   { key: 'phones', translations: ['téléphone', 'phone', 'smartphone'] },\n//   { key: 'laptops', translations: ['ordinateur', 'laptop', 'computer'] }\n// ]\n```\n\n### `validate(content: string): ValidationError[]`\n\nValidate CatEx file content and return validation errors.\n\n```typescript\nconst errors = validate(content);\n// Returns: [\n//   { line: 5, message: 'Duplicate key: phones', severity: 'error' }\n// ]\n```\n\n### `format(content: string): string`\n\nFormat CatEx file content (normalize spacing, etc.).\n\n```typescript\nconst formatted = format(content);\n```\n\n## Features\n\n- ✅ **High Performance** - WASM-powered for native-like speed\n- ✅ **Zero Dependencies** - No external dependencies\n- ✅ **TypeScript Support** - Full type definitions included\n- ✅ **Cross-Platform** - Works in Node.js, Bun, Deno, and browsers\n- ✅ **Validation** - Comprehensive error checking\n- ✅ **UTF-8 Support** - Handle international characters\n\n## Supported Runtimes\n\n- **Node.js** 16+ ✅\n- **Bun** ✅\n- **Deno** ✅\n- **Browsers** (modern) ✅\n\n## Usage Examples\n\n### Node.js\n\n```javascript\nconst { parse } = require('@catex/parser');\nconst fs = require('fs');\n\nconst content = fs.readFileSync('categories.cat', 'utf-8');\nconst categories = parse(content);\n\ncategories.forEach(cat => {\n  console.log(`${cat.key}: ${cat.translations.join(', ')}`);\n});\n```\n\n### Browser\n\n```html\n<script type=\"module\">\n  import { parse } from '@catex/parser';\n  \n  const response = await fetch('categories.cat');\n  const content = await response.text();\n  const categories = parse(content);\n  \n  console.log(categories);\n</script>\n```\n\n### TypeScript\n\n```typescript\nimport { parse, Category, ValidationError } from '@catex/parser';\n\ninterface CategoryMap {\n  [key: string]: string[];\n}\n\nfunction loadCategories(content: string): CategoryMap {\n  const categories = parse(content);\n  const map: CategoryMap = {};\n  \n  for (const cat of categories) {\n    map[cat.key] = cat.translations;\n  }\n  \n  return map;\n}\n```\n\n### With Language Mapping\n\n```typescript\nimport { parse } from '@catex/parser';\n\nconst langMap = { 'fr': 0, 'en': 1, 'es': 2 };\n\nfunction getTranslation(key: string, lang: string, categories: any[]): string {\n  const category = categories.find(c => c.key === key);\n  if (!category) return key;\n  \n  const index = langMap[lang] || 0;\n  return category.translations[index] || category.translations[0] || key;\n}\n\nconst categories = parse(content);\nconsole.log(getTranslation('phones', 'fr', categories)); // 'téléphone'\n```\n\n## File Format\n\nCatEx uses a simple pipe-delimited format:\n\n```catex\n# Single-line comment\n\n/***\n * Multi-line comment\n ***/\n\ncategory_key|translation1|translation2|translation3\n```\n\n### Example\n\n```catex\n/***\n * E-commerce Categories\n * Languages: French, English, Spanish\n ***/\n\n# Electronics\nphones|téléphone|phone|teléfono\nlaptops|ordinateur portable|laptop|portátil\n\n# Fashion\nshoes|chaussures|shoes|zapatos\nclothing|vêtements|clothing|ropa\n```\n\n## Validation Rules\n\nThe parser validates:\n\n- ✅ **Key format** - Must be lowercase letters, numbers, `_`, or `-`\n- ✅ **Duplicate keys** - Each key must be unique\n- ✅ **Empty translations** - At least one translation required\n- ✅ **Line format** - Proper pipe-delimited structure\n\n## Performance\n\nPowered by Rust and WebAssembly:\n\n- **Parsing speed**: ~100MB/s\n- **Memory usage**: O(n) linear\n- **Bundle size**: ~56KB (WASM)\n\n## TypeScript Types\n\n```typescript\ninterface Category {\n  key: string;\n  translations: string[];\n  line: number;\n}\n\ninterface ValidationError {\n  line: number;\n  message: string;\n  severity: 'error' | 'warning';\n}\n\nfunction parse(content: string): Category[];\nfunction validate(content: string): ValidationError[];\nfunction format(content: string): string;\n```\n\n## Error Handling\n\n```typescript\ntry {\n  const categories = parse(content);\n  \n  // Validate\n  const errors = validate(content);\n  if (errors.length > 0) {\n    errors.forEach(err => {\n      console.error(`Line ${err.line}: ${err.message}`);\n    });\n  }\n} catch (error) {\n  console.error('Parse error:', error);\n}\n```\n\n## CLI Alternative\n\nFor command-line usage, install the CLI tool:\n\n```bash\ncargo install catex-cli\ncatex validate categories.cat\n```\n\n## VSCode Extension\n\nGet syntax highlighting and validation in VSCode:\n\nSearch for \"CatEx Language Support\" in the VSCode marketplace.\n\n## Links\n\n- [GitHub Repository](https://github.com/Nehonix-Team/catex)\n- [Documentation](https://github.com/Nehonix-Team/catex/tree/main/docs)\n- [Format Specification](https://github.com/Nehonix-Team/catex/blob/main/docs/FORMAT.md)\n- [Report Issues](https://github.com/Nehonix-Team/catex/issues)\n\n## License\n\nMIT License - See [LICENSE](../LICENSE) for details\n\n---\n\n**Made with ❤️ by Nehonix Team**\n","readmeFilename":"README.md","_rev":"1-e9edd51495a35e5d3346be888928116b"}