Socket
Socket
Sign inDemoInstall

gettext-parser

Package Overview
Dependencies
Maintainers
1
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gettext-parser - npm Package Compare versions

Comparing version 0.1.5 to 0.1.6

12

lib/moparser.js

@@ -8,6 +8,7 @@ var encoding = require("encoding"),

* @param {Buffer} buffer Binary MO object
* @param {String} [defaultCharset] Default charset to use
* @return {Object} Translation object
*/
module.exports = function(buffer){
var parser = new Parser(buffer);
module.exports = function(buffer, defaultCharset){
var parser = new Parser(buffer, defaultCharset);
return parser.parse();

@@ -21,4 +22,5 @@ };

* @param {Buffer} fileContents Binary MO object
* @param {String} [defaultCharset] Default charset to use
*/
function Parser(fileContents){
function Parser(fileContents, defaultCharset){

@@ -37,3 +39,3 @@ this._fileContents = fileContents;

this._charset = "iso-8859-1";
this._charset = defaultCharset || "iso-8859-1";

@@ -121,3 +123,3 @@ this._table = {

if((match = headersStr.match(/[; ]charset\s*=\s*([\w\-]+)/i))){
this._charset = this._table.charset = sharedFuncs.formatCharset(match[1]);
this._charset = this._table.charset = sharedFuncs.formatCharset(match[1], this._charset);
}

@@ -124,0 +126,0 @@

@@ -136,2 +136,3 @@ var encoding = require("encoding"),

replace(/\"/g, "\\\"").
replace(/\t/g, "\\t").
replace(/\r/g, "\\r").

@@ -138,0 +139,0 @@ replace(/\n/g, "\\n");

@@ -8,5 +8,6 @@ var encoding = require("encoding"),

* @param {Buffer|String} buffer PO object
* @param {String} [defaultCharset] Default charset to use
* @return {Object} Translation object
*/
module.exports = function(buffer){
module.exports = function(buffer, defaultCharset){
var parser = new Parser(buffer);

@@ -22,6 +23,7 @@ return parser.parse();

* @param {Buffer|String} fileContents PO object
* @param {String} [defaultCharset] Default charset to use
*/
function Parser(fileContents){
function Parser(fileContents, defaultCharset){
this._charset = "iso-8859-1";
this._charset = defaultCharset || "iso-8859-1";

@@ -53,3 +55,3 @@ if(typeof fileContents == "string"){

if((match = headers.match(/[; ]charset\s*=\s*([\w\-]+)(?:[\s;]|\\n)*"\s*$/mi))){
this._charset = sharedFuncs.formatCharset(match[1]);
this._charset = sharedFuncs.formatCharset(match[1], this._charset);
}

@@ -142,10 +144,8 @@

if(escaped){
if(chr == "n"){
node.value += "\n";
}else if(chr == "r"){
node.value += "\r";
}else if(chr == "t"){
node.value += "\t";
}else{
node.value += chr;
switch(chr){
case "t": node.value += "\t"; break;
case "n": node.value += "\n"; break;
case "r": node.value += "\r"; break;
default:
node.value += "\\" + chr;
}

@@ -152,0 +152,0 @@ escaped = false;

@@ -67,3 +67,3 @@

*/
function formatCharset(charset){
function formatCharset(charset, defaultCharset){
return (charset || "iso-8859-1").toString().toLowerCase().

@@ -74,2 +74,3 @@ replace(/^utf[\-_]?(\d+)$/, "utf-$1").

replace(/^(us[\-_]?)?ascii$/, "ascii").
replace(/^CHARSET$/, defaultCharset || "iso-8859-1").
trim();

@@ -76,0 +77,0 @@ }

{
"name": "gettext-parser",
"description": "Parse and compile gettext po and mo files to/from json, nothing more, nothing less",
"version": "0.1.5",
"version": "0.1.6",
"author" : "Andris Reinman",

@@ -6,0 +6,0 @@ "homepage": "http://github.com/andris9/gettext-parser",

@@ -21,5 +21,5 @@ gettext-parser

* `gettextParser.po.parse(buf)` where `buf` is a *po* file as a Buffer or an unicode string. Returns gettext-parser specific translation object (see below)
* `gettextParser.po.parse(buf[, defaultCharset])` where `buf` is a *po* file as a Buffer or an unicode string. `defaultCharset` is the charset to use if charset is not defined or is the default `"CHARSET"`. Returns gettext-parser specific translation object (see below)
* `gettextParser.po.compile(obj)` where `obj` is a translation object, returns a *po* file as a Buffer
* `gettextParser.mo.parse(buf)` where `buf` is a *mo* file as a Buffer (*mo* is binary format, so do not use strings). Returns translation object
* `gettextParser.mo.parse(buf[, defaultCharset])` where `buf` is a *mo* file as a Buffer (*mo* is binary format, so do not use strings). `defaultCharset` is the charset to use if charset is not defined or is the default `"CHARSET"`. Returns translation object
* `gettextParser.mo.compile(obj)` where `obj` is a translation object, returns a *mo* file as a Buffer

@@ -26,0 +26,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