Skip to content

Commit

Permalink
add combine example with jschardet.
Browse files Browse the repository at this point in the history
Fixes #5
  • Loading branch information
fengmk2 committed Jan 4, 2015
1 parent 05d4b07 commit c2f94ef
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 23 deletions.
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
This software is licensed under the MIT License.

Copyright (C) 2012 - 2014 fengmk2 <fengmk2@gmail.com>
Copyright (C) 2012 - 2015 fengmk2 <fengmk2@gmail.com>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
67 changes: 45 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)

Expand Down Expand Up @@ -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 &lt;fengmk2@gmail.com&gt;
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

0 comments on commit c2f94ef

Please # to comment.