@lp-labs/csv-line-parser 0.0.0-stage → 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Libin Prasanth
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,48 @@
1
- # Temporary Holding Version
1
+ # @lp-labs/csv-line-parser
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Parses one comma-separated CSV record with quoted fields.
4
+
5
+ Original, standalone MIT TypeScript implementation with **zero runtime or peer dependencies**. ESM/CommonJS exports and separate declarations; Node18+ and compatible ES2022 browsers. No service, filesystem, network, clock or browser globals accessed on import. Compiler/formatter dependencies are development-only.
6
+
7
+ ## Install
8
+
9
+ ```sh
10
+ npm install @lp-labs/csv-line-parser
11
+ ```
12
+
13
+ ## Working example
14
+
15
+ ```js
16
+ import { parseCsvLine } from '@lp-labs/csv-line-parser';
17
+ console.log(parseCsvLine('Ada,42,"hello, world"'));
18
+ ```
19
+
20
+ CommonJS: `const api = require('@lp-labs/csv-line-parser')`.
21
+
22
+ ## Behavior, customization and limits
23
+
24
+ Supports commas and doubled quote escapes inside quoted fields and rejects quotes in unquoted fields or unterminated quoted fields. It parses one line only; multiline records and dialect options are outside scope.
25
+
26
+ Use the explicit function arguments and public types below to customize the documented behavior. There are no hidden environment settings or sibling-library requirements. Array inputs must be dense; sparse entries are invalid. Inputs are validated before a successful result is returned. Outputs do not mutate caller-owned inputs. Hostile proxies/getters and concurrent mutation are outside the contract.
27
+
28
+ ## Errors and integration
29
+
30
+ Invalid data never produces an empty success-shaped substitute. TypeError reports incompatible runtime types/nonfinite numbers; RangeError reports unsupported ranges, invalid syntax, inconsistent states and exceeded budgets. Functions that explicitly return null, false or empty arrays describe those legitimate outcomes above. Errors propagate to callers; UI applications should catch at their boundary and visibly notify users. Numerical calculations use JavaScript IEEE754 unless the API explicitly uses bigint; compare approximate numerical results with application-appropriate tolerances.
31
+
32
+ ## Complete public API
33
+
34
+ ```ts
35
+ export declare function parseCsvLine(line: string): string[];
36
+ ```
37
+
38
+ ## Performance and portability
39
+
40
+ Complexity and resource ceilings are specified above. Buffered synchronous algorithms do not create workers or timers; callers can move expensive work to their own worker. Limits are enforced, not silently truncated. No runtime imports from any other library. No compatibility or completeness claims beyond the stated scope.
41
+
42
+ ## Support
43
+
44
+ If this library is useful to you, consider supporting its maintenance with a [donation via PayPal](https://www.paypal.me/LibinPrasanth).
45
+
46
+ ## Author
47
+
48
+ Created by [Libin Prasanth](https://www.linkedin.com/in/libinprasanth/). Connect on LinkedIn for updates and discussion.
@@ -0,0 +1 @@
1
+ export declare function parseCsvLine(line: string): string[];
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseCsvLine = parseCsvLine;
4
+ function parseCsvLine(line) {
5
+ if (typeof line !== 'string')
6
+ throw new TypeError('Expected CSV line');
7
+ const out = [];
8
+ let i = 0;
9
+ while (true) {
10
+ let value = '';
11
+ if (line[i] === '"') {
12
+ i++;
13
+ let closed = false;
14
+ while (i < line.length) {
15
+ if (line[i] === '"') {
16
+ if (line[i + 1] === '"') {
17
+ value += '"';
18
+ i += 2;
19
+ }
20
+ else {
21
+ i++;
22
+ closed = true;
23
+ break;
24
+ }
25
+ }
26
+ else
27
+ value += line[i++];
28
+ }
29
+ if (!closed)
30
+ throw new SyntaxError('Unterminated quoted field');
31
+ if (i < line.length && line[i] !== ',')
32
+ throw new SyntaxError('Unexpected text after quoted field');
33
+ }
34
+ else {
35
+ while (i < line.length && line[i] !== ',') {
36
+ if (line[i] === '"')
37
+ throw new SyntaxError('Quote inside unquoted field');
38
+ value += line[i++];
39
+ }
40
+ }
41
+ out.push(value);
42
+ if (i >= line.length)
43
+ break;
44
+ i++;
45
+ if (i === line.length) {
46
+ out.push('');
47
+ break;
48
+ }
49
+ }
50
+ return out;
51
+ }
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}
@@ -0,0 +1 @@
1
+ export declare function parseCsvLine(line: string): string[];
@@ -0,0 +1,48 @@
1
+ export function parseCsvLine(line) {
2
+ if (typeof line !== 'string')
3
+ throw new TypeError('Expected CSV line');
4
+ const out = [];
5
+ let i = 0;
6
+ while (true) {
7
+ let value = '';
8
+ if (line[i] === '"') {
9
+ i++;
10
+ let closed = false;
11
+ while (i < line.length) {
12
+ if (line[i] === '"') {
13
+ if (line[i + 1] === '"') {
14
+ value += '"';
15
+ i += 2;
16
+ }
17
+ else {
18
+ i++;
19
+ closed = true;
20
+ break;
21
+ }
22
+ }
23
+ else
24
+ value += line[i++];
25
+ }
26
+ if (!closed)
27
+ throw new SyntaxError('Unterminated quoted field');
28
+ if (i < line.length && line[i] !== ',')
29
+ throw new SyntaxError('Unexpected text after quoted field');
30
+ }
31
+ else {
32
+ while (i < line.length && line[i] !== ',') {
33
+ if (line[i] === '"')
34
+ throw new SyntaxError('Quote inside unquoted field');
35
+ value += line[i++];
36
+ }
37
+ }
38
+ out.push(value);
39
+ if (i >= line.length)
40
+ break;
41
+ i++;
42
+ if (i === line.length) {
43
+ out.push('');
44
+ break;
45
+ }
46
+ }
47
+ return out;
48
+ }
package/package.json CHANGED
@@ -1,6 +1,63 @@
1
1
  {
2
2
  "name": "@lp-labs/csv-line-parser",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "Parses one comma-separated CSV record with quoted fields.",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "main": "./dist/cjs/index.js",
8
+ "module": "./dist/esm/index.js",
9
+ "types": "./dist/esm/index.d.ts",
10
+ "exports": {
11
+ ".": {
12
+ "import": {
13
+ "types": "./dist/esm/index.d.ts",
14
+ "default": "./dist/esm/index.js"
15
+ },
16
+ "require": {
17
+ "types": "./dist/cjs/index.d.ts",
18
+ "default": "./dist/cjs/index.js"
19
+ }
20
+ },
21
+ "./package.json": "./package.json"
22
+ },
23
+ "files": [
24
+ "dist",
25
+ "README.md",
26
+ "LICENSE"
27
+ ],
28
+ "sideEffects": false,
29
+ "engines": {
30
+ "node": ">=18"
31
+ },
32
+ "scripts": {
33
+ "build": "node scripts/build.mjs",
34
+ "typecheck": "npm run build && node scripts/check-types.mjs",
35
+ "test": "npm run build && node --test tests/*.test.mjs",
36
+ "format": "prettier --write src scripts tests *.json README.md",
37
+ "format:check": "prettier --check src scripts tests *.json README.md",
38
+ "prepack": "npm run build"
39
+ },
40
+ "devDependencies": {
41
+ "typescript": "^5.9.3",
42
+ "prettier": "^3.6.2"
43
+ },
44
+ "prettier": {
45
+ "singleQuote": true,
46
+ "semi": true,
47
+ "trailingComma": "all",
48
+ "printWidth": 100,
49
+ "endOfLine": "lf"
50
+ },
51
+ "publishConfig": {
52
+ "access": "public",
53
+ "registry": "https://registry.npmjs.org/"
54
+ },
55
+ "author": {
56
+ "name": "Libin Prasanth",
57
+ "url": "https://www.linkedin.com/in/libinprasanth/"
58
+ },
59
+ "funding": {
60
+ "type": "paypal",
61
+ "url": "https://www.paypal.me/LibinPrasanth"
62
+ }
63
+ }