Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

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.2 to 0.1.3

test/folder.js

16

lib/pocompiler.js

@@ -129,8 +129,20 @@ var encoding = require("encoding"),

Compiler.prototype._addPOString = function(key, value){
var line = "";
key = (key || "").toString();
// escape newlines and quotes
value = (value || "").toString().
replace(/\\/g, "\\\\").
replace(/\"/g, "\\\"").
replace(/\r/g, "\\r");
replace(/\r/g, "\\r").
replace(/\n/g, "\\n");
var lines = sharedFuncs.foldLine(value);
if(lines.length < 2){
return key + " \"" + (lines.shift() || "") + "\"";
}else{
return key + " \"\"\n\"" + lines.join("\"\n\"") + "\"";
}
if(value.match(/\n/)){

@@ -137,0 +149,0 @@ value = value.replace(/\n/g, "\\n\n").replace(/\n$/, "");

@@ -6,2 +6,3 @@

module.exports.formatCharset = formatCharset;
module.exports.foldLine = foldLine;

@@ -74,2 +75,46 @@ /**

trim();
}
/**
* Folds long lines according to PO format
*
* @param {String} str PO formatted string to be folded
* @param {Number} [maxLen=76] Maximum allowed length for folded lines
* @return {Array} An array of lines
*/
function foldLine(str, maxLen){
maxLen = maxLen || 76;
var lines = [],
curLine = "",
pos = 0,
len = str.length,
match;
while(pos < len){
curLine = str.substr(pos, maxLen);
// ensure that the line never ends with a partial escaping
// make longer lines if needed
while(curLine.substr(-1) == "\\" && pos + curLine.length < len){
curLine += str.charAt(pos + curLine.length);
}
// ensure that if possible, line breaks are done at reasonable places
if((match = curLine.match(/\\n/))){
curLine = curLine.substr(0, match.index + 2);
}else if(pos + curLine.length < len){
if((match = curLine.match(/(\s+)[^\s]*$/)) && match.index > 0){
curLine = curLine.substr(0, match.index + match[1].length);
}else if((match = curLine.match(/([\x21-\x40\x5b-\x60\x7b-\x7e]+)[^\x21-\x40\x5b-\x60\x7b-\x7e]*$/)) && match.index > 0){
curLine = curLine.substr(0, match.index + match[1].length);
}
}
lines.push(curLine);
pos += curLine.length;
}
return lines;
}

2

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

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

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