franc-cli: Language Detection CLI
franc-cli is a command-line interface (CLI) tool for detecting the natural language of textual input. It acts as a convenient shell wrapper around the core `franc` library, which supports identifying over 180 languages, including various scripts and dialects. The current stable version for `franc-cli` is 8.0.0, which corresponds to breaking changes introduced in `franc` library versions 6.x.x. The project generally follows the `franc` library's release cadence, with updates often driven by new Unicode versions or improvements in language detection models. Its key differentiator is providing quick, direct command-line access to language detection without requiring programmatic integration, making it suitable for shell scripting, data processing pipelines, and rapid prototyping. It is an ESM-only package, requiring Node.js version 12 or higher for execution.
Common errors
-
Error [ERR_REQUIRE_ESM]: require() of ES Module /path/to/node_modules/franc/index.js from /your/app.js not supported. Instead change the require of index.js in /your/app.js to a dynamic import() which is available in all CommonJS modules.
cause Attempting to `require()` the `franc` library (or any package depending on it internally) in a CommonJS module after `franc` became ESM-only.fixMigrate your project or the specific file to use ES module syntax (`import { franc } from 'franc'`) and ensure your project is configured for ESM (e.g., `"type": "module"` in `package.json`). -
TypeError: franc.all is not a function
cause Attempting to call `franc.all()` from the `franc` library after it was renamed to `francAll()` in v6.fixUpdate your import and usage to `import { francAll } from 'franc'` and call `francAll()`. -
command not found: franc-cli
cause `franc-cli` was not installed globally or is not in your system's PATH.fixInstall the package globally using `npm install -g franc-cli` or ensure that the directory containing the `franc-cli` executable is included in your system's PATH environment variable.
Warnings
- breaking The `franc` library, on which `franc-cli` is based, transitioned to an ESM-only package in version 6.0.0. Consequently, `franc-cli@8.0.0` and newer are also ESM-only. This means `require()` statements are no longer supported, and Node.js 12+ is required.
- breaking The `franc` library's `franc.all()` method was renamed to `francAll()` in version 6.0.0 for better ESM compatibility and adherence to naming conventions.
- gotcha `franc-cli` is a command-line interface tool. It is not designed to be imported directly into JavaScript/TypeScript code as a library. For programmatic language detection, you should install and use the `franc` library package.
- gotcha The version numbers of `franc-cli` do not directly correlate with the `franc` library versions. For example, `franc-cli@8.0.0` is built upon `franc@6.x.x`. Always consult the monorepo's changelog for specific version dependencies and breaking changes affecting the underlying library.
Install
-
npm install franc-cli -
yarn add franc-cli -
pnpm add franc-cli
Imports
- franc
import { franc } from 'franc-cli'import { franc } from 'franc' - francAll
import { franc.all } from 'franc'import { francAll } from 'franc' - CommonJS require
const franc = require('franc')N/A
Quickstart
import { spawn } from 'child_process';
const textToAnalyze = "Alle menslike wesens word vry en gelyk in waardigheid en regte gebore.";
const child = spawn('franc-cli', [textToAnalyze]);
let output = '';
child.stdout.on('data', (data) => {
output += data.toString();
});
child.stderr.on('data', (data) => {
console.error(`stderr: ${data}`);
});
child.on('close', (code) => {
if (code === 0) {
console.log(`Detected language: ${output.trim()}`);
} else {
console.error(`franc-cli exited with code ${code}`);
}
});