diff --git a/LICENSE.txt b/LICENSE.txt index e890208..ff64ed3 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,6 +1,6 @@ This software is licensed under the MIT License. -Copyright (C) 2012 - 2014 fengmk2 +Copyright (C) 2012 - 2015 fengmk2 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 0737a72..0b7e80e 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,29 @@ charset ======= -[![Build Status](https://secure.travis-ci.org/node-modules/charset.png)](http://travis-ci.org/node-modules/charset) -[![Coverage Status](https://coveralls.io/repos/node-modules/charset/badge.png)](https://coveralls.io/r/node-modules/charset) -[![NPM](https://nodei.co/npm/charset.png?downloads=true&stars=true)](https://nodei.co/npm/charset) +[![NPM version][npm-image]][npm-url] +[![build status][travis-image]][travis-url] +[![Test coverage][coveralls-image]][coveralls-url] +[![Gittip][gittip-image]][gittip-url] +[![David deps][david-image]][david-url] +[![node version][node-image]][node-url] +[![npm download][download-image]][download-url] + +[npm-image]: https://img.shields.io/npm/v/charset.svg?style=flat-square +[npm-url]: https://npmjs.org/package/charset +[travis-image]: https://img.shields.io/travis/node-modules/charset.svg?style=flat-square +[travis-url]: https://travis-ci.org/node-modules/charset +[coveralls-image]: https://img.shields.io/coveralls/node-modules/charset.svg?style=flat-square +[coveralls-url]: https://coveralls.io/r/node-modules/charset?branch=master +[gittip-image]: https://img.shields.io/gittip/fengmk2.svg?style=flat-square +[gittip-url]: https://www.gittip.com/fengmk2/ +[david-image]: https://img.shields.io/david/node-modules/charset.svg?style=flat-square +[david-url]: https://david-dm.org/node-modules/charset +[node-image]: https://img.shields.io/badge/node.js-%3E=_0.10-green.svg?style=flat-square +[node-url]: http://nodejs.org/download/ +[download-image]: https://img.shields.io/npm/dm/charset.svg?style=flat-square +[download-url]: https://npmjs.org/package/charset ![logo](https://raw.github.com/node-modules/charset/master/logo.png) @@ -41,27 +60,31 @@ Stdout will should log: `utf8` . charset(res.headers['content-type']); ``` -## License +### Detect combine with [jschardet] + +As you know, `charset` only detect from http response headers and html content-type meta tag. +You can combine with [jschardet] to help you detect the finally charset. + +This example codes come from [stackoverflow#12326688](http://stackoverflow.com/a/18712021/2496088): + +```js +var charset = require('charset'); +var jschardet = require('jschardet'); -(The MIT License) +request('http://www.example.com', function (err, res, body) { + if (!err) { + throw err; + } -Copyright (c) 2012 - 2014 fengmk2 <fengmk2@gmail.com> + enc = charset(res.headers, body); + enc = enc or jschardet.detect(body).encoding.toLowerCase(); + console.log(enc); +}); +``` + +## License -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -'Software'), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: +MIT -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +[jschardet]: https://github.com/aadsm/jschardet