Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

to-utf-8

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

to-utf-8 - npm Package Compare versions

Comparing version 1.0.1 to 1.1.0

11

cli.js
#!/usr/bin/env node
var argv = require('minimist')(process.argv.slice(2))
var opts = require('minimist')(process.argv.slice(2))
if(opts.h || opts.help) {
console.error('usage: to-utf-8 [--enc <soruce encoding>] [--conf <minimum confidence>]')
process.exit()
}
opts.encoding = opts.encoding || opts.enc || opts.e
opts.confidence = Number(opts.confidence || opts.conf || opts.c)
process.stdin
.pipe(require('./')(argv.encoding || argv.enc || argv.e))
.pipe(require('./')(opts))
.pipe(process.stdout)

10

index.js

@@ -19,3 +19,7 @@ var detect = require('charset-detector')

function toutf8 (encoding) {
function toutf8 (opts) {
if(!opts) opts = {}
if(typeof encoding == 'string') opts = { encoding: opts }
var conf = opts.confidence || 0
var encoding = opts.encoding
// encoding given

@@ -28,3 +32,5 @@ if(encoding) return convertFrom(encoding)

var matches = detect(data)
var encoding = matches.length > 0 ? matches[0].charsetName : 'utf8'
var encoding = matches.length > 0 && matches[0].confidence > conf
? matches[0].charsetName
: 'utf8'
encoding = getSupportedEncoding(encoding)

@@ -31,0 +37,0 @@ swap(null, convertFrom(encoding))

{
"name": "to-utf-8",
"version": "1.0.1",
"version": "1.1.0",
"description": "Detect input encoding and convert to utf-8 if needed",

@@ -10,3 +10,4 @@ "main": "index.js",

"scripts": {
"test": "node test.js"
"test": "node test.js",
"test-cli": "./cli.js < node_modules/charset-detector/tests/fixtures/utf-16le.txt"
},

@@ -13,0 +14,0 @@ "repository": {

@@ -28,2 +28,6 @@ # to-utf-8

You can also pass an options object instead with the following keys:
* `confidence` Minimum confidence for the detected source encoding. If not reached assume `utf-8`
* `encoding` Same as passing a string directly. Use the given encoding instead of detecting it.
## CLI

@@ -30,0 +34,0 @@

@@ -28,3 +28,3 @@ var utf8 = require('./')

readstream
.pipe(utf8())
.pipe(utf8({confidence: 20}))
.pipe(process.stdout)

@@ -31,0 +31,0 @@ }

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