Skip to content

Commit

Permalink
Maintenance
Browse files Browse the repository at this point in the history
  • Loading branch information
vslinko committed May 15, 2024
1 parent 2fb5cc0 commit 6afea02
Show file tree
Hide file tree
Showing 14 changed files with 131 additions and 63 deletions.
9 changes: 4 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: denolib/setup-deno@master
- uses: denoland/setup-deno@v1
with:
deno-version: "v1.x"

deno-version: "1.42.4"
- run: deno --version
- run: make lint
- run: make test
- run: deno lint
- run: deno task test
4 changes: 0 additions & 4 deletions .prettierrc

This file was deleted.

12 changes: 0 additions & 12 deletions Makefile

This file was deleted.

16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#### Read CSV file

```ts
import { readCSV } from "https://deno.land/x/csv/mod.ts";
import { readCSV } from "jsr:@vslinko/csv";

const f = await Deno.open("./example.csv");

Expand All @@ -33,7 +33,7 @@ f.close();
Line numbering starts from zero. `fromLine` is inclusive, `toLine` is exclusive.

```ts
import { readCSV } from "https://deno.land/x/csv/mod.ts";
import { readCSV } from "jsr:@vslinko/csv";

const f = await Deno.open("./example.csv");

Expand All @@ -50,7 +50,7 @@ f.close();
#### Read CSV file with custom separators

```ts
import { readCSV } from "https://deno.land/x/csv/mod.ts";
import { readCSV } from "jsr:@vslinko/csv";

const f = await Deno.open("./example.csv");

Expand All @@ -73,7 +73,7 @@ f.close();
#### Read objects from CSV file with header row

```ts
import { readCSVObjects } from "https://deno.land/x/csv/mod.ts";
import { readCSVObjects } from "jsr:@vslinko/csv";

const f = await Deno.open("./example.csv");

Expand All @@ -87,7 +87,7 @@ f.close();
#### Read CSV file manually

```ts
import { readCSVObjects } from "https://deno.land/x/csv/mod.ts";
import { readCSVObjects } from "jsr:@vslinko/csv";

const f = await Deno.open("./example.csv");

Expand Down Expand Up @@ -118,7 +118,7 @@ reader.read();
#### Write CSV file

```ts
import { writeCSV } from "https://deno.land/x/csv/mod.ts";
import { writeCSV } from "jsr:@vslinko/csv";

