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

gettext-parser

Package Overview
Dependencies
Maintainers
2
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 1.2.2 to 1.3.0

4

CHANGELOG.md
# Change Log
## [1.3.0] - 2017-08-03
- Added line folding length option to `po.compile` (thx @SleepWalker).
- Updated code to use new buffer API.
## [1.2.2] - 2017-01-11

@@ -4,0 +8,0 @@ - Use semistandard coding style.

25

lib/mocompiler.js
'use strict';
var Buffer = require('safe-buffer').Buffer;
var encoding = require('encoding');

@@ -86,3 +87,3 @@ var sharedFuncs = require('./shared');

list.push({
msgid: new Buffer(0),
msgid: Buffer.alloc(0),
msgstr: encoding.convert(sharedFuncs.generateHeader(this._table.headers), this._charset)

@@ -170,3 +171,3 @@ });

Compiler.prototype._build = function (list, size) {
var returnBuffer = new Buffer(size.total);
var returnBuffer = Buffer.alloc(size.total);
var curPosition = 0;

@@ -176,24 +177,24 @@ var i;

// magic
// magic
returnBuffer[this._writeFunc](this.MAGIC, 0);
// revision
// revision
returnBuffer[this._writeFunc](0, 4);
// string count
// string count
returnBuffer[this._writeFunc](list.length, 8);
// original string table offset
// original string table offset
returnBuffer[this._writeFunc](28, 12);
// translation string table offset
// translation string table offset
returnBuffer[this._writeFunc](28 + (4 + 4) * list.length, 16);
// hash table size
// hash table size
returnBuffer[this._writeFunc](0, 20);
// hash table offset
// hash table offset
returnBuffer[this._writeFunc](28 + (4 + 4) * list.length * 2, 24);
// build originals table
// build originals table
curPosition = 28 + 2 * (4 + 4) * list.length;

@@ -208,3 +209,3 @@ for (i = 0, len = list.length; i < len; i++) {

// build translations table
// build translations table
for (i = 0, len = list.length; i < len; i++) {

@@ -230,3 +231,3 @@ list[i].msgstr.copy(returnBuffer, curPosition);

// sort by msgid
// sort by msgid
list.sort(function (a, b) {

@@ -233,0 +234,0 @@ if (a.msgid > b.msgid) {

@@ -28,3 +28,3 @@ 'use strict';

/**
/**
* Method name for writing int32 values, default littleendian

@@ -34,3 +34,3 @@ */

/**
/**
* Method name for reading int32 values, default littleendian

@@ -86,3 +86,3 @@ */

for (var i = 0; i < this._total; i++) {
// msgid string
// msgid string
length = this._fileContents[this._readFunc](offsetOriginals);

@@ -94,3 +94,3 @@ offsetOriginals += 4;

// matching msgstr
// matching msgstr
length = this._fileContents[this._readFunc](offsetTranslations);

@@ -112,3 +112,3 @@ offsetTranslations += 4;

// dump the file contents object
// dump the file contents object
this._fileContents = null;

@@ -185,3 +185,3 @@ };

/**
/**
* GetText revision nr, usually 0

@@ -191,3 +191,3 @@ */

/**
/**
* Total count of translated strings

@@ -197,3 +197,3 @@ */

/**
/**
* Offset position for original strings table

@@ -203,3 +203,3 @@ */

/**
/**
* Offset position for translation strings table

@@ -209,3 +209,3 @@ */

// Load translations into this._translationTable
// Load translations into this._translationTable
this._loadTranslationTable();

@@ -212,0 +212,0 @@

'use strict';
var Buffer = require('safe-buffer').Buffer;
var encoding = require('encoding');

@@ -13,4 +14,4 @@ var sharedFuncs = require('./shared');

*/
module.exports = function (table) {
var compiler = new Compiler(table);
module.exports = function (table, options) {
var compiler = new Compiler(table, options);
return compiler.compile();

@@ -25,6 +26,10 @@ };

*/
function Compiler (table) {
function Compiler (table, options) {
this._table = table || {};
this._table.headers = this._table.headers || {};
this._table.translations = this._table.translations || {};
this._options = options || {};
if (!('foldLength' in this._options)) {
this._options.foldLength = 76;
}
this._translations = [];

@@ -89,3 +94,3 @@ this._handleCharset();

// add comments
// add comments
if (comments && (comments = this._drawComments(comments))) {

@@ -123,3 +128,3 @@ response.push(comments);

// escape newlines and quotes
// escape newlines and quotes
value = (value || '').toString()

@@ -132,4 +137,8 @@ .replace(/\\/g, '\\\\')

var lines = sharedFuncs.foldLine(value);
var lines = [value];
if (this._options.foldLength > 0) {
lines = sharedFuncs.foldLine(value, this._options.foldLength);
}
if (lines.length < 2) {

@@ -184,3 +193,3 @@ return key + ' "' + (lines.shift() || '') + '"';

var response = [];
var headerBlock = this._table.translations[''] && this._table.translations[''][''] || {};
var headerBlock = (this._table.translations[''] && this._table.translations['']['']) || {};

@@ -208,3 +217,3 @@ response.push(this._drawBlock(headerBlock, {

if (this._charset === 'utf-8' || this._charset === 'ascii') {
return new Buffer(response.join('\n\n'), 'utf-8');
return Buffer.from(response.join('\n\n'), 'utf-8');
} else {

@@ -211,0 +220,0 @@ return encoding.convert(response.join('\n\n'), this._charset);

@@ -44,3 +44,3 @@ 'use strict';

this._escaped = false;
this._node;
this._node = {};
this._state = this.states.none;

@@ -240,3 +240,3 @@

Parser.prototype._parseComments = function (tokens) {
// parse comments
// parse comments
tokens.forEach(function (node) {

@@ -465,3 +465,3 @@ var comment, lines;

// wait until the first 1kb before parsing headers for charset
// wait until the first 1kb before parsing headers for charset
if (this._cacheSize < this.initialTreshold) {

@@ -477,3 +477,3 @@ return setImmediate(done);

} else if (this._cacheSize) {
// this only happens if we had an uncompleted 8bit sequence from the last iteration
// this only happens if we had an uncompleted 8bit sequence from the last iteration
this._cache.push(chunk);

@@ -486,4 +486,4 @@ this._cacheSize += chunk.length;

// cache 8bit bytes from the end of the chunk
// helps if the chunk ends in the middle of an utf-8 sequence
// cache 8bit bytes from the end of the chunk
// helps if the chunk ends in the middle of an utf-8 sequence
for (i = chunk.length - 1; i >= 0; i--) {

@@ -496,3 +496,3 @@ if (chunk[i] >= 0x80) {

}
// it seems we found some 8bit bytes from the end of the string, so let's cache these
// it seems we found some 8bit bytes from the end of the string, so let's cache these
if (len) {

@@ -504,3 +504,3 @@ this._cache = [chunk.slice(chunk.length - len)];

// chunk might be empty if it only contined of 8bit bytes and these were all cached
// chunk might be empty if it only contined of 8bit bytes and these were all cached
if (chunk.length) {

@@ -507,0 +507,0 @@ this._parser._lexer(this._parser._toString(chunk));

@@ -100,4 +100,4 @@ 'use strict';

// ensure that the line never ends with a partial escaping
// make longer lines if needed
// ensure that the line never ends with a partial escaping
// make longer lines if needed
while (curLine.substr(-1) === '\\' && pos + curLine.length < len) {

@@ -107,3 +107,3 @@ curLine += str.charAt(pos + curLine.length);

// ensure that if possible, line breaks are done at reasonable places
// ensure that if possible, line breaks are done at reasonable places
if ((match = curLine.match(/\\n/))) {

@@ -110,0 +110,0 @@ curLine = curLine.substr(0, match.index + 2);

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

@@ -25,11 +25,14 @@ "contributors": [

"dependencies": {
"encoding": "0.1.12"
"encoding": "^0.1.12",
"safe-buffer": "^5.1.1"
},
"devDependencies": {
"chai": "3.5.0",
"eslint": "3.13.1",
"eslint-config-standard": "6.2.1",
"eslint-plugin-promise": "3.4.0",
"eslint-plugin-standard": "2.0.1",
"mocha": "3.2.0"
"chai": "^3.5.0",
"eslint": "^4.3.0",
"eslint-config-standard": "^10.2.1",
"eslint-plugin-import": "^2.7.0",
"eslint-plugin-node": "^5.1.1",
"eslint-plugin-promise": "^3.5.0",
"eslint-plugin-standard": "^3.0.1",
"mocha": "^3.5.0"
},

@@ -36,0 +39,0 @@ "keywords": [

@@ -60,3 +60,3 @@ gettext-parser [![Build Status](https://secure.travis-ci.org/smhg/gettext-parser.png)](http://travis-ci.org/smhg/gettext-parser)

gettextParser.po.compile(data) → Buffer
gettextParser.po.compile(data[, options]) → Buffer

@@ -66,2 +66,4 @@ Where

* **data** is a translation object either got from parsing a PO/MO file or composed by other means
* **options** is a configuration object with possible values
* **foldLength** is the length at which to fold message strings into newlines (default: 76). Set to 0 or false to disable folding.

@@ -68,0 +70,0 @@ **Example**

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