New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

charset-parser

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

charset-parser

Parse charset string from http header and hmtl meta

  • 0.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Charset Parser

  • Node.js module
  • Parse charset string from http header and html data

Installation

npm install charset-parser --save

Usage

  • Input a string, the charsetParser will find the charset string
// charsetParser(string);
var charset = charsetParser('Content-Type:text/html; charset=utf-8');
  • Input: the content type from http header, binary html content and a default charset
  • If http header has no charset defined, the binary content will parse, if there is also no charset, it returns the default
// charsetParser(header, html, default_charset);
var charset = charsetParser('Content-Type:text/html; charset=utf-8',
                            '<html><head><meta charset=utf-8></head><body></body></html>',
                            'iso-8859-1');

Example

  • A small example with node.js modules 'request' and 'iconv-lite'
var request = require('request');
var iconv = require('iconv-lite');
var charsetParser = require('charset-parser');

iconv.extendNodeEncodings();

request('http://example.com', {encoding: 'binary'}, function(err, res, binary){
  // parse charset
  var charset = charsetParser(res.headers['content-type'], binary, 'iso-8859-1');
  // decode binary with charset
  var html = iconv.decode(binary, charset);
  // TODO: do something with html
}

Test

npm install
npm test

Release History

  • 0.2.0 Add more input parameters
  • 0.1.0 Initial release

License

MIT

Keywords

FAQs

Package last updated on 28 Feb 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc