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.1.0 to 1.2.0

6

cli.js

@@ -5,4 +5,4 @@ #!/usr/bin/env node

if(opts.h || opts.help) {
console.error('usage: to-utf-8 [--enc <soruce encoding>] [--conf <minimum confidence>]')
if (opts.h || opts.help) {
console.error('usage: to-utf-8 [--enc <source encoding>] [--conf <minimum confidence>]')
process.exit()

@@ -16,2 +16,2 @@ }

.pipe(require('./')(opts))
.pipe(process.stdout)
.pipe(process.stdout)

@@ -8,10 +8,10 @@ var detect = require('charset-detector')

return splicer([
iconv.decodeStream(encoding),
iconv.encodeStream('utf8')
])
iconv.decodeStream(encoding),
iconv.encodeStream('utf8')
])
}
function getSupportedEncoding (encoding) {
if(encoding === 'ISO-8859-8-I') encoding = 'ISO-8859-8'
if(iconv.encodingExists(encoding)) return encoding
if (encoding === 'ISO-8859-8-I') encoding = 'ISO-8859-8'
if (iconv.encodingExists(encoding)) return encoding
return 'utf8' // default

@@ -21,15 +21,17 @@ }

function toutf8 (opts) {
if(!opts) opts = {}
if(typeof encoding == 'string') opts = { encoding: opts }
if (!opts) opts = {}
if (typeof opts === 'string') opts = { encoding: opts }
var conf = opts.confidence || 0
var newline = opts.newline !== false
var detectSize = opts.detectSize || 65535
var encoding = opts.encoding
// encoding given
if(encoding) return convertFrom(encoding)
if (encoding) return convertFrom(encoding)
// detect encoding first
return peek(function (data, swap) {
if(!Buffer.isBuffer(data)) return swap(new Error('No buffer'))
return peek({newline: newline, maxBuffer: detectSize}, function (data, swap) {
if (!Buffer.isBuffer(data)) return swap(new Error('No buffer'))
var matches = detect(data)
var encoding = matches.length > 0 && matches[0].confidence > conf
? matches[0].charsetName
? matches[0].charsetName
: 'utf8'

@@ -41,2 +43,2 @@ encoding = getSupportedEncoding(encoding)

module.exports = toutf8
module.exports = toutf8
{
"name": "to-utf-8",
"version": "1.1.0",
"version": "1.2.0",
"description": "Detect input encoding and convert to utf-8 if needed",

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

"scripts": {
"pretest": "standard",
"test": "node test.js",

@@ -35,3 +36,6 @@ "test-cli": "./cli.js < node_modules/charset-detector/tests/fixtures/utf-16le.txt"

"stream-splicer": "^1.3.1"
},
"devDependencies": {
"standard": "6.0.8"
}
}

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

[![js-standard-style](https://cdn.rawgit.com/feross/standard/master/badge.svg)](https://github.com/feross/standard)

@@ -32,2 +33,4 @@ ## Usage

* `encoding` Same as passing a string directly. Use the given encoding instead of detecting it.
* `newline` Use input text until newline is reached to detect encoding (default `true`)
* `detectSize` Maximum size from input to detect encoding (default `65535`)

@@ -43,2 +46,2 @@ ## CLI

You can specify the source encoding with the `--enc` flag.
You can specify the source encoding with the `--enc` flag.

@@ -19,5 +19,5 @@ var utf8 = require('./')

function loop() {
function loop () {
var current = testfiles.pop()
if(!current) return
if (!current) return

@@ -32,4 +32,3 @@ var readstream = fs.createReadStream(current)

}
loop()
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