@ezs/basics 2.5.0 → 2.5.2
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/README.md +0 -1
- package/lib/buf-object.js +1 -3
- package/lib/csv-object.js +1 -7
- package/lib/csv-parse.js +1 -10
- package/lib/csv-string.js +1 -8
- package/lib/file-load.js +0 -10
- package/lib/file-save.js +3 -25
- package/lib/index.js +0 -34
- package/lib/ini-string.js +1 -5
- package/lib/json-parse.js +2 -23
- package/lib/json-string.js +0 -4
- package/lib/obj-count.js +1 -3
- package/lib/obj-flatten.js +2 -9
- package/lib/obj-namespaces.js +0 -11
- package/lib/obj-standardize.js +1 -16
- package/lib/request.js +0 -6
- package/lib/tar-dump.js +1 -8
- package/lib/tar-extract.js +0 -16
- package/lib/txt-concat.js +1 -6
- package/lib/txt-inflection.js +3 -9
- package/lib/txt-object.js +1 -6
- package/lib/txt-parse.js +1 -10
- package/lib/txt-sentences.js +4 -13
- package/lib/txt-zip.js +0 -8
- package/lib/url-connect.js +2 -23
- package/lib/url-fetch.js +2 -17
- package/lib/url-pagination.js +2 -9
- package/lib/url-parse.js +1 -5
- package/lib/url-request.js +2 -18
- package/lib/url-stream.js +0 -15
- package/lib/url-string.js +1 -5
- package/lib/xml-convert.js +1 -6
- package/lib/xml-parse.js +1 -7
- package/lib/xml-string.js +1 -9
- package/lib/zip-extract.js +0 -8
- package/package.json +3 -4
- package/CHANGELOG.md +0 -1098
package/README.md
CHANGED
|
@@ -367,7 +367,6 @@ Output:
|
|
|
367
367
|
#### Parameters
|
|
368
368
|
|
|
369
369
|
- `separator` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** to split at every JSONPath found (optional, default `"*"`)
|
|
370
|
-
- `legacy` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** use legacy or newer parser (separator should be different) (optional, default `true`)
|
|
371
370
|
|
|
372
371
|
Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**
|
|
373
372
|
|
package/lib/buf-object.js
CHANGED
|
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
function BUFObject(data, feed) {
|
|
9
8
|
if (this.isLast()) {
|
|
10
9
|
feed.close();
|
|
@@ -12,6 +11,7 @@ function BUFObject(data, feed) {
|
|
|
12
11
|
feed.send(Buffer.from(data));
|
|
13
12
|
}
|
|
14
13
|
}
|
|
14
|
+
|
|
15
15
|
/**
|
|
16
16
|
* Take `Mixed` and produce Buffer.
|
|
17
17
|
* For example, it's useful to send string to browser.
|
|
@@ -21,8 +21,6 @@ function BUFObject(data, feed) {
|
|
|
21
21
|
* @param {undefined} none
|
|
22
22
|
* @returns {Buffer}
|
|
23
23
|
*/
|
|
24
|
-
|
|
25
|
-
|
|
26
24
|
var _default = {
|
|
27
25
|
BUFObject
|
|
28
26
|
};
|
package/lib/csv-object.js
CHANGED
|
@@ -4,12 +4,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
function CSVObject(data, feed) {
|
|
9
8
|
if (this.isLast()) {
|
|
10
9
|
return feed.close();
|
|
11
10
|
}
|
|
12
|
-
|
|
13
11
|
if (!this.columns) {
|
|
14
12
|
this.columns = data.map(name => name.replace(/\./g, ''));
|
|
15
13
|
const countCols = {};
|
|
@@ -22,12 +20,10 @@ function CSVObject(data, feed) {
|
|
|
22
20
|
renamedCols[colname] = !renamedCols[colname] ? 1 : renamedCols[colname] + 1;
|
|
23
21
|
return colname + renamedCols[colname];
|
|
24
22
|
}
|
|
25
|
-
|
|
26
23
|
return colname;
|
|
27
24
|
});
|
|
28
25
|
return feed.end();
|
|
29
26
|
}
|
|
30
|
-
|
|
31
27
|
if (Array.isArray(data)) {
|
|
32
28
|
const obj = {};
|
|
33
29
|
data.forEach((item, index) => {
|
|
@@ -36,9 +32,9 @@ function CSVObject(data, feed) {
|
|
|
36
32
|
});
|
|
37
33
|
return feed.send(obj);
|
|
38
34
|
}
|
|
39
|
-
|
|
40
35
|
feed.end();
|
|
41
36
|
}
|
|
37
|
+
|
|
42
38
|
/**
|
|
43
39
|
* Take an `Array` of arrays and transform rows into objects.
|
|
44
40
|
*
|
|
@@ -101,8 +97,6 @@ function CSVObject(data, feed) {
|
|
|
101
97
|
* @param {undefined} none
|
|
102
98
|
* @returns {Object|Object[]}
|
|
103
99
|
*/
|
|
104
|
-
|
|
105
|
-
|
|
106
100
|
var _default = {
|
|
107
101
|
CSVObject
|
|
108
102
|
};
|
package/lib/csv-parse.js
CHANGED
|
@@ -4,19 +4,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _csvString = _interopRequireDefault(require("csv-string"));
|
|
9
|
-
|
|
10
8
|
var _streamWrite = _interopRequireDefault(require("stream-write"));
|
|
11
|
-
|
|
12
9
|
var _string_decoder = require("string_decoder");
|
|
13
|
-
|
|
14
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
-
|
|
16
11
|
function CSVParse(data, feed) {
|
|
17
12
|
const separator = this.getParam('separator');
|
|
18
13
|
const quote = this.getParam('quote');
|
|
19
|
-
|
|
20
14
|
if (!this.decoder) {
|
|
21
15
|
this.decoder = new _string_decoder.StringDecoder('utf8');
|
|
22
16
|
this.input = _csvString.default.createStream({
|
|
@@ -25,15 +19,14 @@ function CSVParse(data, feed) {
|
|
|
25
19
|
});
|
|
26
20
|
this.whenFinish = feed.flow(this.input);
|
|
27
21
|
}
|
|
28
|
-
|
|
29
22
|
if (this.isLast()) {
|
|
30
23
|
this.decoder.end();
|
|
31
24
|
this.whenFinish.finally(() => feed.close());
|
|
32
25
|
return this.input.end();
|
|
33
26
|
}
|
|
34
|
-
|
|
35
27
|
(0, _streamWrite.default)(this.input, Buffer.isBuffer(data) ? this.decoder.write(data) : data, () => feed.end());
|
|
36
28
|
}
|
|
29
|
+
|
|
37
30
|
/**
|
|
38
31
|
* Take `String` and parse it as CSV to generate arrays.
|
|
39
32
|
*
|
|
@@ -64,8 +57,6 @@ function CSVParse(data, feed) {
|
|
|
64
57
|
* @param {String} [quote=auto] to indicate the CSV quote.
|
|
65
58
|
* @returns {Array<String[]>}
|
|
66
59
|
*/
|
|
67
|
-
|
|
68
|
-
|
|
69
60
|
var _default = {
|
|
70
61
|
CSVParse
|
|
71
62
|
};
|
package/lib/csv-string.js
CHANGED
|
@@ -4,11 +4,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _csvString = _interopRequireDefault(require("csv-string"));
|
|
9
|
-
|
|
10
8
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
-
|
|
12
9
|
function strict(data, sep) {
|
|
13
10
|
const q = new RegExp('"', 'g');
|
|
14
11
|
let line = '';
|
|
@@ -19,19 +16,16 @@ function strict(data, sep) {
|
|
|
19
16
|
});
|
|
20
17
|
return line.concat('\r\n');
|
|
21
18
|
}
|
|
22
|
-
|
|
23
19
|
function CSVString(data, feed) {
|
|
24
20
|
const format = String(this.getParam('format', 'standard'));
|
|
25
21
|
const sep = String(this.getParam('separator', ';'));
|
|
26
22
|
const header = Boolean(this.getParam('header', true));
|
|
27
23
|
let func;
|
|
28
|
-
|
|
29
24
|
if (format === 'strict') {
|
|
30
25
|
func = strict;
|
|
31
26
|
} else {
|
|
32
27
|
func = _csvString.default.stringify;
|
|
33
28
|
}
|
|
34
|
-
|
|
35
29
|
if (this.isLast()) {
|
|
36
30
|
feed.close();
|
|
37
31
|
} else if (this.isFirst() && header) {
|
|
@@ -41,6 +35,7 @@ function CSVString(data, feed) {
|
|
|
41
35
|
feed.send(func(data, sep));
|
|
42
36
|
}
|
|
43
37
|
}
|
|
38
|
+
|
|
44
39
|
/**
|
|
45
40
|
* Take an array of objects and transform row into a string where each field is
|
|
46
41
|
* separated with a character.
|
|
@@ -78,8 +73,6 @@ function CSVString(data, feed) {
|
|
|
78
73
|
* @param {Boolean} [header=true] first line contains key name
|
|
79
74
|
* @returns {String}
|
|
80
75
|
*/
|
|
81
|
-
|
|
82
|
-
|
|
83
76
|
var _default = {
|
|
84
77
|
CSVString
|
|
85
78
|
};
|
package/lib/file-load.js
CHANGED
|
@@ -4,19 +4,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = FILELoad;
|
|
7
|
-
|
|
8
7
|
var _zlib = require("zlib");
|
|
9
|
-
|
|
10
8
|
var _fs = require("fs");
|
|
11
|
-
|
|
12
9
|
var _path = require("path");
|
|
13
|
-
|
|
14
10
|
var _os = require("os");
|
|
15
|
-
|
|
16
11
|
var _higherPath = _interopRequireDefault(require("higher-path"));
|
|
17
|
-
|
|
18
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
|
-
|
|
20
13
|
/**
|
|
21
14
|
* Take `Object` containing filename et throw content by chunk
|
|
22
15
|
*
|
|
@@ -55,17 +48,14 @@ async function FILELoad(data, feed) {
|
|
|
55
48
|
feed.close();
|
|
56
49
|
return;
|
|
57
50
|
}
|
|
58
|
-
|
|
59
51
|
const compress = this.getParam('compress', false);
|
|
60
52
|
const location = (0, _path.normalize)(this.getParam('location', '/'));
|
|
61
53
|
const locations = [(0, _higherPath.default)((0, _os.tmpdir)(), location), (0, _higherPath.default)(process.cwd(), location)];
|
|
62
54
|
const filename = locations.filter(Boolean).map(dir => (0, _path.resolve)(dir, String(data).trim())).filter(fil => (0, _fs.existsSync)(fil)).shift();
|
|
63
|
-
|
|
64
55
|
if (!filename) {
|
|
65
56
|
feed.stop(new Error('File location check failed.'));
|
|
66
57
|
return;
|
|
67
58
|
}
|
|
68
|
-
|
|
69
59
|
(0, _fs.accessSync)((0, _path.dirname)(filename), _fs.constants.R_OK | _fs.constants.W_OK);
|
|
70
60
|
(0, _fs.accessSync)(filename, _fs.constants.R_OK | _fs.constants.W_OK);
|
|
71
61
|
const stream = compress ? (0, _fs.createReadStream)(filename).pipe((0, _zlib.createGunzip)()) : (0, _fs.createReadStream)(filename);
|
package/lib/file-save.js
CHANGED
|
@@ -4,27 +4,16 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = FILESave;
|
|
7
|
-
|
|
8
7
|
var _fs = require("fs");
|
|
9
|
-
|
|
10
8
|
var _zlib = require("zlib");
|
|
11
|
-
|
|
12
9
|
var _path = _interopRequireDefault(require("path"));
|
|
13
|
-
|
|
14
10
|
var _os = require("os");
|
|
15
|
-
|
|
16
11
|
var _pathExists = _interopRequireDefault(require("path-exists"));
|
|
17
|
-
|
|
18
12
|
var _makeDir = _interopRequireDefault(require("make-dir"));
|
|
19
|
-
|
|
20
13
|
var _streamWrite = _interopRequireDefault(require("stream-write"));
|
|
21
|
-
|
|
22
14
|
var _debug = _interopRequireDefault(require("debug"));
|
|
23
|
-
|
|
24
15
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
25
|
-
|
|
26
16
|
const eol = '\n';
|
|
27
|
-
|
|
28
17
|
const toJSONL = line => JSON.stringify(line).concat(eol);
|
|
29
18
|
/**
|
|
30
19
|
* Take data, convert it to buffer and append it to file
|
|
@@ -63,30 +52,21 @@ const toJSONL = line => JSON.stringify(line).concat(eol);
|
|
|
63
52
|
* @param {Boolean} [compress=false] Enable gzip compression
|
|
64
53
|
* @returns {Object}
|
|
65
54
|
*/
|
|
66
|
-
|
|
67
|
-
|
|
68
55
|
function FILESave(data, feed) {
|
|
69
56
|
if (this.isFirst()) {
|
|
70
57
|
const identifier = String(this.getParam('identifier'));
|
|
71
|
-
|
|
72
58
|
const location = _path.default.normalize(this.getParam('location', (0, _os.tmpdir)()));
|
|
73
|
-
|
|
74
59
|
const compress = this.getParam('compress', false);
|
|
75
|
-
|
|
76
60
|
if (location.indexOf((0, _os.tmpdir)()) !== 0 && location.indexOf(process.cwd()) !== 0) {
|
|
77
61
|
feed.stop(new Error('File location check failed.'));
|
|
78
62
|
return;
|
|
79
63
|
}
|
|
80
|
-
|
|
81
64
|
if (!_pathExists.default.sync(location)) {
|
|
82
65
|
_makeDir.default.sync(location);
|
|
83
66
|
}
|
|
84
|
-
|
|
85
67
|
(0, _fs.accessSync)(location, _fs.constants.R_OK | _fs.constants.W_OK);
|
|
86
68
|
const name = compress ? `${identifier}.gz` : identifier;
|
|
87
|
-
|
|
88
69
|
const filename = _path.default.resolve(location, name);
|
|
89
|
-
|
|
90
70
|
this.input = compress ? (0, _zlib.createGzip)() : (0, _fs.createWriteStream)(filename);
|
|
91
71
|
this.whenFinish = new Promise((resolve, reject) => {
|
|
92
72
|
const output = compress ? this.input.pipe((0, _fs.createWriteStream)(filename)) : this.input;
|
|
@@ -100,7 +80,6 @@ function FILESave(data, feed) {
|
|
|
100
80
|
if (err) {
|
|
101
81
|
return reject(err);
|
|
102
82
|
}
|
|
103
|
-
|
|
104
83
|
return resolve({
|
|
105
84
|
filename,
|
|
106
85
|
...stat
|
|
@@ -109,15 +88,14 @@ function FILESave(data, feed) {
|
|
|
109
88
|
});
|
|
110
89
|
});
|
|
111
90
|
}
|
|
112
|
-
|
|
113
91
|
if (this.isLast()) {
|
|
114
92
|
this.input.end();
|
|
115
|
-
|
|
93
|
+
this.whenFinish.then(stats => feed.write(stats)).catch(err => feed.stop(err)).finally(() => feed.close());
|
|
94
|
+
return;
|
|
116
95
|
}
|
|
117
|
-
|
|
118
96
|
const jsonl = Boolean(this.getParam('jsonl', false));
|
|
119
97
|
const bufContent = this.getParam('content', data);
|
|
120
98
|
const bufFunc = jsonl ? toJSONL : String;
|
|
121
|
-
const buf = Buffer.from(bufFunc(bufContent));
|
|
99
|
+
const buf = Buffer.isBuffer(bufContent) ? bufContent : Buffer.from(bufFunc(bufContent));
|
|
122
100
|
(0, _streamWrite.default)(this.input, buf, () => feed.end());
|
|
123
101
|
}
|
package/lib/index.js
CHANGED
|
@@ -4,73 +4,39 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _bufObject = _interopRequireDefault(require("./buf-object"));
|
|
9
|
-
|
|
10
8
|
var _objCount = _interopRequireDefault(require("./obj-count"));
|
|
11
|
-
|
|
12
9
|
var _objNamespaces = _interopRequireDefault(require("./obj-namespaces"));
|
|
13
|
-
|
|
14
10
|
var _objStandardize = _interopRequireDefault(require("./obj-standardize"));
|
|
15
|
-
|
|
16
11
|
var _objFlatten = _interopRequireDefault(require("./obj-flatten"));
|
|
17
|
-
|
|
18
12
|
var _txtConcat = _interopRequireDefault(require("./txt-concat"));
|
|
19
|
-
|
|
20
13
|
var _txtObject = _interopRequireDefault(require("./txt-object"));
|
|
21
|
-
|
|
22
14
|
var _txtParse = _interopRequireDefault(require("./txt-parse"));
|
|
23
|
-
|
|
24
15
|
var _txtSentences = _interopRequireDefault(require("./txt-sentences"));
|
|
25
|
-
|
|
26
16
|
var _txtInflection = _interopRequireDefault(require("./txt-inflection"));
|
|
27
|
-
|
|
28
17
|
var _xmlParse = _interopRequireDefault(require("./xml-parse"));
|
|
29
|
-
|
|
30
18
|
var _xmlString = _interopRequireDefault(require("./xml-string"));
|
|
31
|
-
|
|
32
19
|
var _xmlConvert = _interopRequireDefault(require("./xml-convert"));
|
|
33
|
-
|
|
34
20
|
var _csvParse = _interopRequireDefault(require("./csv-parse"));
|
|
35
|
-
|
|
36
21
|
var _csvObject = _interopRequireDefault(require("./csv-object"));
|
|
37
|
-
|
|
38
22
|
var _csvString = _interopRequireDefault(require("./csv-string"));
|
|
39
|
-
|
|
40
23
|
var _jsonParse = _interopRequireDefault(require("./json-parse"));
|
|
41
|
-
|
|
42
24
|
var _jsonString = _interopRequireDefault(require("./json-string"));
|
|
43
|
-
|
|
44
25
|
var _urlFetch = _interopRequireDefault(require("./url-fetch"));
|
|
45
|
-
|
|
46
26
|
var _urlParse = _interopRequireDefault(require("./url-parse"));
|
|
47
|
-
|
|
48
27
|
var _urlRequest = _interopRequireDefault(require("./url-request"));
|
|
49
|
-
|
|
50
28
|
var _urlPagination = _interopRequireDefault(require("./url-pagination"));
|
|
51
|
-
|
|
52
29
|
var _urlString = _interopRequireDefault(require("./url-string"));
|
|
53
|
-
|
|
54
30
|
var _urlStream = _interopRequireDefault(require("./url-stream"));
|
|
55
|
-
|
|
56
31
|
var _urlConnect = _interopRequireDefault(require("./url-connect"));
|
|
57
|
-
|
|
58
32
|
var _txtZip = _interopRequireDefault(require("./txt-zip"));
|
|
59
|
-
|
|
60
33
|
var _zipExtract = _interopRequireDefault(require("./zip-extract"));
|
|
61
|
-
|
|
62
34
|
var _tarExtract = _interopRequireDefault(require("./tar-extract"));
|
|
63
|
-
|
|
64
35
|
var _tarDump = _interopRequireDefault(require("./tar-dump"));
|
|
65
|
-
|
|
66
36
|
var _iniString = _interopRequireDefault(require("./ini-string"));
|
|
67
|
-
|
|
68
37
|
var _fileSave = _interopRequireDefault(require("./file-save"));
|
|
69
|
-
|
|
70
38
|
var _fileLoad = _interopRequireDefault(require("./file-load"));
|
|
71
|
-
|
|
72
39
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
73
|
-
|
|
74
40
|
const funcs = {
|
|
75
41
|
BUFObject: _bufObject.default,
|
|
76
42
|
OBJCount: _objCount.default,
|
package/lib/ini-string.js
CHANGED
|
@@ -4,14 +4,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
function INIString(data, feed) {
|
|
9
8
|
if (this.isLast()) {
|
|
10
9
|
return feed.close();
|
|
11
10
|
}
|
|
12
|
-
|
|
13
11
|
const cr = this.cr || ''; // avoid cr at the begin
|
|
14
|
-
|
|
15
12
|
let output = [];
|
|
16
13
|
Object.keys(data).forEach(key => {
|
|
17
14
|
if (typeof data[key] === 'object') {
|
|
@@ -24,6 +21,7 @@ function INIString(data, feed) {
|
|
|
24
21
|
this.cr = '\n';
|
|
25
22
|
feed.send(output.join(this.cr).concat(this.cr));
|
|
26
23
|
}
|
|
24
|
+
|
|
27
25
|
/**
|
|
28
26
|
* Take `Object` and generate INI
|
|
29
27
|
*
|
|
@@ -75,8 +73,6 @@ function INIString(data, feed) {
|
|
|
75
73
|
* @name INIString
|
|
76
74
|
* @returns {String}
|
|
77
75
|
*/
|
|
78
|
-
|
|
79
|
-
|
|
80
76
|
var _default = {
|
|
81
77
|
INIString
|
|
82
78
|
};
|
package/lib/json-parse.js
CHANGED
|
@@ -4,37 +4,19 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _JSONStream = _interopRequireDefault(require("JSONStream"));
|
|
9
|
-
|
|
10
|
-
var _stream = require("stream");
|
|
11
|
-
|
|
12
|
-
var _yajsonStream = _interopRequireDefault(require("yajson-stream"));
|
|
13
|
-
|
|
14
8
|
var _streamWrite = _interopRequireDefault(require("stream-write"));
|
|
15
|
-
|
|
16
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
|
-
|
|
18
10
|
function JSONParse(data, feed) {
|
|
19
11
|
if (this.isFirst()) {
|
|
20
|
-
const legacy = this.getParam('legacy', true);
|
|
21
12
|
const separator = this.getParam('separator', '*');
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
this.input = _JSONStream.default.parse(separator);
|
|
25
|
-
this.whenFinish = feed.flow(this.input);
|
|
26
|
-
} else {
|
|
27
|
-
this.input = new _stream.PassThrough();
|
|
28
|
-
const stream = this.input.pipe(this.ezs.toBuffer()).pipe((0, _yajsonStream.default)(separator)).pipe(this.ezs((d, f) => f.send(d ? d.value : d)));
|
|
29
|
-
this.whenFinish = feed.flow(stream);
|
|
30
|
-
}
|
|
13
|
+
this.input = _JSONStream.default.parse(separator);
|
|
14
|
+
this.whenFinish = feed.flow(this.input);
|
|
31
15
|
}
|
|
32
|
-
|
|
33
16
|
if (this.isLast()) {
|
|
34
17
|
this.whenFinish.finally(() => feed.close());
|
|
35
18
|
return this.input.end();
|
|
36
19
|
}
|
|
37
|
-
|
|
38
20
|
(0, _streamWrite.default)(this.input, data, () => feed.end());
|
|
39
21
|
}
|
|
40
22
|
/**
|
|
@@ -79,11 +61,8 @@ function JSONParse(data, feed) {
|
|
|
79
61
|
*
|
|
80
62
|
* @name JSONParse
|
|
81
63
|
* @param {String} [separator="*"] to split at every JSONPath found
|
|
82
|
-
* @param {String} [legacy=true] use legacy or newer parser (separator should be different)
|
|
83
64
|
* @returns {Object}
|
|
84
65
|
*/
|
|
85
|
-
|
|
86
|
-
|
|
87
66
|
var _default = {
|
|
88
67
|
JSONParse
|
|
89
68
|
};
|
package/lib/json-string.js
CHANGED
|
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = JSONString;
|
|
7
|
-
|
|
8
7
|
/**
|
|
9
8
|
* Take an `Object` and generate a JSON string.
|
|
10
9
|
*
|
|
@@ -33,17 +32,14 @@ function JSONString(data, feed) {
|
|
|
33
32
|
const openWith = wrap ? '[' : '';
|
|
34
33
|
const closeWith = wrap ? ']' : '';
|
|
35
34
|
let output = '';
|
|
36
|
-
|
|
37
35
|
if (this.isFirst()) {
|
|
38
36
|
output = openWith;
|
|
39
37
|
} else {
|
|
40
38
|
output = separator;
|
|
41
39
|
}
|
|
42
|
-
|
|
43
40
|
if (this.isLast()) {
|
|
44
41
|
feed.write(closeWith);
|
|
45
42
|
return feed.close();
|
|
46
43
|
}
|
|
47
|
-
|
|
48
44
|
return feed.send(output.concat(JSON.stringify(data, null, spaces)));
|
|
49
45
|
}
|
package/lib/obj-count.js
CHANGED
|
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
function OBJCount(data, feed) {
|
|
9
8
|
if (this.isLast()) {
|
|
10
9
|
feed.send(this.getIndex() - 1);
|
|
@@ -12,6 +11,7 @@ function OBJCount(data, feed) {
|
|
|
12
11
|
feed.end();
|
|
13
12
|
}
|
|
14
13
|
}
|
|
14
|
+
|
|
15
15
|
/**
|
|
16
16
|
* Count how many objects are received, and yield the total.
|
|
17
17
|
*
|
|
@@ -31,8 +31,6 @@ function OBJCount(data, feed) {
|
|
|
31
31
|
* @param {undefined} none
|
|
32
32
|
* @returns {Number}
|
|
33
33
|
*/
|
|
34
|
-
|
|
35
|
-
|
|
36
34
|
var _default = {
|
|
37
35
|
OBJCount
|
|
38
36
|
};
|
package/lib/obj-flatten.js
CHANGED
|
@@ -4,13 +4,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = OBJFlatten;
|
|
7
|
-
|
|
8
7
|
var _flat = _interopRequireWildcard(require("flat"));
|
|
9
|
-
|
|
10
|
-
function
|
|
11
|
-
|
|
12
|
-
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
13
|
-
|
|
8
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
9
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
14
10
|
/**
|
|
15
11
|
* Flatten an `Object` with a path delimiting character.
|
|
16
12
|
*
|
|
@@ -44,15 +40,12 @@ function OBJFlatten(data, feed) {
|
|
|
44
40
|
if (this.isLast()) {
|
|
45
41
|
return feed.close();
|
|
46
42
|
}
|
|
47
|
-
|
|
48
43
|
const opts = {
|
|
49
44
|
delimiter: String(this.getParam('separator', '/')),
|
|
50
45
|
safe: Boolean(this.getParam('safe', true))
|
|
51
46
|
};
|
|
52
|
-
|
|
53
47
|
if (this.getParam('reverse', false)) {
|
|
54
48
|
return feed.send((0, _flat.unflatten)(data, opts));
|
|
55
49
|
}
|
|
56
|
-
|
|
57
50
|
return feed.send((0, _flat.default)(data, opts));
|
|
58
51
|
}
|
package/lib/obj-namespaces.js
CHANGED
|
@@ -4,17 +4,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = OBJNamespaces;
|
|
7
|
-
|
|
8
7
|
var _lodash = _interopRequireDefault(require("lodash.zipobject"));
|
|
9
|
-
|
|
10
8
|
var _lodash2 = _interopRequireDefault(require("lodash.escaperegexp"));
|
|
11
|
-
|
|
12
9
|
var _lodash3 = _interopRequireDefault(require("lodash.mapkeys"));
|
|
13
|
-
|
|
14
10
|
var _lodash4 = _interopRequireDefault(require("lodash.mapvalues"));
|
|
15
|
-
|
|
16
11
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
|
-
|
|
18
12
|
/**
|
|
19
13
|
* Take `Object` and throw the same object, all keys parsed to replace namespaces with their prefixes
|
|
20
14
|
*
|
|
@@ -81,7 +75,6 @@ function OBJNamespaces(data, feed) {
|
|
|
81
75
|
if (this.isLast()) {
|
|
82
76
|
return feed.close();
|
|
83
77
|
}
|
|
84
|
-
|
|
85
78
|
if (this.isFirst()) {
|
|
86
79
|
const prefixes = [].concat(this.getParam('prefix')).map(x => String(x).trim()).filter(Boolean);
|
|
87
80
|
const namespaces = [].concat(this.getParam('namespace')).filter(Boolean).slice(0, prefixes.length).map(x => String(x).trim());
|
|
@@ -89,19 +82,15 @@ function OBJNamespaces(data, feed) {
|
|
|
89
82
|
this.expression = RegExp(Object.keys(this.mapping).map(_lodash2.default).join('|'), 'g');
|
|
90
83
|
this.references = [].concat(this.getParam('reference')).filter(Boolean).map(x => RegExp(String(x).trim(), 'g'));
|
|
91
84
|
}
|
|
92
|
-
|
|
93
85
|
const result = (0, _lodash3.default)(data, (val, key) => String(key).replace(this.expression, matched => this.mapping[matched]));
|
|
94
|
-
|
|
95
86
|
if (this.references.length > 0) {
|
|
96
87
|
const result1 = (0, _lodash4.default)(result, (value, key) => {
|
|
97
88
|
if (this.references.some(x => key.search(x) !== -1)) {
|
|
98
89
|
return String(value).replace(this.expression, matched => this.mapping[matched]);
|
|
99
90
|
}
|
|
100
|
-
|
|
101
91
|
return value;
|
|
102
92
|
});
|
|
103
93
|
return feed.send(result1);
|
|
104
94
|
}
|
|
105
|
-
|
|
106
95
|
return feed.send(result);
|
|
107
96
|
}
|
package/lib/obj-standardize.js
CHANGED
|
@@ -4,20 +4,14 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _tmpFilepath = _interopRequireDefault(require("tmp-filepath"));
|
|
9
|
-
|
|
10
8
|
var _fs = _interopRequireDefault(require("fs"));
|
|
11
|
-
|
|
12
9
|
var _streamWrite = _interopRequireDefault(require("stream-write"));
|
|
13
|
-
|
|
14
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
-
|
|
16
11
|
function normalize(data, feed) {
|
|
17
12
|
if (this.isLast()) {
|
|
18
13
|
return feed.close();
|
|
19
14
|
}
|
|
20
|
-
|
|
21
15
|
const struct = this.getEnv();
|
|
22
16
|
const vv = {};
|
|
23
17
|
struct.forEach(k => {
|
|
@@ -29,27 +23,21 @@ function normalize(data, feed) {
|
|
|
29
23
|
});
|
|
30
24
|
return feed.send(vv);
|
|
31
25
|
}
|
|
32
|
-
|
|
33
26
|
function cleanup(data, feed) {
|
|
34
27
|
if (this.isLast()) {
|
|
35
28
|
const filename = this.getParam('filename');
|
|
36
|
-
|
|
37
29
|
if (filename) {
|
|
38
30
|
return _fs.default.unlink(filename, () => feed.close());
|
|
39
31
|
}
|
|
40
|
-
|
|
41
32
|
return feed.close();
|
|
42
33
|
}
|
|
43
|
-
|
|
44
34
|
return feed.send(data);
|
|
45
35
|
}
|
|
46
|
-
|
|
47
36
|
function OBJStandardize(data, feed) {
|
|
48
37
|
const self = this;
|
|
49
38
|
const {
|
|
50
39
|
ezs
|
|
51
40
|
} = this;
|
|
52
|
-
|
|
53
41
|
if (!self.tmpFile) {
|
|
54
42
|
self.tmpFile = (0, _tmpFilepath.default)('.bin');
|
|
55
43
|
self.struct = [];
|
|
@@ -57,14 +45,12 @@ function OBJStandardize(data, feed) {
|
|
|
57
45
|
self.tmpStream = self.tmpInput.pipe(ezs('pack')).pipe(ezs.toBuffer()).pipe(ezs.compress()).pipe(_fs.default.createWriteStream(self.tmpFile));
|
|
58
46
|
self.tmpHandle = new Promise((resolve, reject) => self.tmpStream.on('error', reject).on('close', resolve));
|
|
59
47
|
}
|
|
60
|
-
|
|
61
48
|
if (self.isLast()) {
|
|
62
49
|
self.tmpInput.end();
|
|
63
50
|
return self.tmpHandle.then(() => feed.flow(_fs.default.createReadStream(self.tmpFile).pipe(ezs.uncompress()).pipe(ezs('unpack')).pipe(ezs(normalize, {}, self.struct)).pipe(ezs(cleanup, {
|
|
64
51
|
filename: self.tmpFile
|
|
65
52
|
})))).catch(e => feed.stop(e));
|
|
66
53
|
}
|
|
67
|
-
|
|
68
54
|
Object.keys(data).forEach(k => {
|
|
69
55
|
if (self.struct.indexOf(k) === -1) {
|
|
70
56
|
self.struct.push(k);
|
|
@@ -72,6 +58,7 @@ function OBJStandardize(data, feed) {
|
|
|
72
58
|
});
|
|
73
59
|
(0, _streamWrite.default)(self.tmpInput, data, () => feed.end());
|
|
74
60
|
}
|
|
61
|
+
|
|
75
62
|
/**
|
|
76
63
|
* Standardize `Object`s so that each object have the same keys.
|
|
77
64
|
*
|
|
@@ -96,8 +83,6 @@ function OBJStandardize(data, feed) {
|
|
|
96
83
|
* @param {undefined} none
|
|
97
84
|
* @returns {Object}
|
|
98
85
|
*/
|
|
99
|
-
|
|
100
|
-
|
|
101
86
|
var _default = {
|
|
102
87
|
OBJStandardize
|
|
103
88
|
};
|
package/lib/request.js
CHANGED
|
@@ -4,23 +4,17 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _fetchWithProxy = _interopRequireDefault(require("fetch-with-proxy"));
|
|
9
|
-
|
|
10
8
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
-
|
|
12
9
|
const request = (url, parameters) => async () => {
|
|
13
10
|
const response = await (0, _fetchWithProxy.default)(url, parameters);
|
|
14
|
-
|
|
15
11
|
if (!response.ok) {
|
|
16
12
|
const err = new Error(response.statusText);
|
|
17
13
|
const text = await response.text();
|
|
18
14
|
err.responseText = text;
|
|
19
15
|
throw err;
|
|
20
16
|
}
|
|
21
|
-
|
|
22
17
|
return response;
|
|
23
18
|
};
|
|
24
|
-
|
|
25
19
|
var _default = request;
|
|
26
20
|
exports.default = _default;
|