Skip to content

Commit

Permalink
csv: add declarations
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaliy-art committed Feb 24, 2024
1 parent b9cbf86 commit 2a9a4d9
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 4 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tarantoolscript",
"version": "0.5.3",
"version": "0.6.0",
"author": "Vitaliy Artemov [email protected]",
"description": "TypeScript definitions for Tarantool Lua API.",
"repository": {
Expand Down
38 changes: 38 additions & 0 deletions src/builtin/csv/Csv.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/** @noSelfInFile */

import { CsvOptions } from './CsvOptions';
import { CsvReadable } from './CsvReadable';
import { CsvWritable } from './CsvWritable';

/**
* Get CSV-formatted input from `readable` and return a table as output.
* Usually `readable` is either a string or a file opened for reading.
* Usually `options` is not specified.
* @param readable A string, or any object which has a `read()` method, formatted according to the CSV rules.
* @param options An options table.
* @returns Table - loaded value.
*/
export declare function load(readable: CsvReadable, options?: CsvOptions): unknown[];

/**
* Get table input from `csv-table` and return a CSV-formatted string as output.
* Or, get table input from `csv-table` and put the output in `writable`.
* Usually `options` is not specified.
* Usually `writable`, if specified, is a file opened for writing.
* `csv.dump()` is the reverse of `csv.load()`.
* @param csvTable A table which can be formatted according to the CSV rules.
* @param options An options table.
* @param writable Any object which has a `write()` method.
* @returns String, which is written to `writable` if specified.
*/
export declare function dump(csvTable: unknown[], options?: CsvOptions): string;
export declare function dump(csvTable: unknown[], options?: CsvOptions, writable: CsvWritable): void;

/**
* Form a Lua iterator function for going through CSV records one field at a time.
* Use of an iterator is strongly recommended if the amount of data is large (ten or more megabytes).
* @param input A string, or any object which has a `read()` method, formatted according to che CSV rules.
* @param options An options table.
* @returns Lua iterator.
*/
export declare function iterate(input: CsvReadable, options?: CsvOptions): LuaIterable<LuaMultiReturn<number, unknown[]>>
21 changes: 21 additions & 0 deletions src/builtin/csv/CsvOptions.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
export interface CsvOptions {
/**
* Single-byte character to designate end-of-field.
*/
delimiter?: string;

/**
* Single-byte character to designate encloser of string.
*/
quote_char?: string;

/**
* Number of characters to read at once (usually for file-IO efficiency).
*/
chunk_size?: number;

/**
* Number of lines to skip at the start (usually for a header).
*/
skip_head_lines?: number;
}
3 changes: 3 additions & 0 deletions src/builtin/csv/CsvReadable.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export type CsvReadable =
| string
| { read(): unknown }
3 changes: 3 additions & 0 deletions src/builtin/csv/CsvWritable.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface CsvWritable {
write(...args: unknown[]): unknown;
}
3 changes: 3 additions & 0 deletions src/builtin/csv/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './CsvOptions';
export * from './CsvReadable';
export * from './CsvWritable';
2 changes: 1 addition & 1 deletion src/builtin/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
/** @todo config https://www.tarantool.io/en/doc/latest/reference/reference_lua/config/ */
/** @todo console https://www.tarantool.io/en/doc/latest/reference/reference_lua/console/ */
/** @todo crypto https://www.tarantool.io/en/doc/latest/reference/reference_lua/crypto/ */
/** @todo csv https://www.tarantool.io/en/doc/latest/reference/reference_lua/csv/ */
/** @todo datetime https://www.tarantool.io/en/doc/latest/reference/reference_lua/datetime/ */
/** @todo decimal https://www.tarantool.io/en/doc/latest/reference/reference_lua/decimal/ */
/** @todo digest https://www.tarantool.io/en/doc/latest/reference/reference_lua/digest/ */
Expand Down Expand Up @@ -39,6 +38,7 @@

export * from './box';
export * from './buffer';
export * from './csv';
export * from './log';
export * from './msgpack';
export * from './package';
Expand Down
1 change: 1 addition & 0 deletions src/csv.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './builtin/csv/Csv';

0 comments on commit 2a9a4d9

Please sign in to comment.