Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5ace01f
commit 3d5d2c7
Showing
8 changed files
with
163 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# codes | ||
|
||
Node.js iconv bindings - Streamable, fast and lightweight | ||
|
||
## Installing with [npm](http://npmjs.org/) | ||
|
||
npm install codes | ||
|
||
## Usage | ||
|
||
Encode from one character encoding to another: | ||
|
||
var assert = require('assert'); | ||
var codes = require('../index'); | ||
|
||
// convert from UTF-8 to ISO-8859-1 | ||
var str = 'É isso ai. Testando acentuação: áéíóú...'; | ||
var buffer = codes.encode(str, 'ISO-8859-1//TRANSLIT'); | ||
var str2 = codes.decode(buffer, 'ISO-8859-1'); | ||
assert.equal(str, str2); | ||
|
||
// stream from LATIN1 to UTF-8 | ||
var cs = codes.createStream('UTF-8', 'LATIN1'); | ||
var str4 = ''; | ||
cs.on('data', function (data) { | ||
var str3 = data.toString(); | ||
console.log(str3); | ||
str4 += str3; | ||
}); | ||
cs.on('end', function () { | ||
assert.equal(str4, str); | ||
console.log(str4); | ||
}); | ||
cs.on('error', function (error) { | ||
console.log(error); | ||
}); | ||
cs.write(buffer.slice(0,1)); | ||
cs.write(buffer.slice(1,8)); | ||
cs.write(buffer.slice(8,16)); | ||
cs.write(buffer.slice(16,24)); | ||
cs.write(buffer.slice(24, 28)); | ||
cs.write(buffer.slice(28, 32)); | ||
cs.write(buffer.slice(32)); | ||
cs.end(); | ||
|
||
// convert from UTF-8 to ASCII | ||
var str = 'aéióuçÁEÍOÚC'; | ||
var ascii = codes.convert(str, 'ASCII//TRANSLIT', 'UTF-8'); | ||
console.log(str + ' => ' + ascii.toString()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
var assert = require('assert'); | ||
var codes = require('../index'); | ||
|
||
// convert from UTF-8 to ISO-8859-1 | ||
var str = 'É isso ai. Testando acentuação: áéíóú...'; | ||
var buffer = codes.encode(str, 'ISO-8859-1//TRANSLIT'); | ||
var str2 = codes.decode(buffer, 'ISO-8859-1'); | ||
assert.equal(str, str2); | ||
|
||
// stream from LATIN1 to UTF-8 | ||
var cs = codes.createStream('UTF-8', 'LATIN1'); | ||
var str4 = ''; | ||
cs.on('data', function (data) { | ||
var str3 = data.toString(); | ||
console.log(str3); | ||
str4 += str3; | ||
}); | ||
cs.on('end', function () { | ||
assert.equal(str4, str); | ||
console.log(str4); | ||
}); | ||
cs.on('error', function (error) { | ||
console.log(error); | ||
}); | ||
cs.write(buffer.slice(0,1)); | ||
cs.write(buffer.slice(1,8)); | ||
cs.write(buffer.slice(8,16)); | ||
cs.write(buffer.slice(16,24)); | ||
cs.write(buffer.slice(24, 28)); | ||
cs.write(buffer.slice(28, 32)); | ||
cs.write(buffer.slice(32)); | ||
cs.end(); | ||
|
||
// convert from UTF-8 to ASCII | ||
var str = 'aéióuçÁEÍOÚC'; | ||
var ascii = codes.convert(str, 'ASCII//TRANSLIT', 'UTF-8'); | ||
console.log(str + ' => ' + ascii.toString()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.