{"id":13895235,"url":"https://github.com/gignupg/Detect-File-Encoding-And-Language","last_synced_at":"2025-07-17T10:33:17.398Z","repository":{"id":40252484,"uuid":"346655143","full_name":"gignupg/Detect-File-Encoding-And-Language","owner":"gignupg","description":"An NPM Package to detect the encoding and language of text files","archived":false,"fork":false,"pushed_at":"2023-11-23T21:18:01.000Z","size":1976,"stargazers_count":40,"open_issues_count":3,"forks_count":6,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-04-24T19:24:12.059Z","etag":null,"topics":["detect-encoding","detect-language","encoding-detection","encoding-detector","file-encoding","file-language","language-detection","language-detector"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gignupg.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2021-03-11T09:57:00.000Z","updated_at":"2024-04-18T07:55:20.000Z","dependencies_parsed_at":"2023-11-23T22:24:24.083Z","dependency_job_id":"1dc8c471-c5c4-4b32-9ab1-8751124d518e","html_url":"https://github.com/gignupg/Detect-File-Encoding-And-Language","commit_stats":{"total_commits":174,"total_committers":7,"mean_commits":"24.857142857142858","dds":0.5287356321839081,"last_synced_commit":"31a2d19943a30995291a547bec0069a2a10d2718"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gignupg%2FDetect-File-Encoding-And-Language","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gignupg%2FDetect-File-Encoding-And-Language/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gignupg%2FDetect-File-Encoding-And-Language/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gignupg%2FDetect-File-Encoding-And-Language/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gignupg","download_url":"https://codeload.github.com/gignupg/Detect-File-Encoding-And-Language/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226255373,"owners_count":17595859,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["detect-encoding","detect-language","encoding-detection","encoding-detector","file-encoding","file-language","language-detection","language-detector"],"created_at":"2024-08-06T18:02:05.153Z","updated_at":"2024-11-25T00:31:17.499Z","avatar_url":"https://github.com/gignupg.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# Detect-File-Encoding-And-Language\n\n![npm](https://img.shields.io/npm/dm/detect-file-encoding-and-language)\n![npm](https://img.shields.io/npm/v/detect-file-encoding-and-language)\n![npm bundle size](https://img.shields.io/bundlephobia/min/detect-file-encoding-and-language)\n\n[![NPM stats](https://nodei.co/npm/detect-file-encoding-and-language.svg?downloadRank=true\u0026downloads=true)](https://www.npmjs.org/package/detect-file-encoding-and-language)\n\n## Functionality\n\nDetermine the encoding and language of text files!\n\n- Detects 40 languages as well as the appropriate encoding\n- Available as CLI, in Node.js and in the browser\n- Supports .txt, .srt, .sub, .html, .csv, .tsv\n- Works best with large inputs\n- Completely free, no API key required\n\nFor 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.\n\n## Live Demo\n\nFeel free to test the functionality of this NPM package [here](https://detect-file-encoding-and-language-live-demo.netlify.app/). Upload your own files and see if the encoding and language are detected correctly!\n\n## Installation\n\n```\nnpm install detect-file-encoding-and-language\n```\n\n## Usage\n\n### Via CDN\n\n```js\n// index.html\n\u003cbody\u003e\n  \u003cinput type=\"file\" id=\"my-input-field\" /\u003e\n  \u003cscript src=\"https://unpkg.com/detect-file-encoding-and-language/umd/language-encoding.min.js\"\u003e\u003c/script\u003e\n  \u003cscript src=\"app.js\"\u003e\u003c/script\u003e\n\u003c/body\u003e\n\n// app.js\ndocument.getElementById(\"my-input-field\").addEventListener(\"change\", (e) =\u003e {\n  const file = e.target.files[0];\n  languageEncoding(file).then((fileInfo) =\u003e console.log(fileInfo));\n  // Possible result: { language: english, encoding: UTF-8, confidence: { encoding: 1, language: 1 } }\n});\n```\n\nIf you don't want to use a CDN feel free to [download the source code](https://github.com/gignupg/Detect-File-Encoding-and-Language/wiki/Downloading-the-Source-Code)!\n\n### In React\n\n```js\n// App.js\nimport languageEncoding from \"detect-file-encoding-and-language\";\nexport default function App() {\n  function inputHandler(e) {\n    const file = e.target.files[0];\n    languageEncoding(file).then((fileInfo) =\u003e console.log(fileInfo));\n    // Possible result: { language: english, encoding: UTF-8, confidence: { encoding: 1, language: 1 } }\n  }\n  return \u003cinput type=\"file\" onChange={inputHandler} /\u003e;\n}\n```\n\n### In Node\n#### File\n\n```js\n// server.js\nconst languageEncoding = require(\"detect-file-encoding-and-language\");\nconst pathToFile = \"/home/username/documents/my-text-file.txt\";\nlanguageEncoding(pathToFile).then((fileInfo) =\u003e console.log(fileInfo));\n// Possible result: { language: japanese, encoding: Shift-JIS, confidence: { encoding: 0.94, language: 0.94 } }\n```\n\n#### Buffer\n\n```js\n// server.js\nconst languageEncoding = require(\"detect-file-encoding-and-language\");\nconst content = Buffer.from(\"file content\");\nlanguageEncoding(content).then((fileInfo) =\u003e console.log(fileInfo));\n// Possible result: { language: japanese, encoding: Shift-JIS, confidence: { encoding: 0.94, language: 0.94 } }\n```\n\n### Via CLI\n\n```bash\n# Installation\nnpm install -g detect-file-encoding-and-language\n\n# Usage\ndfeal \"/home/username/Documents/subtitle file.srt\"\n# Possible result: { language: french, encoding: CP1252, confidence: { encoding: 0.99, language: 0.99 } }\n```\n\n### Using a buffer (browser)\nCheck out [this issue page](https://github.com/gignupg/Detect-File-Encoding-And-Language/issues/3#issuecomment-1476074963)! @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!\n\n## Supported Languages\n\n- Polish\n- Czech\n- Hungarian\n- Romanian\n- Slovak\n- Slovenian\n- Albanian\n- Russian\n- Ukrainian\n- Bulgarian\n- English\n- French\n- Portuguese\n- Spanish\n- German\n- Italian\n- Danish\n- Norwegian\n- Swedish\n- Dutch\n- Finnish\n- Serbo-Croatian\n- Estonian\n- Icelandic\n- Malay-Indonesian\n- Greek\n- Turkish\n- Hebrew\n- Arabic\n- Farsi-Persian\n- Lithuanian\n- Chinese-Simplified\n- Chinese-Traditional\n- Japanese\n- Korean\n- Thai\n- Bengali\n- Hindi\n- Urdu\n- Vietnamese\n\n## Used Encodings\n\n- UTF-8\n- UTF-16LE\n- UTF-16BE\n- UTF-32LE\n- UTF-32BE\n- UTF-7\n- UTF-1\n- UTF-EBCDIC\n- SCSU\n- BOCU-1\n- CP1250\n- CP1251\n- CP1252\n- CP1253\n- CP1254\n- CP1255\n- CP1256\n- CP1257\n- GB18030\n- BIG5\n- Shift-JIS\n- EUC-KR\n- TIS-620\n\n## Confidence Score\n\nThe 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](https://github.com/gignupg/Detect-File-Encoding-and-Language/wiki)!\n\n## License\n\nThis project is licensed under the MIT License\n\n![License](https://img.shields.io/badge/License-MIT-yellowgreen)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgignupg%2FDetect-File-Encoding-And-Language","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgignupg%2FDetect-File-Encoding-And-Language","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgignupg%2FDetect-File-Encoding-And-Language/lists"}