node-gettext
Advanced tools
Comparing version 0.1.1 to 0.1.2
@@ -76,3 +76,3 @@ var jspack = require("./vendor/jspack/jspack").jspack; | ||
var data = Buffer.isBuffer(data) && data || new Buffer(data); | ||
var i=0, pos = this.findAll(data), len = pos.length, parts = [], | ||
var i=0, pos = module.exports.bufferFindAll(this, data), len = pos.length, parts = [], | ||
startPos, endPos; | ||
@@ -94,2 +94,3 @@ if(!this.length || !data.length){ | ||
function bufferEquals(data){ | ||
var data = Buffer.isBuffer(data) && data || new Buffer(data); | ||
@@ -122,67 +123,24 @@ | ||
function bufferReadint(fmt){ | ||
var data = this.read(4); | ||
return data.unpack(fmt); | ||
var data = module.exports.bufferRead(this, 4); | ||
return module.exports.bufferUnpack(data, fmt); | ||
} | ||
if(!("reset" in Buffer.prototype)){ | ||
Object.defineProperty(Buffer.prototype, "reset",{ | ||
value: bufferReset, | ||
enumerable: false | ||
}); | ||
} | ||
if(!("seek" in Buffer.prototype)){ | ||
Object.defineProperty(Buffer.prototype, "seek",{ | ||
value: bufferSeek, | ||
enumerable: false | ||
}); | ||
function bufferBinder(func){ | ||
return function(){ | ||
var args = Array.prototype.slice.call(arguments), | ||
buffer = args.shift(); | ||
return func.apply(buffer, args); | ||
} | ||
} | ||
if(!("read" in Buffer.prototype)){ | ||
Object.defineProperty(Buffer.prototype, "read",{ | ||
value: bufferRead, | ||
enumerable: false | ||
}); | ||
} | ||
if(!("readint" in Buffer.prototype)){ | ||
Object.defineProperty(Buffer.prototype, "readint",{ | ||
value: bufferReadint, | ||
enumerable: false | ||
}); | ||
} | ||
if(!("findAll" in Buffer.prototype)){ | ||
Object.defineProperty(Buffer.prototype, "findAll",{ | ||
value: bufferFindAll, | ||
enumerable: false | ||
}); | ||
} | ||
if(!("split" in Buffer.prototype)){ | ||
Object.defineProperty(Buffer.prototype, "split",{ | ||
value: bufferSplit, | ||
enumerable: false | ||
}); | ||
} | ||
if(!("equals" in Buffer.prototype)){ | ||
Object.defineProperty(Buffer.prototype, "equals",{ | ||
value: bufferEquals, | ||
enumerable: false | ||
}); | ||
} | ||
if(!("unpack" in Buffer.prototype)){ | ||
Object.defineProperty(Buffer.prototype, "unpack",{ | ||
value: bufferUnpack, | ||
enumerable: false | ||
}); | ||
} | ||
if(!("pack" in Number.prototype)){ | ||
Object.defineProperty(Number.prototype, "pack",{ | ||
value: numberPack, | ||
enumerable: false | ||
}); | ||
} | ||
// Expose to the world | ||
module.exports.bufferReset = bufferBinder(bufferReset); | ||
module.exports.bufferSeek = bufferBinder(bufferSeek); | ||
module.exports.bufferRead = bufferBinder(bufferRead); | ||
module.exports.bufferReadint = bufferBinder(bufferReadint); | ||
module.exports.bufferFindAll = bufferBinder(bufferFindAll); | ||
module.exports.bufferSplit = bufferBinder(bufferSplit); | ||
module.exports.bufferEquals = bufferBinder(bufferEquals); | ||
module.exports.bufferUnpack = bufferBinder(bufferUnpack); | ||
module.exports.numberPack = bufferBinder(numberPack); |
41
index.js
@@ -6,3 +6,3 @@ | ||
require("./buffer-helpers"); | ||
var buftools = require("./buffer-helpers"); | ||
@@ -13,6 +13,6 @@ function GettextDomain(textdomain){ | ||
this.revision = this.textdomain.readint(this.byteorder); | ||
this.total = this.textdomain.readint(this.byteorder); | ||
this.originals = this.textdomain.readint(this.byteorder); | ||
this.translations = this.textdomain.readint(this.byteorder); | ||
this.revision = buftools.bufferReadint(this.textdomain, this.byteorder); | ||
this.total = buftools.bufferReadint(this.textdomain, this.byteorder); | ||
this.originals = buftools.bufferReadint(this.textdomain, this.byteorder); | ||
this.translations = buftools.bufferReadint(this.textdomain, this.byteorder); | ||
@@ -25,3 +25,9 @@ this.table_originals = []; | ||
this.headers = false; | ||
this.iconv = { | ||
convert: function(data){ | ||
return data; | ||
} | ||
} | ||
if(this.total){ | ||
@@ -36,6 +42,6 @@ this.load_tables(); | ||
GettextDomain.prototype.checkMagick = function(){ | ||
var magic = this.textdomain.read(4); | ||
if(magic.equals(GettextDomain.bigMagic)){ | ||
var magic = buftools.bufferRead(this.textdomain, 4); | ||
if(buftools.bufferEquals(magic, GettextDomain.bigMagic)){ | ||
this.byteorder = ">i"; | ||
}else if(magic.equals(GettextDomain.littleMagic)){ | ||
}else if(buftools.bufferEquals(magic, GettextDomain.littleMagic)){ | ||
this.byteorder = "<i"; | ||
@@ -51,11 +57,11 @@ }else{ | ||
// get originals | ||
this.textdomain.seek(this.originals); | ||
buftools.bufferSeek(this.textdomain, this.originals); | ||
for(var i=0; i<this.total; i++){ | ||
this.table_originals.push([this.textdomain.readint(this.byteorder), this.textdomain.readint(this.byteorder)]); | ||
this.table_originals.push([buftools.bufferReadint(this.textdomain, this.byteorder), buftools.bufferReadint(this.textdomain, this.byteorder)]); | ||
} | ||
// get translations | ||
this.textdomain.seek(this.translations); | ||
buftools.bufferSeek(this.textdomain, this.translations); | ||
for(var i=0; i<this.total; i++){ | ||
this.table_translations.push([this.textdomain.readint(this.byteorder), this.textdomain.readint(this.byteorder)]); | ||
this.table_translations.push([buftools.bufferReadint(this.textdomain, this.byteorder), buftools.bufferReadint(this.textdomain, this.byteorder)]); | ||
} | ||
@@ -65,10 +71,11 @@ | ||
for(var i=0; i<this.total; i++){ | ||
this.textdomain.seek(this.table_originals[i][1]); | ||
original = this.textdomain.read(this.table_originals[i][0]); | ||
buftools.bufferSeek(this.textdomain, this.table_originals[i][1]); | ||
original = buftools.bufferRead(this.textdomain, this.table_originals[i][0]); | ||
this.textdomain.seek(this.table_translations[i][1]); | ||
translation = this.textdomain.read(this.table_translations[i][0]); | ||
buftools.bufferSeek(this.textdomain, this.table_translations[i][1]); | ||
translation = buftools.bufferRead(this.textdomain, this.table_translations[i][0]); | ||
this.handle_strings(original, translation); | ||
} | ||
} | ||
@@ -75,0 +82,0 @@ |
{ | ||
"name": "node-gettext", | ||
"description": "Gettext client for Node.js to use .mo files for I18N", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"author" : "Andris Reinman", | ||
@@ -6,0 +6,0 @@ "maintainers":[ |
@@ -9,6 +9,2 @@ # node-gettext | ||
## Quirks | ||
**node-gettext** currently messes a bit with Buffer an Number prototypes (adds some non-enumerable helpers) | ||
## Usage | ||
@@ -15,0 +11,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Non-existent author
Supply chain riskThe package was published by an npm account that no longer exists.
Found 1 instance in 1 package
0
31917
586
82
1