From 67d9bedc1481a0ba13db93fcb09a0ee8e60ab71c Mon Sep 17 00:00:00 2001 From: SheetJS Date: Sat, 27 Sep 2014 14:05:43 -0400 Subject: [PATCH] version bump 1.3.5: codepage bin supports stdin --- bin/codepage.njs | 47 +++++++++++++++++++++++++++-------------------- codepage.md | 13 +++++++++---- cpexcel.js | 2 +- cptable.js | 2 +- package.json | 3 ++- sbcs.js | 2 +- test.js | 10 +++++++--- 7 files changed, 48 insertions(+), 31 deletions(-) diff --git a/bin/codepage.njs b/bin/codepage.njs index 8c8abcc..5666707 100755 --- a/bin/codepage.njs +++ b/bin/codepage.njs @@ -25,31 +25,38 @@ if(program.list) { process.exit(); } -if(!fs.existsSync(program.args[0])) { - console.error('codepage: must specify a filename'); - process.exit(13); -} - var fr = program.fromCode || 65001; var to = program.toCode || 65001; var f = program.args[0]; var o = program.output; -var text = fs.readFileSync(f); -var dec = codepage.utils.decode(fr, text); -var bom = { - 1200: new Buffer([0xFF, 0xFE]), - 1201: new Buffer([0xFE, 0xFF]), - 12000: new Buffer([0xFF, 0xFE, 0x00, 0x00]), - 12001: new Buffer([0x00, 0x00, 0xFE, 0xFF]), - 16969: new Buffer([0x69, 0x69]), - 65000: new Buffer([0x2B, 0x2F, 0x76, 0x2B]), - 65001: new Buffer([0xEF, 0xBB, 0xBF]) +if(!process.stdin.isTTY) f = f || "-"; + +if(f !== "-" && !fs.existsSync(f)) { + console.error('codepage: must specify a filename'); + process.exit(13); } -if(!program.toCode && !o) console.log(dec.toString('utf8')); -else if(!program.bom || !bom[fr]) fs.writeFileSync(o || (f + "." + to), codepage.utils.encode(to, dec)); -else { - fs.writeFileSync(o || (f + "." + to), bom[fr]); - fs.appendFileSync(o || (f + "." + to), codepage.utils.encode(to, dec)); +if(f === "-") process.stdin.pipe(require('concat-stream')(process_text)); +else process_text(fs.readFileSync(f)); + +function process_text(text) { + var dec = codepage.utils.decode(fr, text); + + var bom = { + 1200: new Buffer([0xFF, 0xFE]), + 1201: new Buffer([0xFE, 0xFF]), + 12000: new Buffer([0xFF, 0xFE, 0x00, 0x00]), + 12001: new Buffer([0x00, 0x00, 0xFE, 0xFF]), + 16969: new Buffer([0x69, 0x69]), + 65000: new Buffer([0x2B, 0x2F, 0x76, 0x2B]), + 65001: new Buffer([0xEF, 0xBB, 0xBF]) + } + + if(!program.toCode && !o) console.log(dec.toString('utf8')); + else if(!program.bom || !bom[fr]) fs.writeFileSync(o || (f + "." + to), codepage.utils.encode(to, dec)); + else { + fs.writeFileSync(o || (f + "." + to), bom[fr]); + fs.appendFileSync(o || (f + "." + to), codepage.utils.encode(to, dec)); + } } diff --git a/codepage.md b/codepage.md index 97b3fc7..512320a 100644 --- a/codepage.md +++ b/codepage.md @@ -489,7 +489,7 @@ describe('consistency', function() { cptable = require('./'); U = cptable.utils; var chk = function(cptable, cacheit) { return function(x) { - it('should consistently process CP ' + x + ' ' + cacheit, function() { + it('should consistently process CP ' + x, function() { var cp = cptable[x], D = cp.dec, E = cp.enc; if(cacheit) cptable.utils.cache.encache(); else cptable.utils.cache.decache(); @@ -513,8 +513,12 @@ describe('consistency', function() { cptable.utils.cache.encache(); }); }; }; - Object.keys(cptable).filter(function(w) { return w == +w; }).forEach(chk(cptable, true)); - Object.keys(cptable).filter(function(w) { return w == +w; }).forEach(chk(cptable, false)); + describe('cached', function() { + Object.keys(cptable).filter(function(w) { return w == +w; }).forEach(chk(cptable, true)); + }); + describe('direct', function() { + Object.keys(cptable).filter(function(w) { return w == +w; }).forEach(chk(cptable, false)); + }); }); ``` @@ -715,7 +719,7 @@ describe('failures', function() { ```json>package.json { "name": "codepage", - "version": "1.3.4", + "version": "1.3.5", "author": "SheetJS", "description": "pure-JS library to handle codepages", "keywords": [ "codepage", "iconv", "convert", "strings" ], @@ -733,6 +737,7 @@ describe('failures', function() { "main": "cputils.js", "dependencies": { "voc":"", + "concat-stream":"", "commander":"" }, "devDependencies": { diff --git a/cpexcel.js b/cpexcel.js index b3a000c..33b128b 100644 --- a/cpexcel.js +++ b/cpexcel.js @@ -1,6 +1,6 @@ /* cpexcel.js (C) 2013-2014 SheetJS -- http://sheetjs.com */ /*jshint -W100 */ -var cptable = {version:"1.3.4"}; +var cptable = {version:"1.3.5"}; cptable[874] = (function(){ var d = "\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007\b\t\n\u000b\f\r\u000e\u000f\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019\u001a\u001b\u001c\u001d\u001e\u001f !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~€����…�����������‘’“”•–—�������� กขฃคฅฆงจฉชซฌญฎฏฐฑฒณดตถทธนบปผฝพฟภมยรฤลฦวศษสหฬอฮฯะัาำิีึืฺุู����฿เแโใไๅๆ็่้๊๋์ํ๎๏๐๑๒๓๔๕๖๗๘๙๚๛����", D = [], e = {}; for(var i=0;i!=d.length;++i) { if(d.charCodeAt(i) !== 0xFFFD) e[d[i]] = i; D[i] = d.charAt(i); } return {"enc": e, "dec": D }; })(); cptable[932] = (function(){ var d = [], e = {}, D = [], j; D[0] = "\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007\b\t\n\u000b\f\r\u000e\u000f\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019\u001a\u001b\u001c\u001d\u001e\u001f !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~���������������������������������。「」、・ヲァィゥェォャュョッーアイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワン゙゚��������������������������������".split(""); diff --git a/cptable.js b/cptable.js index 8caa6cf..fdcf270 100644 --- a/cptable.js +++ b/cptable.js @@ -1,6 +1,6 @@ /* cptable.js (C) 2013-2014 SheetJS -- http://sheetjs.com */ /*jshint -W100 */ -var cptable = {version:"1.3.4"}; +var cptable = {version:"1.3.5"}; cptable[37] = (function(){ var d = "\u0000\u0001\u0002\u0003œ\t†—Ž\u000b\f\r\u000e\u000f\u0010\u0011\u0012\u0013…\b‡\u0018\u0019’\u001c\u001d\u001e\u001f€‚ƒ„\n\u0017\u001bˆ‰Š‹Œ\u0005\u0006\u0007‘\u0016“”•–\u0004˜™š›\u0014\u0015ž\u001a  âäàáãåçñ¢.<(+|&éêëèíîïìß!$*);¬-/ÂÄÀÁÃÅÇѦ,%_>?øÉÊËÈÍÎÏÌ`:#@'=\"Øabcdefghi«»ðýþ±°jklmnopqrªºæ¸Æ¤µ~stuvwxyz¡¿ÐÝÞ®^£¥·©§¶¼½¾[]¯¨´×{ABCDEFGHI­ôöòóõ}JKLMNOPQR¹ûüùúÿ\\÷STUVWXYZ²ÔÖÒÓÕ0123456789³ÛÜÙڟ", D = [], e = {}; for(var i=0;i!=d.length;++i) { if(d.charCodeAt(i) !== 0xFFFD) e[d[i]] = i; D[i] = d.charAt(i); } return {"enc": e, "dec": D }; })(); cptable[437] = (function(){ var d = "\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007\b\t\n\u000b\f\r\u000e\u000f\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019\u001a\u001b\u001c\u001d\u001e\u001f !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~ÇüéâäàåçêëèïîìÄÅÉæÆôöòûùÿÖÜ¢£¥₧ƒáíóúñѪº¿⌐¬½¼¡«»░▒▓│┤╡╢╖╕╣║╗╝╜╛┐└┴┬├─┼╞╟╚╔╩╦╠═╬╧╨╤╥╙╘╒╓╫╪┘┌█▄▌▐▀αßΓπΣσµτΦΘΩδ∞φε∩≡±≥≤⌠⌡÷≈°∙·√ⁿ²■ ", D = [], e = {}; for(var i=0;i!=d.length;++i) { if(d.charCodeAt(i) !== 0xFFFD) e[d[i]] = i; D[i] = d.charAt(i); } return {"enc": e, "dec": D }; })(); cptable[500] = (function(){ var d = "\u0000\u0001\u0002\u0003œ\t†—Ž\u000b\f\r\u000e\u000f\u0010\u0011\u0012\u0013…\b‡\u0018\u0019’\u001c\u001d\u001e\u001f€‚ƒ„\n\u0017\u001bˆ‰Š‹Œ\u0005\u0006\u0007‘\u0016“”•–\u0004˜™š›\u0014\u0015ž\u001a  âäàáãåçñ[.<(+!&éêëèíîïìß]$*);^-/ÂÄÀÁÃÅÇѦ,%_>?øÉÊËÈÍÎÏÌ`:#@'=\"Øabcdefghi«»ðýþ±°jklmnopqrªºæ¸Æ¤µ~stuvwxyz¡¿ÐÝÞ®¢£¥·©§¶¼½¾¬|¯¨´×{ABCDEFGHI­ôöòóõ}JKLMNOPQR¹ûüùúÿ\\÷STUVWXYZ²ÔÖÒÓÕ0123456789³ÛÜÙڟ", D = [], e = {}; for(var i=0;i!=d.length;++i) { if(d.charCodeAt(i) !== 0xFFFD) e[d[i]] = i; D[i] = d.charAt(i); } return {"enc": e, "dec": D }; })(); diff --git a/package.json b/package.json index 287d5ff..79b45cc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "codepage", - "version": "1.3.4", + "version": "1.3.5", "author": "SheetJS", "description": "pure-JS library to handle codepages", "keywords": [ "codepage", "iconv", "convert", "strings" ], @@ -18,6 +18,7 @@ "main": "cputils.js", "dependencies": { "voc":"", + "concat-stream":"", "commander":"" }, "devDependencies": { diff --git a/sbcs.js b/sbcs.js index 8b69592..87f23f8 100644 --- a/sbcs.js +++ b/sbcs.js @@ -1,6 +1,6 @@ /* sbcs.js (C) 2013-2014 SheetJS -- http://sheetjs.com */ /*jshint -W100 */ -var cptable = {version:"1.3.4"}; +var cptable = {version:"1.3.5"}; cptable[37] = (function(){ var d = "\u0000\u0001\u0002\u0003œ\t†—Ž\u000b\f\r\u000e\u000f\u0010\u0011\u0012\u0013…\b‡\u0018\u0019’\u001c\u001d\u001e\u001f€‚ƒ„\n\u0017\u001bˆ‰Š‹Œ\u0005\u0006\u0007‘\u0016“”•–\u0004˜™š›\u0014\u0015ž\u001a  âäàáãåçñ¢.<(+|&éêëèíîïìß!$*);¬-/ÂÄÀÁÃÅÇѦ,%_>?øÉÊËÈÍÎÏÌ`:#@'=\"Øabcdefghi«»ðýþ±°jklmnopqrªºæ¸Æ¤µ~stuvwxyz¡¿ÐÝÞ®^£¥·©§¶¼½¾[]¯¨´×{ABCDEFGHI­ôöòóõ}JKLMNOPQR¹ûüùúÿ\\÷STUVWXYZ²ÔÖÒÓÕ0123456789³ÛÜÙڟ", D = [], e = {}; for(var i=0;i!=d.length;++i) { if(d.charCodeAt(i) !== 0xFFFD) e[d[i]] = i; D[i] = d.charAt(i); } return {"enc": e, "dec": D }; })(); cptable[437] = (function(){ var d = "\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007\b\t\n\u000b\f\r\u000e\u000f\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019\u001a\u001b\u001c\u001d\u001e\u001f !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~ÇüéâäàåçêëèïîìÄÅÉæÆôöòûùÿÖÜ¢£¥₧ƒáíóúñѪº¿⌐¬½¼¡«»░▒▓│┤╡╢╖╕╣║╗╝╜╛┐└┴┬├─┼╞╟╚╔╩╦╠═╬╧╨╤╥╙╘╒╓╫╪┘┌█▄▌▐▀αßΓπΣσµτΦΘΩδ∞φε∩≡±≥≤⌠⌡÷≈°∙·√ⁿ²■ ", D = [], e = {}; for(var i=0;i!=d.length;++i) { if(d.charCodeAt(i) !== 0xFFFD) e[d[i]] = i; D[i] = d.charAt(i); } return {"enc": e, "dec": D }; })(); cptable[500] = (function(){ var d = "\u0000\u0001\u0002\u0003œ\t†—Ž\u000b\f\r\u000e\u000f\u0010\u0011\u0012\u0013…\b‡\u0018\u0019’\u001c\u001d\u001e\u001f€‚ƒ„\n\u0017\u001bˆ‰Š‹Œ\u0005\u0006\u0007‘\u0016“”•–\u0004˜™š›\u0014\u0015ž\u001a  âäàáãåçñ[.<(+!&éêëèíîïìß]$*);^-/ÂÄÀÁÃÅÇѦ,%_>?øÉÊËÈÍÎÏÌ`:#@'=\"Øabcdefghi«»ðýþ±°jklmnopqrªºæ¸Æ¤µ~stuvwxyz¡¿ÐÝÞ®¢£¥·©§¶¼½¾¬|¯¨´×{ABCDEFGHI­ôöòóõ}JKLMNOPQR¹ûüùúÿ\\÷STUVWXYZ²ÔÖÒÓÕ0123456789³ÛÜÙڟ", D = [], e = {}; for(var i=0;i!=d.length;++i) { if(d.charCodeAt(i) !== 0xFFFD) e[d[i]] = i; D[i] = d.charAt(i); } return {"enc": e, "dec": D }; })(); diff --git a/test.js b/test.js index 9073cd8..0ddec2b 100644 --- a/test.js +++ b/test.js @@ -45,7 +45,7 @@ describe('consistency', function() { cptable = require('./'); U = cptable.utils; var chk = function(cptable, cacheit) { return function(x) { - it('should consistently process CP ' + x + ' ' + cacheit, function() { + it('should consistently process CP ' + x, function() { var cp = cptable[x], D = cp.dec, E = cp.enc; if(cacheit) cptable.utils.cache.encache(); else cptable.utils.cache.decache(); @@ -69,8 +69,12 @@ describe('consistency', function() { cptable.utils.cache.encache(); }); }; }; - Object.keys(cptable).filter(function(w) { return w == +w; }).forEach(chk(cptable, true)); - Object.keys(cptable).filter(function(w) { return w == +w; }).forEach(chk(cptable, false)); + describe('cached', function() { + Object.keys(cptable).filter(function(w) { return w == +w; }).forEach(chk(cptable, true)); + }); + describe('direct', function() { + Object.keys(cptable).filter(function(w) { return w == +w; }).forEach(chk(cptable, false)); + }); }); describe('entry conditions', function() { it('should fail to load utils if cptable unavailable', function() {