@cjser/neat-csv 7.0.0-cjser.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.
@@ -0,0 +1,52 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+
29
+ // packages/@cjser/neat-csv.tmp-26-1778153652480/index.js
30
+ var index_exports = {};
31
+ __export(index_exports, {
32
+ default: () => neatCsv
33
+ });
34
+ module.exports = __toCommonJS(index_exports);
35
+ var import_node_util = require("node:util");
36
+ var import_node_stream = require("node:stream");
37
+ var import_node_process = __toESM(require("node:process"), 1);
38
+ var import_node_buffer = require("node:buffer");
39
+ var import_csv_parser = __toESM(require("csv-parser"), 1);
40
+ var import_get_stream = __toESM(require("get-stream"), 1);
41
+ var pipelinePromise = (0, import_node_util.promisify)(import_node_stream.pipeline);
42
+ async function neatCsv(data, options) {
43
+ if (typeof data === "string" || import_node_buffer.Buffer.isBuffer(data)) {
44
+ data = import_node_stream.Readable.from(data);
45
+ }
46
+ const parserStream = (0, import_csv_parser.default)(options);
47
+ if (Number(import_node_process.default.versions.node.split(".")[0]) >= 16) {
48
+ return import_get_stream.default.array(data.pipe(parserStream));
49
+ }
50
+ await pipelinePromise([data, parserStream]);
51
+ return import_get_stream.default.array(parserStream);
52
+ }
package/index.d.ts ADDED
@@ -0,0 +1,30 @@
1
+ import {Buffer} from 'node:buffer';
2
+ import {Readable as ReadableStream} from 'node:stream';
3
+ import {Options} from 'csv-parser';
4
+
5
+ export type Row = Record<string, string>;
6
+
7
+ /**
8
+ Fast CSV parser.
9
+
10
+ Convenience wrapper around the super-fast streaming [`csv-parser`](https://github.com/mafintosh/csv-parser) module. Use that one if you want streamed parsing.
11
+
12
+ @param data - The CSV data to parse.
13
+ @param options - See the [`csv-parser` options](https://github.com/mafintosh/csv-parser#options).
14
+
15
+ @example
16
+ ```
17
+ import neatCsv from '@cjser/neat-csv';
18
+
19
+ const csv = 'type,part\nunicorn,horn\nrainbow,pink';
20
+
21
+ console.log(await neatCsv(csv));
22
+ //=> [{type: 'unicorn', part: 'horn'}, {type: 'rainbow', part: 'pink'}]
23
+ ```
24
+ */
25
+ export default function neatCsv<RowType = Row>(
26
+ data: string | Buffer | ReadableStream,
27
+ options?: Options
28
+ ): Promise<RowType[]>;
29
+
30
+ export {Options} from 'csv-parser';
package/index.js ADDED
@@ -0,0 +1,25 @@
1
+ import {promisify} from 'node:util';
2
+ import {Readable as ReadableStream, pipeline} from 'node:stream';
3
+ import process from 'node:process';
4
+ import {Buffer} from 'node:buffer';
5
+ import csvParser from 'csv-parser';
6
+ import getStream from 'get-stream';
7
+ // TODO: Use `import {pipeline as pipelinePromise} from 'node:stream/promises';` when targeting Node.js 16.
8
+
9
+ const pipelinePromise = promisify(pipeline);
10
+
11
+ export default async function neatCsv(data, options) {
12
+ if (typeof data === 'string' || Buffer.isBuffer(data)) {
13
+ data = ReadableStream.from(data);
14
+ }
15
+
16
+ const parserStream = csvParser(options);
17
+
18
+ // Node.js 16 has a bug with `.pipeline` for large strings. It works fine in Node.js 14 and 12.
19
+ if (Number(process.versions.node.split('.')[0]) >= 16) {
20
+ return getStream.array(data.pipe(parserStream));
21
+ }
22
+
23
+ await pipelinePromise([data, parserStream]);
24
+ return getStream.array(parserStream);
25
+ }
package/license ADDED
@@ -0,0 +1,9 @@
1
+ MIT License
2
+
3
+ Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/package.json ADDED
@@ -0,0 +1,78 @@
1
+ {
2
+ "name": "@cjser/neat-csv",
3
+ "version": "7.0.0-cjser.2",
4
+ "description": "Fast CSV parser",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://code.moenext.com/3rdeye/cjser.git"
9
+ },
10
+ "funding": "https://github.com/sponsors/sindresorhus",
11
+ "author": {
12
+ "name": "Sindre Sorhus",
13
+ "email": "sindresorhus@gmail.com",
14
+ "url": "https://sindresorhus.com"
15
+ },
16
+ "type": "module",
17
+ "exports": {
18
+ "require": "./dist-cjser/index.cjs",
19
+ "default": "./index.js"
20
+ },
21
+ "engines": {
22
+ "node": "^12.20.0 || ^14.13.1 || >=16.0.0"
23
+ },
24
+ "scripts": {
25
+ "test": "xo && ava && tsd"
26
+ },
27
+ "files": [
28
+ "index.js",
29
+ "index.d.ts",
30
+ "dist-cjser"
31
+ ],
32
+ "keywords": [
33
+ "parse",
34
+ "csv",
35
+ "comma",
36
+ "separated",
37
+ "values",
38
+ "tab",
39
+ "delimiter",
40
+ "separator",
41
+ "text",
42
+ "string",
43
+ "buffer",
44
+ "stream",
45
+ "parser"
46
+ ],
47
+ "dependencies": {
48
+ "csv-parser": "^3.0.0",
49
+ "get-stream": "^6.0.1"
50
+ },
51
+ "devDependencies": {
52
+ "ava": "^3.15.0",
53
+ "tsd": "^0.18.0",
54
+ "xo": "^0.45.0"
55
+ },
56
+ "main": "./dist-cjser/index.cjs",
57
+ "cjser": {
58
+ "sourceVersion": "7.0.0",
59
+ "cjserVersion": 2,
60
+ "original": {
61
+ "name": "neat-csv",
62
+ "version": "7.0.0",
63
+ "exports": "./index.js",
64
+ "repository": "sindresorhus/neat-csv",
65
+ "dependencies": {
66
+ "csv-parser": "^3.0.0",
67
+ "get-stream": "^6.0.1"
68
+ },
69
+ "files": [
70
+ "index.js",
71
+ "index.d.ts"
72
+ ],
73
+ "scripts": {
74
+ "test": "xo && ava && tsd"
75
+ }
76
+ }
77
+ }
78
+ }
package/readme.md ADDED
@@ -0,0 +1,47 @@
1
+ # neat-csv
2
+
3
+ > Fast CSV parser
4
+
5
+ Convenience wrapper around the super-fast streaming [`csv-parser`](https://github.com/mafintosh/csv-parser) module. Use that one if you want streamed parsing.
6
+
7
+ Parsing-related issues should be reported to [`csv-parser`](https://github.com/mafintosh/csv-parser/issues).
8
+
9
+ ## Install
10
+
11
+ ```sh
12
+ npm install neat-csv
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ ```js
18
+ import neatCsv from 'neat-csv';
19
+
20
+ const csv = 'type,part\nunicorn,horn\nrainbow,pink';
21
+
22
+ console.log(await neatCsv(csv));
23
+ //=> [{type: 'unicorn', part: 'horn'}, {type: 'rainbow', part: 'pink'}]
24
+ ```
25
+
26
+ ## API
27
+
28
+ ### neatCsv(data, options?)
29
+
30
+ Returns a `Promise<object[]>` with the parsed CSV.
31
+
32
+ #### data
33
+
34
+ Type: `string | Buffer | stream.Readable`
35
+
36
+ The CSV data to parse.
37
+
38
+ #### options
39
+
40
+ Type: `object`
41
+
42
+ See the [`csv-parser` options](https://github.com/mafintosh/csv-parser#options).
43
+
44
+ ## cjser
45
+
46
+ This package is a CommonJS-compatible build generated by cjser for projects that still need `require()` support. The source version matches the original npm package version, with a cjser prerelease suffix for this generated build.
47
+ Original repository: https://github.com/sindresorhus/neat-csv