sv 0.4.2 → 0.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bin/sv.d.ts CHANGED
@@ -1 +1,2 @@
1
+ #!/usr/bin/env node
1
2
  export declare function main(): void;
package/bin/sv.js CHANGED
@@ -1,9 +1,11 @@
1
1
  #!/usr/bin/env node
2
2
  "use strict";
3
- var optimist = require('optimist');
4
- var fs_1 = require('fs');
5
- var async_1 = require('async');
6
- var index_1 = require('../index');
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.main = void 0;
5
+ var optimist = require("optimist");
6
+ var fs_1 = require("fs");
7
+ var async_1 = require("async");
8
+ var index_1 = require("../index");
7
9
  function main() {
8
10
  var argvparser = optimist
9
11
  .usage([
@@ -103,13 +105,13 @@ function main() {
103
105
  }
104
106
  else if (!process.stdin['isTTY']) {
105
107
  // process.stdin.setEncoding('utf8');
106
- index_1.transform(process.stdin, parser_opts, stringifier_opts, exit);
108
+ (0, index_1.transform)(process.stdin, parser_opts, stringifier_opts, exit);
107
109
  }
108
110
  else if (argv._.length) {
109
111
  var filepaths = argv._;
110
- async_1.eachSeries(filepaths, function (filepath, callback) {
111
- var stream = fs_1.createReadStream(filepath);
112
- index_1.transform(stream, parser_opts, stringifier_opts, callback);
112
+ (0, async_1.eachSeries)(filepaths, function (filepath, callback) {
113
+ var stream = (0, fs_1.createReadStream)(filepath);
114
+ (0, index_1.transform)(stream, parser_opts, stringifier_opts, callback);
113
115
  console.error(''); // newline
114
116
  }, exit);
115
117
  }
package/common.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ /// <reference types="node" />
1
2
  /**
2
3
  - `encoding` for converting to strings.
3
4
  - `missing` is the value we use for 'time' when we have `columns = ['index', 'time']` and `write({index: 90})` is called.
@@ -8,7 +9,7 @@
8
9
  */
9
10
  export interface Configuration {
10
11
  /** character encoding */
11
- encoding?: string;
12
+ encoding?: BufferEncoding;
12
13
  /** string to represent missing data */
13
14
  missing?: string;
14
15
  /** string to separate rows */
package/common.js CHANGED
@@ -1,4 +1,6 @@
1
1
  "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.zip = exports.merge = void 0;
2
4
  /**
3
5
  Like reverse Object.assign, but with special treatment for undefined.
4
6
  */
package/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ /// <reference types="node" />
1
2
  import { Parser, ParserConfiguration } from './parser';
2
3
  import { Stringifier, StringifierConfiguration } from './stringifier';
3
4
  export interface TransformParserConfiguration extends ParserConfiguration {
package/index.js CHANGED
@@ -1,10 +1,12 @@
1
1
  "use strict";
2
- var json_1 = require('streaming/json');
3
- var property_1 = require('streaming/property');
4
- var parser_1 = require('./parser');
5
- exports.Parser = parser_1.Parser;
6
- var stringifier_1 = require('./stringifier');
7
- exports.Stringifier = stringifier_1.Stringifier;
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.transform = exports.Stringifier = exports.Parser = void 0;
4
+ var json_1 = require("streaming/json");
5
+ var property_1 = require("streaming/property");
6
+ var parser_1 = require("./parser");
7
+ Object.defineProperty(exports, "Parser", { enumerable: true, get: function () { return parser_1.Parser; } });
8
+ var stringifier_1 = require("./stringifier");
9
+ Object.defineProperty(exports, "Stringifier", { enumerable: true, get: function () { return stringifier_1.Stringifier; } });
8
10
  function transform(input, parserConfig, stringifierConfig, callback) {
9
11
  var transforms = [
10
12
  parserConfig.json ? new json_1.Parser() : new parser_1.Parser(parserConfig),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sv",
3
- "version": "0.4.2",
3
+ "version": "0.4.3",
4
4
  "description": "Any separated values.",
5
5
  "keywords": [
6
6
  "any",
@@ -12,24 +12,23 @@
12
12
  "tables"
13
13
  ],
14
14
  "homepage": "https://github.com/chbrown/sv",
15
- "repository": {
16
- "type": "git",
17
- "url": "https://github.com/chbrown/sv.git"
18
- },
15
+ "repository": "github:chbrown/sv",
19
16
  "author": "Christopher Brown <io@henrian.com> (http://henrian.com)",
20
17
  "license": "MIT",
21
18
  "dependencies": {
22
- "async": "*",
23
- "optimist": "*",
24
- "streaming": "*"
19
+ "async": "^1.5.2",
20
+ "optimist": "^0.6.1",
21
+ "streaming": "^1.1.1"
25
22
  },
26
23
  "devDependencies": {
27
- "coveralls": "*",
28
- "declarations": "*",
29
- "istanbul": "*",
30
- "mocha": "*",
31
- "mocha-lcov-reporter": "*",
32
- "typescript": "*"
24
+ "@types/mocha": "^2.2.43",
25
+ "@types/node": "^18.11.9",
26
+ "@types/optimist": "^0.0.33",
27
+ "coveralls": "^3.1.1",
28
+ "istanbul": "^0.4.5",
29
+ "mocha": "^2.4.5",
30
+ "mocha-lcov-reporter": "^1.3.0",
31
+ "typescript": "^4.9.5"
33
32
  },
34
33
  "scripts": {
35
34
  "test": "make test"
package/parser.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
1
3
  import { Transform } from 'stream';
2
4
  import { Configuration } from './common';
3
5
  export interface ParserConfiguration extends Configuration {
@@ -25,5 +27,5 @@ export declare class Parser extends Transform {
25
27
  protected writeRow(cells: string[]): void;
26
28
  flush(callback: (error?: Error) => void, nonfinal: boolean): void;
27
29
  _flush(callback: (error?: Error) => void): void;
28
- _transform(chunk: Buffer, encoding: string, callback: (error?: Error) => void): void;
30
+ _transform(chunk: Buffer, encoding: BufferEncoding | 'buffer', callback: (error?: Error) => void): void;
29
31
  }
package/parser.js CHANGED
@@ -1,11 +1,23 @@
1
1
  "use strict";
2
- var __extends = (this && this.__extends) || function (d, b) {
3
- for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
4
- function __() { this.constructor = d; }
5
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
6
- };
7
- var stream_1 = require('stream');
8
- var common_1 = require('./common');
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.Parser = exports.inferDelimiter = exports.defaultParserConfiguration = void 0;
19
+ var stream_1 = require("stream");
20
+ var common_1 = require("./common");
9
21
  exports.defaultParserConfiguration = {
10
22
  encoding: 'utf8',
11
23
  missing: '',
@@ -32,7 +44,7 @@ function inferDelimiter(buffer) {
32
44
  9,
33
45
  59,
34
46
  44,
35
- 32,
47
+ 32, // ' ' (space)
36
48
  ];
37
49
  // TODO: make this more robust (that's why I even counted them)
38
50
  for (var candidate = void 0, j = 0; (candidate = candidates[j]); j++) {
@@ -47,30 +59,31 @@ exports.inferDelimiter = inferDelimiter;
47
59
  - `cellBuffer` is a list of strings that have yet to be processed (and sent to output).
48
60
 
49
61
  */
50
- var Parser = (function (_super) {
62
+ var Parser = /** @class */ (function (_super) {
51
63
  __extends(Parser, _super);
52
64
  function Parser(config) {
53
65
  if (config === void 0) { config = {}; }
54
- _super.call(this, {
66
+ var _this = _super.call(this, {
55
67
  decodeStrings: true,
56
68
  readableObjectMode: true,
57
69
  writableObjectMode: false,
58
- });
59
- this.byteBuffer = new Buffer(0);
60
- this.cellBuffer = [];
70
+ }) || this;
71
+ _this.byteBuffer = Buffer.alloc(0);
72
+ _this.cellBuffer = [];
61
73
  // merge defaults
62
- this.config = common_1.merge(config, exports.defaultParserConfiguration);
74
+ _this.config = (0, common_1.merge)(config, exports.defaultParserConfiguration);
63
75
  // special demarcating characters
64
76
  // 1. delimiter
65
- if (this.config.delimiter) {
66
- this.delimiterByte = this.config.delimiter.charCodeAt(0);
77
+ if (_this.config.delimiter) {
78
+ _this.delimiterByte = _this.config.delimiter.charCodeAt(0);
67
79
  }
68
80
  // 2. quote
69
- this.quoteByte = this.config.quotechar.charCodeAt(0);
70
- this.quotequoteRegExp = new RegExp(this.config.quotechar + this.config.quotechar, 'g');
81
+ _this.quoteByte = _this.config.quotechar.charCodeAt(0);
82
+ _this.quotequoteRegExp = new RegExp(_this.config.quotechar + _this.config.quotechar, 'g');
71
83
  // 3. escape
72
- this.escapeByte = this.config.escape.charCodeAt(0);
73
- this.escapeQuoteRegExp = new RegExp('\\' + this.config.escape + this.config.quotechar, 'g');
84
+ _this.escapeByte = _this.config.escape.charCodeAt(0);
85
+ _this.escapeQuoteRegExp = new RegExp('\\' + _this.config.escape + _this.config.quotechar, 'g');
86
+ return _this;
74
87
  }
75
88
  Parser.prototype.writeRow = function (cells) {
76
89
  if (!this.config.columns) {
@@ -78,7 +91,7 @@ var Parser = (function (_super) {
78
91
  this.config.columns = cells;
79
92
  }
80
93
  else {
81
- this.push(common_1.zip(this.config.columns, cells, this.config.missing));
94
+ this.push((0, common_1.zip)(this.config.columns, cells, this.config.missing));
82
95
  }
83
96
  };
84
97
  Parser.prototype.flush = function (callback, nonfinal) {
@@ -127,7 +140,9 @@ var Parser = (function (_super) {
127
140
  else if (!eos && buffer[i] === this.quoteByte && !inside_quote && i == start) {
128
141
  // if we are not already inside, and on a "
129
142
  inside_quote = true;
143
+ // we can only enter a quote at the edge of the cell (thus, i == start)
130
144
  }
145
+ // otherwise we just wait for the delimiter
131
146
  else if (
132
147
  // if we are at the very end of the input and this is the final chunk (ignoring any sort of state)
133
148
  eos ||
package/stringifier.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
1
3
  import { Transform } from 'stream';
2
4
  import { Configuration } from './common';
3
5
  export interface StringifierConfiguration extends Configuration {
@@ -38,5 +40,5 @@ export declare class Stringifier extends Transform {
38
40
  protected writeObjects(objects: any[]): void;
39
41
  flush(callback: (error?: Error) => void, nonfinal: boolean): void;
40
42
  _flush(callback: (error?: Error) => void): void;
41
- _transform(chunk: any, encoding: string, callback: (error?: Error) => void): void;
43
+ _transform(chunk: any, encoding: BufferEncoding, callback: (error?: Error) => void): void;
42
44
  }
package/stringifier.js CHANGED
@@ -1,11 +1,23 @@
1
1
  "use strict";
2
- var __extends = (this && this.__extends) || function (d, b) {
3
- for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
4
- function __() { this.constructor = d; }
5
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
6
- };
7
- var stream_1 = require('stream');
8
- var common_1 = require('./common');
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.Stringifier = exports.inferColumns = exports.defaultStringifierConfiguration = void 0;
19
+ var stream_1 = require("stream");
20
+ var common_1 = require("./common");
9
21
  exports.defaultStringifierConfiguration = {
10
22
  encoding: 'utf8',
11
23
  missing: '',
@@ -50,21 +62,22 @@ exports.inferColumns = inferColumns;
50
62
 
51
63
  - `_buffer` is an array of arrays or objects that need to be written
52
64
  */
53
- var Stringifier = (function (_super) {
65
+ var Stringifier = /** @class */ (function (_super) {
54
66
  __extends(Stringifier, _super);
55
67
  function Stringifier(config) {
56
68
  if (config === void 0) { config = {}; }
57
- _super.call(this, { readableObjectMode: false, writableObjectMode: true });
58
- this.rowBuffer = [];
59
- this.config = common_1.merge(config, exports.defaultStringifierConfiguration);
60
- this.quotecharRegExp = new RegExp(this.config.quotechar, 'ig');
61
- if (this.config.columns) {
69
+ var _this = _super.call(this, { readableObjectMode: false, writableObjectMode: true }) || this;
70
+ _this.rowBuffer = [];
71
+ _this.config = (0, common_1.merge)(config, exports.defaultStringifierConfiguration);
72
+ _this.quotecharRegExp = new RegExp(_this.config.quotechar, 'ig');
73
+ if (_this.config.columns) {
62
74
  // maybe we should write the columns even if we don't get any data?
63
- this.rowBuffer = [this.config.columns];
75
+ _this.rowBuffer = [_this.config.columns];
64
76
  }
65
77
  else {
66
- this.rowBuffer = [];
78
+ _this.rowBuffer = [];
67
79
  }
80
+ return _this;
68
81
  }
69
82
  Stringifier.prototype.writeObject = function (object) {
70
83
  // _write is already a thing, so don't use it.
@@ -97,6 +110,8 @@ var Stringifier = (function (_super) {
97
110
  if (contains_quotechar) {
98
111
  // serialize into the excel dialect, currently
99
112
  value = value.replace(this.quotecharRegExp, this.config.quotechar + this.config.quotechar);
113
+ // serialize with escapes:
114
+ // value = value.replace(this.quotechar_regex, '\\' + this.quotechar);
100
115
  }
101
116
  value = this.config.quotechar + value + this.config.quotechar;
102
117
  }
package/.npmignore DELETED
@@ -1,14 +0,0 @@
1
- tests/basic.ts
2
- tests/pairs.ts
3
- tests/quotes.ts
4
- tests/throughput.ts
5
- bin/sv.ts
6
- common.ts
7
- index.ts
8
- parser.ts
9
- stringifier.ts
10
- .travis.yml
11
- Makefile
12
- tsconfig.json
13
- tests/
14
- coverage/