const f = await Deno.open("./example.csv", {
write: true,
Expand All @@ -138,7 +138,7 @@ f.close();
#### Write objects asynchronously to CSV file

```ts
import { writeCSVObjects } from "https://deno.land/x/csv/mod.ts";
import { writeCSVObjects } from "jsr:@vslinko/csv";

const f = await Deno.open("./example.csv", {
write: true,
Expand All @@ -159,7 +159,7 @@ f.close();
#### Write CSV file manually

```ts
import { CSVWriter } from "https://deno.land/x/csv/mod.ts";
import { CSVWriter } from "jsr:@vslinko/csv";

const f = await Deno.open("./example.csv", {
write: true,
Expand Down
2 changes: 1 addition & 1 deletion csv_spectrum_test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { readCSVObjects } from "./mod.ts";
import { assertEquals } from "./dev_deps.ts";
import { assertEquals } from "@std/assert/assert-equals";

for await (const file of Deno.readDir("./third_party/csv-spectrum/csvs")) {
const csvFilePath = "./third_party/csv-spectrum/csvs/" + file.name;
Expand Down
28 changes: 28 additions & 0 deletions deno.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "@vslinko/csv",
"version": "1.0.1",
"exports": "./mod.ts",
"imports": {
"@std/assert": "jsr:@std/[email protected]",
"@std/bytes": "jsr:@std/[email protected]",
"@std/io": "jsr:@std/[email protected]",
"@std/log": "jsr:@std/[email protected]",
"chiefbiiko/sha256": "https://denopkg.com/chiefbiiko/[email protected]/mod.ts"
},
"tasks": {
"test": "deno test --allow-read",
"benchmark": "cd benchmarks && make"
},
"test": {
"include": ["reader_test.ts", "writer_test.ts", "csv_spectrum_test.ts"]
},
"lint": {
"include": ["*.ts", "benchmarks/*.ts", "benchmarks/*.js"]
},
"fmt": {
"include": ["*.ts", "benchmarks/*.ts", "benchmarks/*.js", "*.json"]
},
"publish": {
"include": ["*.ts", "LICENSE", "README.md", "deno.json"]
}
}
63 changes: 63 additions & 0 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 0 additions & 7 deletions deps.ts

This file was deleted.

7 changes: 0 additions & 7 deletions dev_deps.ts

This file was deleted.

26 changes: 15 additions & 11 deletions reader.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { concat, getLogger, iterateReader, Logger, repeat } from "./deps.ts";
import type { Reader } from "@std/io/types";
import { concat } from "@std/bytes/concat";
import { repeat } from "@std/bytes/repeat";
import { getLogger, Logger } from "@std/log";
import { iterateReader } from "@std/io/iterate-reader";
import { getUint8Array, hasPrefixFrom } from "./utils.ts";

/** Common options for CSV reader module */
Expand Down Expand Up @@ -114,7 +118,7 @@ export class CSVReader {
private fromLine: number;
private toLine: number;

constructor(reader: Deno.Reader, options?: Partial<CSVReaderOptions>) {
constructor(reader: Reader, options?: Partial<CSVReaderOptions>) {
this.decoder = new TextDecoder(options?.encoding);
const mergedOptions: HiddenCSVReaderOptions = {
...defaultCSVReaderOptions,
Expand Down Expand Up @@ -240,7 +244,7 @@ export class CSVReader {
if (done) {
this.readerEmpty = true;
} else {
this.inputBuffer = concat(this.inputBuffer, value);
this.inputBuffer = concat([this.inputBuffer, value]);
this.inputBufferUnprocessed += value.length;
}
}
Expand Down Expand Up @@ -500,7 +504,7 @@ class CSVStreamReader implements AsyncIterableIterator<string | symbol> {
) => void;
private nextPromiseReject?: (err: Error) => void;

constructor(reader: Deno.Reader, options?: Partial<CommonCSVReaderOptions>) {
constructor(reader: Reader, options?: Partial<CommonCSVReaderOptions>) {
this.buffer = [];
this.done = false;
this.reader = new CSVReader(reader, {
Expand Down Expand Up @@ -597,7 +601,7 @@ export const newLine = Symbol("newLine");
* }
*/
export function readCSVStream(
reader: Deno.Reader,
reader: Reader,
options?: Partial<CommonCSVReaderOptions>,
): AsyncIterable<string | symbol> {
return new CSVStreamReader(reader, options);
Expand All @@ -612,7 +616,7 @@ class CSVRowReader implements AsyncIterableIterator<string[]> {
private nextPromiseResolve?: (res: IteratorResult<string[], void>) => void;
private nextPromiseReject?: (err: Error) => void;

constructor(reader: Deno.Reader, options?: Partial<CommonCSVReaderOptions>) {
constructor(reader: Reader, options?: Partial<CommonCSVReaderOptions>) {
this.buffer = [];
this.done = false;
this.row = [];
Expand Down Expand Up @@ -701,7 +705,7 @@ class CSVRowReader implements AsyncIterableIterator<string[]> {
* }
*/
export function readCSVRows(
reader: Deno.Reader,
reader: Reader,
options?: Partial<CommonCSVReaderOptions>,
): AsyncIterable<string[]> {
return new CSVRowReader(reader, options);
Expand Down Expand Up @@ -740,7 +744,7 @@ class RowIterator implements AsyncIterableIterator<string> {
}

const { done, value } = this.buffer.length > 0
? this.buffer.shift() as IteratorResult<string | symbol>
? (this.buffer.shift() as IteratorResult<string | symbol>)
: await this.onRequested();

if (done || value === newLine) {
Expand All @@ -767,7 +771,7 @@ class CSVRowIteratorReader implements AsyncIterableIterator<RowIterator> {
) => void;
private nextPromiseReject?: (err: Error) => void;

constructor(reader: Deno.Reader, options?: Partial<CommonCSVReaderOptions>) {
constructor(reader: Reader, options?: Partial<CommonCSVReaderOptions>) {
this.done = false;
this.buffer = [];
this.reader = new CSVReader(reader, {
Expand Down Expand Up @@ -875,7 +879,7 @@ class CSVRowIteratorReader implements AsyncIterableIterator<RowIterator> {
* }
*/
export function readCSV(
reader: Deno.Reader,
reader: Reader,
options?: Partial<CommonCSVReaderOptions>,
): AsyncIterable<AsyncIterable<string>> {
return new CSVRowIteratorReader(reader, options);
Expand All @@ -888,7 +892,7 @@ export function readCSV(
* }
*/
export async function* readCSVObjects(
reader: Deno.Reader,
reader: Reader,
options?: Partial<CommonCSVReaderOptions>,
): AsyncIterable<{ [key: string]: string }> {
let header: string[] | undefined;
Expand Down
10 changes: 6 additions & 4 deletions reader_test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { concat } from "./deps.ts";
import { assertEquals, assertRejects } from "./dev_deps.ts";
import type { Reader } from "@std/io/types";
import { concat } from "@std/bytes/concat";
import { assertRejects } from "@std/assert/assert-rejects";
import { assertEquals } from "@std/assert/assert-equals";
import {
newLine,
readCSV,
Expand All @@ -9,15 +11,15 @@ import {
} from "./reader.ts";
import { asyncArrayFrom, asyncArrayFrom2 } from "./utils.ts";

class MyReader implements Deno.Reader {
class MyReader implements Reader {
private buf: Uint8Array;
private index: number;

constructor(content: string, options: { withBom?: boolean } = {}) {
const opts = { withBom: false, ...options };
this.buf = new TextEncoder().encode(content);
if (opts.withBom) {
this.buf = concat(new Uint8Array([0xef, 0xbb, 0xbf]), this.buf);
this.buf = concat([new Uint8Array([0xef, 0xbb, 0xbf]), this.buf]);
}
this.index = 0;
}
Expand Down
2 changes: 1 addition & 1 deletion utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getLogger } from "./deps.ts";
import { getLogger } from "@std/log";

const enc = new TextEncoder();

Expand Down
5 changes: 3 additions & 2 deletions writer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { concat, indexOfNeedle } from "./deps.ts";
import { concat } from "@std/bytes/concat";
import { indexOfNeedle } from "@std/bytes/index-of-needle";
import {
dummyAsyncIterable,
getUint8Array,
Expand Down Expand Up @@ -113,7 +114,7 @@ export class CSVWriter {
if (done) {
inputBufferEmpty = true;
} else {
inputBuffer = concat(inputBuffer, value);
inputBuffer = concat([inputBuffer, value]);
}
continue;
}
Expand Down
3 changes: 2 additions & 1 deletion writer_test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { assertEquals, Buffer } from "./dev_deps.ts";
import { assertEquals } from "@std/assert/assert-equals";
import { Buffer } from "@std/io/buffer";
import { CSVWriter, writeCSV, writeCSVObjects } from "./writer.ts";

Deno.test({
Expand Down

0 comments on commit 6afea02

Please sign in to comment.