Content-Length: 654577 | pFad | http://github.com/SheetJS/js-codepage/commit/67d9bedc1481a0ba13db93fcb09a0ee8e60ab71c

A4 version bump 1.3.5: codepage bin supports stdin · SheetJS/js-codepage@67d9bed · GitHub
Skip to content

Commit 67d9bed

Browse files
committed
version bump 1.3.5: codepage bin supports stdin
1 parent 21a55bd commit 67d9bed

File tree

7 files changed

+49
-32
lines changed

7 files changed

+49
-32
lines changed

bin/codepage.njs

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,31 +25,38 @@ if(program.list) {
2525
process.exit();
2626
}
2727

28-
if(!fs.existsSync(program.args[0])) {
29-
console.error('codepage: must specify a filename');
30-
process.exit(13);
31-
}
32-
3328
var fr = program.fromCode || 65001;
3429
var to = program.toCode || 65001;
3530
var f = program.args[0];
3631
var o = program.output;
37-
var text = fs.readFileSync(f);
38-
var dec = codepage.utils.decode(fr, text);
39-
40-
var bom = {
41-
1200: new Buffer([0xFF, 0xFE]),
42-
1201: new Buffer([0xFE, 0xFF]),
43-
12000: new Buffer([0xFF, 0xFE, 0x00, 0x00]),
44-
12001: new Buffer([0x00, 0x00, 0xFE, 0xFF]),
45-
16969: new Buffer([0x69, 0x69]),
46-
65000: new Buffer([0x2B, 0x2F, 0x76, 0x2B]),
47-
65001: new Buffer([0xEF, 0xBB, 0xBF])
32+
33+
if(!process.stdin.isTTY) f = f || "-";
34+
35+
if(f !== "-" && !fs.existsSync(f)) {
36+
console.error('codepage: must specify a filename');
37+
process.exit(13);
4838
}
4939

50-
if(!program.toCode && !o) console.log(dec.toString('utf8'));
51-
else if(!program.bom || !bom[fr]) fs.writeFileSync(o || (f + "." + to), codepage.utils.encode(to, dec));
52-
else {
53-
fs.writeFileSync(o || (f + "." + to), bom[fr]);
54-
fs.appendFileSync(o || (f + "." + to), codepage.utils.encode(to, dec));
40+
if(f === "-") process.stdin.pipe(require('concat-stream')(process_text));
41+
else process_text(fs.readFileSync(f));
42+
43+
function process_text(text) {
44+
var dec = codepage.utils.decode(fr, text);
45+
46+
var bom = {
47+
1200: new Buffer([0xFF, 0xFE]),
48+
1201: new Buffer([0xFE, 0xFF]),
49+
12000: new Buffer([0xFF, 0xFE, 0x00, 0x00]),
50+
12001: new Buffer([0x00, 0x00, 0xFE, 0xFF]),
51+
16969: new Buffer([0x69, 0x69]),
52+
65000: new Buffer([0x2B, 0x2F, 0x76, 0x2B]),
53+
65001: new Buffer([0xEF, 0xBB, 0xBF])
54+
}
55+
56+
if(!program.toCode && !o) console.log(dec.toString('utf8'));
57+
else if(!program.bom || !bom[fr]) fs.writeFileSync(o || (f + "." + to), codepage.utils.encode(to, dec));
58+
else {
59+
fs.writeFileSync(o || (f + "." + to), bom[fr]);
60+
fs.appendFileSync(o || (f + "." + to), codepage.utils.encode(to, dec));
61+
}
5562
}

codepage.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ describe('consistency', function() {
489489
cptable = require('./');
490490
U = cptable.utils;
491491
var chk = function(cptable, cacheit) { return function(x) {
492-
it('should consistently process CP ' + x + ' ' + cacheit, function() {
492+
it('should consistently process CP ' + x, function() {
493493
var cp = cptable[x], D = cp.dec, E = cp.enc;
494494
if(cacheit) cptable.utils.cache.encache();
495495
else cptable.utils.cache.decache();
@@ -513,8 +513,12 @@ describe('consistency', function() {
513513
cptable.utils.cache.encache();
514514
});
515515
}; };
516-
Object.keys(cptable).filter(function(w) { return w == +w; }).forEach(chk(cptable, true));
517-
Object.keys(cptable).filter(function(w) { return w == +w; }).forEach(chk(cptable, false));
516+
describe('cached', function() {
517+
Object.keys(cptable).filter(function(w) { return w == +w; }).forEach(chk(cptable, true));
518+
});
519+
describe('direct', function() {
520+
Object.keys(cptable).filter(function(w) { return w == +w; }).forEach(chk(cptable, false));
521+
});
518522
});
519523
```
520524

@@ -715,7 +719,7 @@ describe('failures', function() {
715719
```json>package.json
716720
{
717721
"name": "codepage",
718-
"version": "1.3.4",
722+
"version": "1.3.5",
719723
"author": "SheetJS",
720724
"description": "pure-JS library to handle codepages",
721725
"keywords": [ "codepage", "iconv", "convert", "strings" ],
@@ -733,6 +737,7 @@ describe('failures', function() {
733737
"main": "cputils.js",
734738
"dependencies": {
735739
"voc":"",
740+
"concat-stream":"",
736741
"commander":""
737742
},
738743
"devDependencies": {

cpexcel.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cptable.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "codepage",
3-
"version": "1.3.4",
3+
"version": "1.3.5",
44
"author": "SheetJS",
55
"description": "pure-JS library to handle codepages",
66
"keywords": [ "codepage", "iconv", "convert", "strings" ],
@@ -18,6 +18,7 @@
1818
"main": "cputils.js",
1919
"dependencies": {
2020
"voc":"",
21+
"concat-stream":"",
2122
"commander":""
2223
},
2324
"devDependencies": {

sbcs.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ describe('consistency', function() {
4545
cptable = require('./');
4646
U = cptable.utils;
4747
var chk = function(cptable, cacheit) { return function(x) {
48-
it('should consistently process CP ' + x + ' ' + cacheit, function() {
48+
it('should consistently process CP ' + x, function() {
4949
var cp = cptable[x], D = cp.dec, E = cp.enc;
5050
if(cacheit) cptable.utils.cache.encache();
5151
else cptable.utils.cache.decache();
@@ -69,8 +69,12 @@ describe('consistency', function() {
6969
cptable.utils.cache.encache();
7070
});
7171
}; };
72-
Object.keys(cptable).filter(function(w) { return w == +w; }).forEach(chk(cptable, true));
73-
Object.keys(cptable).filter(function(w) { return w == +w; }).forEach(chk(cptable, false));
72+
describe('cached', function() {
73+
Object.keys(cptable).filter(function(w) { return w == +w; }).forEach(chk(cptable, true));
74+
});
75+
describe('direct', function() {
76+
Object.keys(cptable).filter(function(w) { return w == +w; }).forEach(chk(cptable, false));
77+
});
7478
});
7579
describe('entry conditions', function() {
7680
it('should fail to load utils if cptable unavailable', function() {

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/SheetJS/js-codepage/commit/67d9bedc1481a0ba13db93fcb09a0ee8e60ab71c

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy