marc8
Version:
A Node.js module for converting MARC8 encoding to Unicode
51 lines (34 loc) • 1.47 kB
Markdown
[](https://travis-ci.org/jiaola/marc8)
A Node.js module to convert MARC8 encoded string to UTF-8.
npm install marc8
```javascript
var marc8 = require('marc8');
var options = {
normalization: 'NFC',
invalid: 'replace',
replace: '',
expandNCR: false
};
marc8(marc8_string, options);
```
the options parameter is optional. If used, the following options can be set.
* `normalization`: by default return NFC normalized, but set :normalization option to:
"NFC", "NFD", "NFKC", "NFKD", or false. Set to false for higher performance.
* `expandNCR`: By default, escaped unicode 'named character references' in Marc8 will
be translated to actuall UTF8. Eg. "‏". But pass expandNCR: false to disable.
* `invalid`: Bad Marc8 bytes? By default will throw an error message. Set option invalid: "replace"
to instead silently replace bad bytes with a replacement char -- by default Unicode
Replacement Char, but can set option replace to something else include empty string.
* `replace`: used with the option invalid. For example:
`marc8(bad_marc8, {invalid: "replace", replace: "")`
```javascript
var marc8 = require('marc8');
var marc8Str = "Conversa\xF0c\xE4ao \xC1";
var unicodeStr = "Conversação \u2113";
var converted = marc8(marc8Str);
console.log(converted === unicodeStr); // will print true
```