{"id":22281771,"url":"https://github.com/node-modules/charset","last_synced_at":"2025-04-03T02:09:54.053Z","repository":{"id":4965526,"uuid":"6123158","full_name":"node-modules/charset","owner":"node-modules","description":"Get the content charset from header and html content-type.","archived":false,"fork":false,"pushed_at":"2017-09-07T03:00:24.000Z","size":116,"stargazers_count":34,"open_issues_count":3,"forks_count":10,"subscribers_count":13,"default_branch":"master","last_synced_at":"2025-03-24T08:18:40.862Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"redhat-cip/puppet-ceph","license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/node-modules.png","metadata":{"files":{"readme":"README.md","changelog":"History.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-10-08T11:02:40.000Z","updated_at":"2023-04-30T09:25:56.000Z","dependencies_parsed_at":"2022-09-06T11:11:47.139Z","dependency_job_id":null,"html_url":"https://github.com/node-modules/charset","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/node-modules%2Fcharset","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/node-modules%2Fcharset/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/node-modules%2Fcharset/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/node-modules%2Fcharset/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/node-modules","download_url":"https://codeload.github.com/node-modules/charset/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246922247,"owners_count":20855345,"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":[],"created_at":"2024-12-03T16:21:48.743Z","updated_at":"2025-04-03T02:09:54.032Z","avatar_url":"https://github.com/node-modules.png","language":"JavaScript","readme":"charset\n=======\n\n[![NPM version][npm-image]][npm-url]\n[![build status][travis-image]][travis-url]\n[![Test coverage][codecov-image]][codecov-url]\n[![David deps][david-image]][david-url]\n[![npm download][download-image]][download-url]\n\n[npm-image]: https://img.shields.io/npm/v/charset.svg?style=flat-square\n[npm-url]: https://npmjs.org/package/charset\n[travis-image]: https://img.shields.io/travis/node-modules/charset.svg?style=flat-square\n[travis-url]: https://travis-ci.org/node-modules/charset\n[codecov-image]: https://codecov.io/gh/node-modules/charset/branch/master/graph/badge.svg\n[codecov-url]: https://codecov.io/gh/node-modules/charset\n[david-image]: https://img.shields.io/david/node-modules/charset.svg?style=flat-square\n[david-url]: https://david-dm.org/node-modules/charset\n[download-image]: https://img.shields.io/npm/dm/charset.svg?style=flat-square\n[download-url]: https://npmjs.org/package/charset\n\n![logo](https://raw.github.com/node-modules/charset/master/logo.png)\n\nGet the content charset from header and html content-type.\n\n## Install\n\n```bash\n$ npm install charset --save\n```\n\n## Usage\n\n### Detect charset from http client response and content\n\n```js\nvar charset = require('charset');\nvar http = require('http');\n\nhttp.get('http://nodejs.org', function (res) {\n  res.on('data', function (chunk) {\n    console.log(charset(res.headers, chunk));\n    // or `console.log(charset(res, chunk));`\n    res.destroy();\n  });\n});\n```\n\nStdout will should log: `utf8` .\n\n### Detect from String\n\n```js\ncharset(res.headers['content-type']);\n```\n\n### Detect combine with [jschardet]\n\nAs you know, `charset` only detect from http response headers and html content-type meta tag.\nYou can combine with [jschardet] to help you detect the finally charset.\n\nThis example codes come from [stackoverflow#12326688](http://stackoverflow.com/a/18712021/2496088):\n\n```js\nvar request = require('request');\nvar charset = require('charset');\nvar jschardet = require('jschardet');\n\nrequest({\n  url: 'http://www.example.com',\n  encoding: null\n}, function (err, res, body) {\n  if (err) {\n    throw err;\n  }\n  enc = charset(res.headers, body);\n  enc = enc || jschardet.detect(body).encoding.toLowerCase();\n  console.log(enc);\n});\n```\n\n## License\n\n[MIT](LICENSE.txt)\n\n[jschardet]: https://github.com/aadsm/jschardet\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnode-modules%2Fcharset","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnode-modules%2Fcharset","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnode-modules%2Fcharset/lists"}