Skip to content

Commit f2090d5

Browse files
authored
type newline result meta field as Newline, and export Newline type (#19)
1 parent a3808d1 commit f2090d5

10 files changed

Lines changed: 17 additions & 11 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# CHANGELOG
22

3+
## [0.0.5]
4+
5+
- export Newline type
6+
37
## [0.0.4]
48

59
- export parse result types

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "csv-range",
3-
"version": "0.0.4",
3+
"version": "0.0.5",
44
"description": "Parse ranges of a CSV file.",
55
"type": "module",
66
"license": "MIT",

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
export { parseText } from './text'
2-
export type { ParseError, ParseMeta, ParseResult } from './types'
2+
export type { Newline, ParseError, ParseMeta, ParseResult } from './types'
33
export { parseURL } from './url'
44
export { testEmptyLine } from './utils'

src/options/delimiter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { parse } from '../parser'
2+
import type { Newline } from '../types'
23
import { testEmptyLine } from '../utils'
34
import { BAD_DELIMITERS, RECORD_SEP, UNIT_SEP } from './constants'
4-
import type { Newline } from './newline'
55

66
/**
77
* Validates the delimiter

src/options/newline.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1+
import type { Newline } from '../types'
12
import { escapeRegExp } from '../utils'
23

3-
export type Newline = '\n' | '\r' | '\r\n'
4-
54
/**
65
* Returns the newline string to be used in parsing.
76
* @param newline The newline string to validate.

src/options/parseOptions.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
import type { Newline } from '../types'
12
import { validateComments } from './comments'
23
import { DefaultDelimiter } from './constants'
34
import { guessDelimiter, validateDelimiter } from './delimiter'
45
import { validateEscapeChar } from './escapeChar'
5-
import { guessLineEndings, type Newline, validateNewline } from './newline'
6+
import { guessLineEndings, validateNewline } from './newline'
67
import { validateQuoteChar } from './quoteChar'
78

89
export interface ParseOptions {

src/types.d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
export type Newline = '\n' | '\r' | '\r\n'
2+
13
/** Error structure */
24
export interface ParseError {
35
/** A generalization of the error */
@@ -18,7 +20,7 @@ export interface ParseMeta {
1820
/** Delimiter used */
1921
delimiter: string
2022
/** Line break sequence used */
21-
newline: string
23+
newline: Newline
2224
/** Byte offset at the start of the row */
2325
byteOffset: number
2426
/** Number of bytes consumed in this row */

tests/parser.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ describe('Papaparse core parser tests', () => {
1717
expect(charCount).toBe(test.expected.meta?.charCount)
1818
}
1919
if (test.expected.meta?.newline !== undefined) {
20-
const newlines = new Set(result.map(({ meta }) => meta.newline))
20+
const newlines = new Set<string>(result.map(({ meta }) => meta.newline as string))
2121
expect(newlines.size).toBe(1)
2222
expect(newlines.has(test.expected.meta?.newline)).toBe(true)
2323
}

tests/text.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ describe('Papaparse high-level tests', () => {
7070
expect(charCount).toBe(test.expected.meta?.charCount)
7171
}
7272
if (test.expected.meta?.newline !== undefined) {
73-
const newlines = new Set(result.map(({ meta }) => meta.newline))
73+
const newlines = new Set(result.map(({ meta }) => meta.newline as string))
7474
expect(newlines.size).toBe(1)
7575
expect(newlines.has(test.expected.meta?.newline)).toBe(true)
7676
}

tests/url.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ describe('parseURL, while mocking parse, ', () => {
110110
byteOffset: 0,
111111
byteCount: 2 * text.length,
112112
charCount: 2 * text.length,
113-
newline: '\n',
113+
newline: '\n' as const,
114114
// quote: '"',
115115
delimiter: ',',
116116
},
@@ -150,7 +150,7 @@ describe('Papaparse high-level tests', () => {
150150
expect(charCount).toBe(test.expected.meta?.charCount)
151151
}
152152
if (test.expected.meta?.newline !== undefined) {
153-
const newlines = new Set(result.map(({ meta }) => meta.newline))
153+
const newlines = new Set(result.map(({ meta }) => meta.newline as string))
154154
expect(newlines.size).toBe(1)
155155
expect(newlines.has(test.expected.meta?.newline)).toBe(true)
156156
}

0 commit comments

Comments
 (0)