Skip to content

Commit 803781b

Browse files
committed
0.0.7, export toURL and upgrade deps
1 parent 5057522 commit 803781b

8 files changed

Lines changed: 521 additions & 426 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.7]
4+
5+
- export toURL utility function
6+
37
## [0.0.6]
48

59
- rename testEmptyLine to isEmptyLine, change its signature to accept options object with greedy property

package-lock.json

Lines changed: 483 additions & 392 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "csv-range",
3-
"version": "0.0.6",
3+
"version": "0.0.7",
44
"description": "Parse ranges of a CSV file.",
55
"type": "module",
66
"license": "MIT",
@@ -37,21 +37,21 @@
3737
"typecheck": "tsc --noEmit"
3838
},
3939
"devDependencies": {
40-
"@eslint/compat": "1.4.1",
40+
"@eslint/compat": "2.0.0",
4141
"@eslint/js": "9.39.1",
42-
"@stylistic/eslint-plugin": "5.5.0",
43-
"@types/node": "24.10.0",
44-
"@vitest/browser-playwright": "4.0.7",
45-
"@vitest/coverage-v8": "4.0.7",
46-
"@vitest/ui": "4.0.7",
42+
"@stylistic/eslint-plugin": "5.6.1",
43+
"@types/node": "24.10.1",
44+
"@vitest/browser-playwright": "4.0.10",
45+
"@vitest/coverage-v8": "4.0.10",
46+
"@vitest/ui": "4.0.10",
4747
"bumpp": "10.3.1",
4848
"eslint": "9.39.1",
49-
"eslint-plugin-jsdoc": "^61.1.12",
50-
"eslint-plugin-simple-import-sort": "^12.1.1",
49+
"eslint-plugin-jsdoc": "61.2.1",
50+
"eslint-plugin-simple-import-sort": "12.1.1",
5151
"globals": "16.5.0",
52-
"tsdown": "0.16.0",
52+
"tsdown": "0.16.5",
5353
"typescript": "5.9.3",
54-
"typescript-eslint": "8.46.3",
55-
"vitest": "4.0.7"
54+
"typescript-eslint": "8.47.0",
55+
"vitest": "4.0.10"
5656
}
5757
}

src/fetch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* const result = fetchChunk({ url, chunkSize, firstByte, maxLastByte: fileSize - 1 })
1616
* ```
1717
*
18-
* See `toUrl` in `src/url.ts` for a helper function that creates such URLs.
18+
* See `toURL` in `src/url.ts` for a helper function that creates such URLs.
1919
* @param options Options for fetching the chunk.
2020
* @param options.url The URL of the remote file.
2121
* @param options.chunkSize The size of the chunk to fetch.

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'
22
export type { Newline, ParseError, ParseMeta, ParseResult } from './types'
33
export { parseURL } from './url'
4-
export { isEmptyLine } from './utils'
4+
export { isEmptyLine, toURL } from './utils'

src/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* @param text The text to create a blob URL from.
44
* @returns An object containing the blob URL, the size of the text in bytes, and a function to revoke the URL.
55
*/
6-
export function toUrl(text: string): {
6+
export function toURL(text: string): {
77
url: string
88
fileSize: number
99
revoke: () => void

tests/url.test.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { describe, expect, it } from 'vitest'
22

33
import type { ParseResult } from '../src/types'
44
import { parseURL } from '../src/url'
5-
import { toUrl } from '../src/utils'
5+
import { toURL } from '../src/utils'
66
import { PARSE_TESTS } from './cases'
77

88
function* parseMock(text: string): Generator<ParseResult, void, unknown> {
@@ -25,7 +25,7 @@ function* parseMock(text: string): Generator<ParseResult, void, unknown> {
2525
describe('parseURL, while mocking parse, ', () => {
2626
it.each([1, 2, 3, 10, 17, 18, 19, 20, 21, 1_000, undefined])('accepts chunk size of %s', async (chunkSize) => {
2727
const text = 'hello, csvremote!!!' // length: 19
28-
const { url, fileSize, revoke } = toUrl(text)
28+
const { url, fileSize, revoke } = toURL(text)
2929
let result = ''
3030
let bytes = 0
3131
// passing 'to: fileSize - 1' for Node.js bug: https://github.com/nodejs/node/issues/60382
@@ -41,7 +41,7 @@ describe('parseURL, while mocking parse, ', () => {
4141

4242
it.each([0, -1, 1.5, NaN, Infinity])('throws if chunkSize is invalid: %s', async (chunkSize) => {
4343
const text = 'hello, csvremote!!!'
44-
const { url, fileSize, revoke } = toUrl(text)
44+
const { url, fileSize, revoke } = toURL(text)
4545
const iterator = parseURL(url, { chunkSize, lastByte: fileSize - 1 })
4646
await expect(iterator.next()).rejects.toThrow()
4747
revoke()
@@ -57,7 +57,7 @@ describe('parseURL, while mocking parse, ', () => {
5757
[5, 5, ','],
5858
])('accepts valid firstByte: %s and lastByte: %s', async (firstByte, lastByte, expected) => {
5959
const text = 'hello, csvremote!!!'
60-
const { url, revoke } = toUrl(text)
60+
const { url, revoke } = toURL(text)
6161
let result = ''
6262
// implicit assertation in the loop: no exceptions thrown
6363
for await (const { row } of parseURL(url, { firstByte, lastByte, parse: parseMock })) {
@@ -82,15 +82,15 @@ describe('parseURL, while mocking parse, ', () => {
8282
// [5, 0], // now allowed
8383
])('throws for invalid from: %s or lastByte: %s', async (firstByte, lastByte) => {
8484
const text = 'hello, csvremote!!!'
85-
const { url, revoke } = toUrl(text)
85+
const { url, revoke } = toURL(text)
8686
const iterator = parseURL(url, { chunkSize: 10, firstByte, lastByte })
8787
await expect(iterator.next()).rejects.toThrow()
8888
revoke()
8989
})
9090

9191
it('uses the requestInit option, allowing to pass an abort signal', async () => {
9292
const text = 'hello, csvremote!!!'
93-
const { url, revoke } = toUrl(text)
93+
const { url, revoke } = toURL(text)
9494
const controller = new AbortController()
9595
const iterator = parseURL(url, { requestInit: { signal: controller.signal } })
9696
controller.abort()
@@ -100,7 +100,7 @@ describe('parseURL, while mocking parse, ', () => {
100100

101101
it('throws if parse yields more bytes than provided', async () => {
102102
const text = 'hello, csvremote!!!'
103-
const { url, revoke } = toUrl(text)
103+
const { url, revoke } = toURL(text)
104104
function* parseMock(text: string) {
105105
// yield more bytes than provided
106106
yield {
@@ -129,7 +129,7 @@ describe('Papaparse high-level tests', () => {
129129
PARSE_TESTS.forEach((test) => {
130130
it(test.description, async () => {
131131
const config: Parameters<typeof parseURL>[1] = test.config || {}
132-
const { url, fileSize, revoke } = toUrl(test.text)
132+
const { url, fileSize, revoke } = toURL(test.text)
133133
const result = []
134134
for await (const r of parseURL(url, { ...config, lastByte: fileSize - 1 })) {
135135
result.push(r)
@@ -170,7 +170,7 @@ describe('parseURL', () => {
170170
})
171171
it.for([1, 2, 3, 5, 9, 14])('with known delimiter and newline, accepts chunk size of %s bytes.', async (chunkSize) => {
172172
const text = 'a,b,c\n1,2,3\n4,5,6\n7,8,9\na,b,c\n1,2,3\n4,5,6\n7,8,9\na,b,c\n1,2,3\n4,5,6\n7,8,9\n'
173-
const { url, fileSize, revoke } = toUrl(text)
173+
const { url, fileSize, revoke } = toURL(text)
174174
const result = []
175175
let bytes = 0
176176
for await (const { row, meta: { byteOffset, byteCount } } of parseURL(url, { chunkSize, lastByte: fileSize - 1 })) {
@@ -184,7 +184,7 @@ describe('parseURL', () => {
184184
})
185185
it.each([undefined, true, false])('should respect the stripBOM option (%s), and count the bytes correctly', async (stripBOM) => {
186186
const text = '\ufeffhello, csvremote!!!'
187-
const { url, fileSize, revoke } = toUrl(text)
187+
const { url, fileSize, revoke } = toURL(text)
188188
const result = []
189189
for await (const r of parseURL(url, { stripBOM, lastByte: fileSize - 1 })) {
190190
result.push(r)
@@ -213,7 +213,7 @@ describe('parseURL', () => {
213213
])('should support cutting 👉🏿 emoji: firstByte=$firstByte, lastByte=$lastByte', async ({ firstByte, lastByte, expected: { row, charCount, invalidByteCount } }) => {
214214
// 👉🏿 uses 8 bytes in UTF-8.
215215
const text = '👉🏿,1'
216-
const { url, fileSize, revoke } = toUrl(text)
216+
const { url, fileSize, revoke } = toURL(text)
217217
lastByte ??= fileSize - 1
218218
const result = []
219219
for await (const r of parseURL(url, { firstByte, lastByte, delimiter: ',', newline: '\n' })) {
@@ -245,7 +245,7 @@ describe('parseURL', () => {
245245

246246
it('should search invalid bytes over multiple chunks if needed', async () => {
247247
const text = '👉,1'
248-
const { url, fileSize, revoke } = toUrl(text)
248+
const { url, fileSize, revoke } = toURL(text)
249249
const result = []
250250
// There are 3 invalid bytes at start, when starting at byte 1. Using chunkSize=1 to force multiple iterations.
251251
for await (const r of parseURL(url, { chunkSize: 1, firstByte: 1, lastByte: fileSize - 1, delimiter: ',', newline: '\n' })) {
@@ -273,7 +273,7 @@ describe('parseURL', () => {
273273

274274
it('should report invalid data in multiple rows', async () => {
275275
const text = '👉a,b\n1,2'
276-
const { url, fileSize, revoke } = toUrl(text)
276+
const { url, fileSize, revoke } = toURL(text)
277277
const result = []
278278
for await (const r of parseURL(url, { firstByte: 3, lastByte: fileSize - 1, delimiter: ',', newline: '\n' })) {
279279
result.push(r)

tests/utils.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
import { describe, expect, it } from 'vitest'
22

3-
import { decode, escapeRegExp, isEmptyLine, toUrl } from '../src/utils'
3+
import { decode, escapeRegExp, isEmptyLine, toURL } from '../src/utils'
44

5-
describe('toUrl', () => {
5+
describe('toURL', () => {
66
it('creates a valid blob URL and revokes it', async () => {
77
const text = 'Hello, world!'
8-
const { url, revoke } = toUrl(text)
8+
const { url, revoke } = toURL(text)
99
expect(url).toMatch(/^blob:/)
1010
// After revocation, fetching the URL should fail
1111
revoke()
1212
await expect(fetch(url)).rejects.toThrow()
1313
})
1414
it('includes an extra space to fix Node.js issue and returns correct file size', async () => {
1515
const text = 'Sample text in ASCII (1 char = 1 byte)'
16-
const { url, fileSize } = toUrl(text)
16+
const { url, fileSize } = toURL(text)
1717
expect(fileSize).toBe(text.length)
1818

1919
// Fetch the blob URL to verify its content
@@ -32,14 +32,14 @@ describe('toUrl', () => {
3232
})
3333
it('correctly calculates file size for multi-byte characters', async () => {
3434
const text = 'こんにちは' // "Hello" in Japanese, 5 characters but more than 5 bytes
35-
const { fileSize } = toUrl(text)
35+
const { fileSize } = toURL(text)
3636
const encoder = new TextEncoder()
3737
const encoded = encoder.encode(text)
3838
expect(fileSize).toBe(encoded.length)
3939
})
4040
it('allows an empty string', async () => {
4141
const text = ''
42-
const { url, fileSize } = toUrl(text)
42+
const { url, fileSize } = toURL(text)
4343
expect(fileSize).toBe(0)
4444

4545
const response = await fetch(url)

0 commit comments

Comments
 (0)