Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add typings for TypeScript support #34

Merged
merged 2 commits into from
Mar 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 86 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1,86 @@
define module 'csv-string';
import { Transform } from "stream";

declare namespace CsvString {

type rowElement = string | number | boolean;
type row = rowElement[];
type separator = "," | ";" | "|" | "\t";

function parse(input: string, separator?: separator, quote?: string): row;
function stringify(input: row, separator?: string): string;
function detect(input: string): separator;
function createStream(options?: {
separator: separator;
quote: string;
}): Transform;

type forEachCallback = (row: row, index: number) => undefined;

function forEach(
input: string,
separator: string,
quote: string,
callback: forEachCallback
): void;

function forEach(
input: string,
separator: string,
callback: forEachCallback
): void;

function forEach(input: string, callback: forEachCallback): void;

type readCallback = (row: row) => undefined;

function read(input: string, callback: readCallback): number;

function read(
input: string,
separator: string,
quote: string,
callback: readCallback
): number;

function read(
input: string,
separator: string,
callback: readCallback
): number;

type readAllCallback = readCallback;

function readAll(input: string, callback: readCallback): number;

function readAll(
input: string,
separator: string,
quote: string,
callback: readCallback
): number;

function readAll(
input: string,
separator: string,
callback: readCallback
): number;

type readChunkCallback = readCallback;

function readChunk(input: string, callback: readCallback): number;

function readChunk(
input: string,
separator: string,
quote: string,
callback: readCallback
): number;

function readChunk(
input: string,
separator: string,
callback: readCallback
): number;
}

export = CsvString;
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"test": "nyc mocha -R spec"
},
"main": "./index.js",
"types": "./index.d.ts",
"repository": {
"type": "git",
"url": "https://github.com/touv/node-csv-string.git"
Expand Down
Loading