Socket
Socket
Sign inDemoInstall

a2u

Package Overview
Dependencies
0
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    a2u

Convert ansi buffer to character(ucs2 encodings), or convert character to ansi encodings in NodeJs.


Version published
Maintainers
1
Install size
1.61 MB
Created

Readme

Source

ANSI TO UNICODE

Convert ansi buffer to character(ucs2 encodings), or convert character to ansi encodings in NodeJs.

  • Faster than iconv-lite.
  • Don't depend other module.
  • The volume is so small.

Usage

Decode API

var fs = require('fs');
var buf = fs.readFileSync('demo.txt'); //txt's encoding is ANSI, the content is "I(我) love(爱) you(你)."
var a2u = require('a2u');
var str, newBuf;

// Convert from an encoded buffer to js string.
str = a2u.decode(buf);
console.log(str);//I(我) love(爱) you(你).

// If you want convert to buffer with ucs2 encoding, the second arg for method(decode) will be true.
newBuf = a2u.decode(buf, true);

console.log('ANSI buffer : ', buf);
console.log('ucs2 buffer : ', newBuf);
console.log(newBuf.toString('ucs2'));//I(我) love(爱) you(你).

Encode API

var fs = require('fs');
var a2u = require('a2u');
var str = "I(我) love(爱) you(你).";
var buf;

// If string
buf = a2u.encode(str);
console.log('ANSI buffer : ', buf);

// If buffer
buf = a2u.encode( new Buffer(str, 'ucs2') );
console.log('ANSI buffer : ', buf);

// Write to file
fs.writeFileSync('ansi.txt', buf);

Keywords

FAQs

Last updated on 15 Feb 2015

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc