{"id":13528338,"url":"https://github.com/runk/node-chardet","last_synced_at":"2025-05-14T01:03:14.944Z","repository":{"id":44828648,"uuid":"9749948","full_name":"runk/node-chardet","owner":"runk","description":"Character encoding detection tool for NodeJS","archived":false,"fork":false,"pushed_at":"2025-02-24T22:26:27.000Z","size":1949,"stargazers_count":291,"open_issues_count":2,"forks_count":73,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-05-04T15:39:11.638Z","etag":null,"topics":["hacktoberfest"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/runk.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,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2013-04-29T14:29:28.000Z","updated_at":"2025-05-02T07:30:26.000Z","dependencies_parsed_at":"2024-05-01T02:43:30.240Z","dependency_job_id":"5283645a-558c-47c0-a693-455276716ec3","html_url":"https://github.com/runk/node-chardet","commit_stats":{"total_commits":144,"total_committers":16,"mean_commits":9.0,"dds":0.5416666666666667,"last_synced_commit":"2472f2837109bedc23da53464939f77d51f492b3"},"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/runk%2Fnode-chardet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/runk%2Fnode-chardet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/runk%2Fnode-chardet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/runk%2Fnode-chardet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/runk","download_url":"https://codeload.github.com/runk/node-chardet/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253042655,"owners_count":21845187,"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":["hacktoberfest"],"created_at":"2024-08-01T06:02:26.486Z","updated_at":"2025-05-14T01:03:14.912Z","avatar_url":"https://github.com/runk.png","language":"TypeScript","funding_links":[],"categories":["TypeScript","hacktoberfest"],"sub_categories":[],"readme":"# chardet\n\n_Chardet_ is a character detection module written in pure JavaScript (TypeScript). Module uses occurrence analysis to determine the most probable encoding.\n\n- Packed size is only **22 KB**\n- Works in all environments: Node / Browser / Native\n- Works on all platforms: Linux / Mac / Windows\n- No dependencies\n- No native code / bindings\n- 100% written in TypeScript\n- Extensive code coverage\n\n## Installation\n\n```\nnpm i chardet\n```\n\n## Usage\n\nTo return the encoding with the highest confidence:\n\n```javascript\nimport chardet from 'chardet';\n\nconst encoding = chardet.detect(Buffer.from('hello there!'));\n// or\nconst encoding = await chardet.detectFile('/path/to/file');\n// or\nconst encoding = chardet.detectFileSync('/path/to/file');\n```\n\nTo return the full list of possible encodings use `analyse` method.\n\n```javascript\nimport chardet from 'chardet';\nchardet.analyse(Buffer.from('hello there!'));\n```\n\nReturned value is an array of objects sorted by confidence value in descending order\n\n```javascript\n[\n  { confidence: 90, name: 'UTF-8' },\n  { confidence: 20, name: 'windows-1252', lang: 'fr' },\n];\n```\n\nIn browser, you can use [Uint8Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array) instead of the `Buffer`:\n\n```javascript\nimport chardet from 'chardet';\nchardet.analyse(new Uint8Array([0x68, 0x65, 0x6c, 0x6c, 0x6f]));\n```\n\n## Working with large data sets\n\nSometimes, when data set is huge and you want to optimize performance (with a trade off of less accuracy),\nyou can sample only the first N bytes of the buffer:\n\n```javascript\nconst encoding = await chardet.detectFile('/path/to/file', { sampleSize: 32 });\n```\n\nYou can also specify where to begin reading from in the buffer:\n\n```javascript\nconst encoding = await chardet.detectFile('/path/to/file', {\n  sampleSize: 32,\n  offset: 128,\n});\n```\n\n## Working with strings\n\nIn both Node.js and browsers, all strings in memory are represented in UTF-16 encoding. This is a fundamental aspect of the JavaScript language specification. Therefore, you cannot use plain strings directly as input for `chardet.analyse()` or `chardet.detect()`. Instead, you need the original string data in the form of a Buffer or Uint8Array.\n\nIn other words, if you receive a piece of data over the network and want to detect its encoding, use the original data payload, not its string representation. By the time you convert data to a string, it will be in UTF-16 encoding.\n\nNote on [TextEncoder](https://developer.mozilla.org/en-US/docs/Web/API/TextEncoder/TextEncoder): By default, it returns a UTF-8 encoded buffer, which means the buffer will not be in the original encoding of the string.\n\n## Supported Encodings:\n\n- UTF-8\n- UTF-16 LE\n- UTF-16 BE\n- UTF-32 LE\n- UTF-32 BE\n- ISO-2022-JP\n- ISO-2022-KR\n- ISO-2022-CN\n- Shift_JIS\n- Big5\n- EUC-JP\n- EUC-KR\n- GB18030\n- ISO-8859-1\n- ISO-8859-2\n- ISO-8859-5\n- ISO-8859-6\n- ISO-8859-7\n- ISO-8859-8\n- ISO-8859-9\n- windows-1250\n- windows-1251\n- windows-1252\n- windows-1253\n- windows-1254\n- windows-1255\n- windows-1256\n- KOI8-R\n\nCurrently only these encodings are supported.\n\n## TypeScript?\n\nYes. Type definitions are included.\n\n### References\n\n- ICU project http://site.icu-project.org/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frunk%2Fnode-chardet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frunk%2Fnode-chardet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frunk%2Fnode-chardet/lists"}