{"_id":"@antistatique/blaspjs","_rev":"2-e48e3fda93bbf80bcdc85fb4e2da5f5a","name":"@antistatique/blaspjs","dist-tags":{"latest":"0.0.2"},"versions":{"0.0.1":{"name":"@antistatique/blaspjs","version":"0.0.1","license":"MIT","_id":"@antistatique/blaspjs@0.0.1","maintainers":[{"name":"antistatique-dev","email":"dev@antistatique.net"},{"name":"yannlugrin","email":"yann.lugrin@antistatique.net"},{"name":"gido","email":"gilles.doge@gmail.com"}],"dist":{"shasum":"66ae80e5e5c17653fa12b9d1f05c97dce0d3fc7e","tarball":"https://registry.npmjs.org/@antistatique/blaspjs/-/blaspjs-0.0.1.tgz","fileCount":5,"integrity":"sha512-BxM5xk7/uYdvSUKSgR7js1kr8zBm+pOn45jFJfxsK/ByrrWpzADqolcL7aZ8wzTIQijHi0+3agKsG+AbWMLBow==","signatures":[{"sig":"MEUCIFXEM3HotvfAa5wjTd/K4XE8wrxIxDNts0AlWp7E3uBDAiEA9zzzyTId5qjB3CE0EtZyyY0HNpmqG2vm8uyXsv4ZulM=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":128191},"main":"./dist/index.js","type":"module","types":"./dist/index.d.ts","gitHead":"a75fb903b2de6cc7cf081b233541655024438495","private":false,"scripts":{"test":"vitest","build":"tsup --config tsup.config.ts","fix:js":"eslint --max-warnings=0 --fix","lint:js":"eslint --max-warnings=0","prepare":"husky && bun run build","test:run":"vitest run","test:coverage":"vitest run --coverage","export-languages":"./scripts/export-languages.sh"},"_npmUser":{"name":"antistatique-dev","email":"dev@antistatique.net"},"_npmVersion":"11.3.0","description":"TypeScript port of Blaspsoft Blasp (v4) — profanity detection, masking, drivers (regex, pattern, phonetic, pipeline), multi-language dictionaries.","directories":{},"lint-staged":{"src/**/*.{js,jsx,ts,tsx}":"eslint --ext .js,.jsx,.ts,.tsx --max-warnings=0"},"_nodeVersion":"24.1.0","dependencies":{"metaphone":"^2.0.1","fastest-levenshtein":"^1.0.16"},"_hasShrinkwrap":false,"devDependencies":{"tsup":"^8.5.1","husky":"^9.1.7","eslint":"^10.1.0","vitest":"^4.1.2","prettier":"^3.8.1","@eslint/js":"^10.0.1","@types/bun":"latest","lint-staged":"^16.4.0","@vitest/coverage-v8":"^4.1.2","eslint-config-prettier":"^10.1.8","eslint-plugin-prettier":"^5.5.5","@typescript-eslint/parser":"^8.58.0","@typescript-eslint/eslint-plugin":"^8.58.0","@trivago/prettier-plugin-sort-imports":"^6.0.2"},"peerDependencies":{"typescript":"^5.0.0"},"_npmOperationalInternal":{"tmp":"tmp/blaspjs_0.0.1_1775142659454_0.37574754532954024","host":"s3://npm-registry-packages-npm-production"}},"0.0.2":{"name":"@antistatique/blaspjs","version":"0.0.2","description":"TypeScript port of Blaspsoft Blasp (v4) — profanity detection, masking, drivers (regex, pattern, phonetic, pipeline), multi-language dictionaries.","type":"module","private":false,"license":"MIT","main":"./dist/index.js","types":"./dist/index.d.ts","scripts":{"build":"tsup --config tsup.config.ts","export-languages":"./scripts/export-languages.sh","bench:check":"npm run build && node ./scripts/bench-check.mjs","test":"vitest","test:coverage":"vitest run --coverage","test:run":"vitest run","prepare":"husky && bun run build","lint:js":"eslint --max-warnings=0","fix:js":"eslint --max-warnings=0 --fix"},"lint-staged":{"src/**/*.{js,jsx,ts,tsx}":"eslint --ext .js,.jsx,.ts,.tsx --max-warnings=0"},"devDependencies":{"@eslint/js":"^10.0.1","@trivago/prettier-plugin-sort-imports":"^6.0.2","@types/bun":"latest","@typescript-eslint/eslint-plugin":"^8.58.0","@typescript-eslint/parser":"^8.58.0","@vitest/coverage-v8":"^4.1.2","eslint":"^10.1.0","eslint-config-prettier":"^10.1.8","eslint-plugin-prettier":"^5.5.5","husky":"^9.1.7","lint-staged":"^16.4.0","prettier":"^3.8.1","tsup":"^8.5.1","vitest":"^4.1.2"},"peerDependencies":{"typescript":"^5.0.0"},"dependencies":{"fastest-levenshtein":"^1.0.16","metaphone":"^2.0.1"},"_id":"@antistatique/blaspjs@0.0.2","gitHead":"eb70563c691daaa3a9cea81b579edb7b2b18de44","_nodeVersion":"24.1.0","_npmVersion":"11.3.0","dist":{"integrity":"sha512-nN8L1e7K82u0In0wZ567Iyttv8xQF7ZnUniUAtqbtsQ68Gy7pRZLcjIEZsjKkvUZNgFomBmH1DuMVH6cE9kwLw==","shasum":"6238e0c062190a4efceb8707c33d759b84c97337","tarball":"https://registry.npmjs.org/@antistatique/blaspjs/-/blaspjs-0.0.2.tgz","fileCount":5,"unpackedSize":130368,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIBBDq5Wrji12T4vvYyhhU2mOQ9vQ6lzVnyJGySEbTiazAiEAia5Yd4k8SGDkGPagv96x/16BVHoIbvGVHvuv5UZMfXg="}]},"_npmUser":{"name":"antistatique-dev","email":"dev@antistatique.net"},"directories":{},"maintainers":[{"name":"antistatique-dev","email":"dev@antistatique.net"},{"name":"yannlugrin","email":"yann.lugrin@antistatique.net"},{"name":"gido","email":"gilles.doge@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/blaspjs_0.0.2_1776152678766_0.039903345758224296"},"_hasShrinkwrap":false}},"time":{"created":"2026-04-02T15:10:59.314Z","modified":"2026-04-14T07:44:39.081Z","0.0.1":"2026-04-02T15:10:59.597Z","0.0.2":"2026-04-14T07:44:38.900Z"},"license":"MIT","description":"TypeScript port of Blaspsoft Blasp (v4) — profanity detection, masking, drivers (regex, pattern, phonetic, pipeline), multi-language dictionaries.","maintainers":[{"name":"antistatique-dev","email":"dev@antistatique.net"},{"name":"yannlugrin","email":"yann.lugrin@antistatique.net"},{"name":"gido","email":"gilles.doge@gmail.com"}],"readme":"# @antistatique/blaspjs\n\nTypeScript / JavaScript library that ports the **language-agnostic core** of [Blaspsoft Blasp v4](https://github.com/Blaspsoft/blasp): driver-based profanity detection, severity scoring, masking, and multi-language dictionaries (English, Spanish, German, French). It is intended for Node.js and bundlers (ESM); the build targets modern browsers as well.\n\nBlasp itself is a Laravel package; this project does **not** ship Laravel integration. Use it in Express, Nest, Remix, serverless handlers, or any TS/JS runtime.\n\n## Installation\n\n```bash\nnpm install @antistatique/blaspjs\n# or\nbun add @antistatique/blaspjs\n```\n\nPeer dependency: TypeScript `^5.0` (optional if you consume only JavaScript).\n\n## Quick start\n\n```ts\nimport { Blasp, Severity } from '@antistatique/blaspjs';\n\nconst blasp = new Blasp();\n\nconst result = blasp.check('This is a fucking sentence');\n\nresult.isOffensive(); // true\nresult.clean(); // masked text (e.g. asterisks)\nresult.original(); // unchanged input\nresult.score(); // 0–100\nresult.count(); // number of matches\nresult.uniqueWords(); // unique dictionary bases\nresult.severity(); // highest SeverityLevel in matches, or null\n```\n\nA default instance is also exported as `blasp` (same defaults as `new Blasp()`).\n\n## Fluent API\n\n`Blasp` mirrors the PHP `PendingCheck` surface: chain options, then call `check(text)` or `checkMany(...)`.\n\n### Languages\n\n```ts\nblasp.in('spanish').check(text);\nblasp.in('english', 'french').check(text);\nblasp.inAllLanguages().check(text);\n\nblasp.english().check(text);\nblasp.spanish().check(text);\nblasp.german().check(text);\nblasp.french().check(text);\n```\n\n### Drivers\n\n```ts\nblasp.driver('regex').check(text); // default; obfuscation, substitutions, separators\nblasp.driver('pattern').check(text); // fast word-boundary exact match\nblasp.driver('phonetic').check(text); // metaphone + Levenshtein (English-oriented)\nblasp.driver('pipeline').check(text); // uses config `drivers.pipeline.drivers`\n\nblasp.pipeline('regex', 'phonetic').check(text);\n```\n\n### Modes\n\n```ts\nblasp.lenient().check(text); // forces the `pattern` driver (same as PHP)\nblasp.strict().check(text); // clears lenient mode; included in the result cache key like PHP\n```\n\n### Masking\n\n```ts\nblasp.mask('*').check(text);\nblasp.mask('#').check(text);\nblasp.mask('grawlix').check(text); // !@#$% rotation\nblasp.mask((word, len) => '[CENSORED]').check(text);\n```\n\nCallback masks **disable** result caching (same idea as PHP: closures are not serializable).\n\n### Severity and lists\n\n```ts\nimport { Severity } from '@antistatique/blaspjs';\n\nblasp.withSeverity(Severity.High).check(text); // drops milder matches before masking\n\nblasp.allow('damn', 'hell').check(text);\nblasp.block('customword').check(text);\n```\n\n### Batch\n\n```ts\nblasp.checkMany(['one', 'two']); // Result[]\nblasp.checkMany({ a: 'x', b: 'y' }); // Record<string, Result>\n```\n\n### Custom drivers\n\n```ts\nimport type { Driver } from '@antistatique/blaspjs';\n\nconst myDriver: Driver = {\n  detect(text, dictionary, mask, options) {\n    /* return a Result */\n  },\n};\n\nblasp.extend('my-driver', () => myDriver);\nblasp.driver('my-driver').check(text);\n```\n\n## `Result`\n\n| Method           | Returns              | Description                          |\n| ---------------- | -------------------- | ------------------------------------ |\n| `isOffensive()`  | `boolean`            | Any profanity matched                |\n| `isClean()`      | `boolean`            | No matches                           |\n| `clean()`        | `string`             | Masked text                          |\n| `original()`     | `string`             | Original input                       |\n| `score()`        | `number`             | 0–100 severity score                 |\n| `count()`        | `number`             | Match count                          |\n| `uniqueWords()`  | `string[]`           | Unique base words                    |\n| `severity()`     | `SeverityLevel \\| null` | Strongest severity among matches  |\n| `words()`        | `MatchedWord[]`      | Positions, lengths, severity, etc.   |\n| `toArray()`      | `object`             | JSON-friendly snapshot               |\n| `toJson()`       | `string`             | `JSON.stringify(toArray())`          |\n\nLegacy-style aliases from PHP v3 are available on `Result` (`hasProfanity`, `getCleanString`, …).\n\n`String(result)` / template interpolation uses the clean string (like PHP `Stringable`).\n\n## Configuration\n\nPass a partial config to `new Blasp(partialConfig)`; it is deep-merged with `defaultBlaspConfig` (see [`src/config/defaultConfig.ts`](src/config/defaultConfig.ts) and [`src/config/blasp-defaults.json`](src/config/blasp-defaults.json)).\n\nRelevant keys include:\n\n- `default` — default driver name (`regex`, `pattern`, `phonetic`, `pipeline`)\n- `language` / `default_language`\n- `mask` / `mask_character`\n- `allow`, `block`, `false_positives`, `separators`, `substitutions`\n- `drivers.pipeline.drivers`, `drivers.phonetic.*`\n- `cache.enabled`, `cache.results`, `cache.ttl`\n\nMiddleware / Eloquent / Blade keys exist on the type for parity with PHP config shape; they are **not** used by this library.\n\n## Runtime options\n\n```ts\nimport { Blasp, MemoryCache } from '@antistatique/blaspjs';\n\nconst blasp = new Blasp(undefined, {\n  cache: new MemoryCache(), // or your own CacheAdapter; pass null to disable internal cache\n  onProfanityDetected(result, originalText) {\n    if (result.isOffensive()) {\n      // logging, metrics, etc.\n    }\n  },\n});\n```\n\n`getCache()` returns `null` when `cache.enabled` is false or `runtime.cache === null`.\n\n## Regenerating language data\n\nWord lists and global separator/substitution defaults are vendored as JSON. To refresh from upstream [Blaspsoft/blasp](https://github.com/Blaspsoft/blasp):\n\n```bash\nbun run export-languages\n```\n\nRequires `curl` and `php` on your PATH. This overwrites `src/languages/*.json` and `src/config/blasp-defaults.json`.\n\n## API parity vs PHP Blasp\n\n| Feature | PHP ([Blasp v4](https://github.com/Blaspsoft/blasp)) | @antistatique/blaspjs |\n| ------- | ---------------------------------------------------- | ------- |\n| Drivers: regex, pattern, phonetic, pipeline | Yes | Yes |\n| Fluent `PendingCheck` API | Yes | Yes |\n| `Result` / `MatchedWord`, scoring, masking | Yes | Yes |\n| Multi-language dictionaries + normalizers | Yes | Yes |\n| Allow / block lists, severity filter | Yes | Yes |\n| Result caching (in-memory or custom) | Laravel cache | `MemoryCache` or `CacheAdapter` |\n| Custom drivers (`extend`) | Yes | Yes |\n| Laravel facade, service provider | Yes | No |\n| Middleware, validation rules, Blade | Yes | No |\n| Eloquent `Blaspable`, model events | Yes | No |\n| Artisan commands, `Blasp::fake()` | Yes | No |\n\nFor full behaviour and examples, see the [upstream README](https://github.com/Blaspsoft/blasp/blob/main/README.md).\n\n## Development\n\n```bash\nbun install\nbun run build   # ESM + types in dist/\nbun test        # Vitest\nbun run lint:js\n```\n\n## License\n\nMIT. Profanity dictionaries and algorithmic behaviour are derived from [Blaspsoft/blasp](https://github.com/Blaspsoft/blasp) (MIT). This port is maintained separately and is not an official Blaspsoft package unless they choose to adopt it.\n","readmeFilename":"README.md"}