
Security News
Deno 2.4 Brings Back deno bundle, Improves Dependency Management and Observability
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.
detect-file-encoding-and-language
Advanced tools
Charset Detector - Detect the encoding and language of text files - Use it in the browser, with Node.js, or via CLI
Determine the encoding and language of text files!
For reliable encoding and language detection, use files containing at least 500 words of coherent text. Smaller inputs can work as well but the results might be less accurate and in some cases incorrect.
Feel free to test the functionality of this NPM package here. Upload your own files and see if the encoding and language are detected correctly!
npm install detect-file-encoding-and-language
// index.html
<body>
<input type="file" id="my-input-field" />
<script src="https://unpkg.com/detect-file-encoding-and-language/umd/language-encoding.min.js"></script>
<script src="app.js"></script>
</body>
// app.js
document.getElementById("my-input-field").addEventListener("change", (e) => {
const file = e.target.files[0];
languageEncoding(file).then((fileInfo) => console.log(fileInfo));
// Possible result: { language: english, encoding: UTF-8, confidence: { encoding: 1, language: 1 } }
});
If you don't want to use a CDN feel free to download the source code!
// App.js
import languageEncoding from "detect-file-encoding-and-language";
export default function App() {
function inputHandler(e) {
const file = e.target.files[0];
languageEncoding(file).then((fileInfo) => console.log(fileInfo));
// Possible result: { language: english, encoding: UTF-8, confidence: { encoding: 1, language: 1 } }
}
return <input type="file" onChange={inputHandler} />;
}
// server.js
const languageEncoding = require("detect-file-encoding-and-language");
const pathToFile = "/home/username/documents/my-text-file.txt";
languageEncoding(pathToFile).then((fileInfo) => console.log(fileInfo));
// Possible result: { language: japanese, encoding: Shift-JIS, confidence: { encoding: 0.94, language: 0.94 } }
// server.js
const languageEncoding = require("detect-file-encoding-and-language");
const content = Buffer.from("file content");
languageEncoding(content).then((fileInfo) => console.log(fileInfo));
// Possible result: { language: japanese, encoding: Shift-JIS, confidence: { encoding: 0.94, language: 0.94 } }
# Installation
npm install -g detect-file-encoding-and-language
# Usage
dfeal "/home/username/Documents/subtitle file.srt"
# Possible result: { language: french, encoding: CP1252, confidence: { encoding: 0.99, language: 0.99 } }
Check out this issue page! @davuses posted a very simple code snippet there that converts your buffer into a blob which you can then pass into the function instead of a file!
The confidence score ranges from 0 to 1. It's an object that contains two different confidence scores. The language confidence score and the encoding confidence score. Both confidence scores will be the same if the detected encoding is Unicode. Otherwise the confidence score for the language and the encoding is calculated seperately. It is based on the amount of matches that were found for a particular language and the frequency of those matches. If you want to learn more about how it all works, check out the Wiki entry!
This project is licensed under the MIT License
FAQs
Charset Detector - Detect the encoding and language of text files - Use it in the browser, with Node.js, or via CLI
The npm package detect-file-encoding-and-language receives a total of 46,182 weekly downloads. As such, detect-file-encoding-and-language popularity was classified as popular.
We found that detect-file-encoding-and-language demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.
Security News
CVEForecast.org uses machine learning to project a record-breaking surge in vulnerability disclosures in 2025.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.