Product
Introducing Java Support in Socket
We're excited to announce that Socket now supports the Java programming language.
Get the content charset from header and html content-type.
$ npm install charset --save
var charset = require('charset');
var http = require('http');
http.get('http://nodejs.org', function (res) {
res.on('data', function (chunk) {
console.log(charset(res.headers, chunk));
// or `console.log(charset(res, chunk));`
res.destroy();
});
});
Stdout will should log: utf8
.
charset(res.headers['content-type']);
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:
var request = require('request');
var charset = require('charset');
var jschardet = require('jschardet');
request({
url: 'http://www.example.com',
encoding: null
}, function (err, res, body) {
if (err) {
throw err;
}
enc = charset(res.headers, body);
enc = enc || jschardet.detect(body).encoding.toLowerCase();
console.log(enc);
});
FAQs
Get the content charset from header and html content-type.
The npm package charset receives a total of 920,859 weekly downloads. As such, charset popularity was classified as popular.
We found that charset demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Product
We're excited to announce that Socket now supports the Java programming language.
Security News
Socket detected a malicious Python package impersonating a popular browser cookie library to steal passwords, screenshots, webcam images, and Discord tokens.
Security News
Deno 2.0 is now available with enhanced package management, full Node.js and npm compatibility, improved performance, and support for major JavaScript frameworks.