Gathering detailed insights and metrics for detect-file-encoding-and-language
Gathering detailed insights and metrics for detect-file-encoding-and-language
An NPM Package to detect the encoding and language of text files
npm install detect-file-encoding-and-language
Typescript
Module System
Node Version
NPM Version
99.1
Supply Chain
100
Quality
76.2
Maintenance
100
Vulnerability
100
License
JavaScript (79.97%)
TypeScript (11.62%)
HTML (8.02%)
CSS (0.39%)
Love this project? Help keep it running — sponsor us today! 🚀
Total Downloads
1,931,908
Last Day
8,376
Last Week
40,310
Last Month
156,252
Last Year
1,273,135
MIT License
45 Stars
184 Commits
6 Forks
3 Watchers
1 Branches
5 Contributors
Updated on Feb 07, 2025
Minified
Minified + Gzipped
Latest Version
2.4.0
Package Id
detect-file-encoding-and-language@2.4.0
Unpacked Size
49.50 kB
Size
12.33 kB
File Count
15
NPM Version
9.6.7
Node Version
20.3.1
Published on
Jun 30, 2023
Cumulative downloads
Total Downloads
Last Day
33.9%
8,376
Compared to previous day
Last Week
14.1%
40,310
Compared to previous week
Last Month
42.4%
156,252
Compared to previous month
Last Year
178.6%
1,273,135
Compared to previous year
No dependencies detected.
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
1// index.html 2<body> 3 <input type="file" id="my-input-field" /> 4 <script src="https://unpkg.com/detect-file-encoding-and-language/umd/language-encoding.min.js"></script> 5 <script src="app.js"></script> 6</body> 7 8// app.js 9document.getElementById("my-input-field").addEventListener("change", (e) => { 10 const file = e.target.files[0]; 11 languageEncoding(file).then((fileInfo) => console.log(fileInfo)); 12 // Possible result: { language: english, encoding: UTF-8, confidence: { encoding: 1, language: 1 } } 13});
If you don't want to use a CDN feel free to download the source code!
1// App.js 2import languageEncoding from "detect-file-encoding-and-language"; 3export default function App() { 4 function inputHandler(e) { 5 const file = e.target.files[0]; 6 languageEncoding(file).then((fileInfo) => console.log(fileInfo)); 7 // Possible result: { language: english, encoding: UTF-8, confidence: { encoding: 1, language: 1 } } 8 } 9 return <input type="file" onChange={inputHandler} />; 10}
1// server.js 2const languageEncoding = require("detect-file-encoding-and-language"); 3const pathToFile = "/home/username/documents/my-text-file.txt"; 4languageEncoding(pathToFile).then((fileInfo) => console.log(fileInfo)); 5// Possible result: { language: japanese, encoding: Shift-JIS, confidence: { encoding: 0.94, language: 0.94 } }
1// server.js 2const languageEncoding = require("detect-file-encoding-and-language"); 3const content = Buffer.from("file content"); 4languageEncoding(content).then((fileInfo) => console.log(fileInfo)); 5// Possible result: { language: japanese, encoding: Shift-JIS, confidence: { encoding: 0.94, language: 0.94 } }
1# Installation 2npm install -g detect-file-encoding-and-language 3 4# Usage 5dfeal "/home/username/Documents/subtitle file.srt" 6# 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
No vulnerabilities found.
No security vulnerabilities found.