Add typings for csv-stringify.

This commit is contained in:
Rogier Schouten 2015-03-09 10:00:24 +01:00
parent dd99be72dc
commit 164c9dd0a5
3 changed files with 106 additions and 0 deletions

View File

@ -133,6 +133,7 @@ This document generated by [dt-contributors-generator](https://github.com/vvakam
* [:link:](cryptojs/cryptojs.d.ts) [CryptoJS](https://code.google.com/p/crypto-js) by [Gia Bảo @ Sân Đình](https://github.com/giabao)
* [:link:](googlemaps.infobubble/google.maps.infobubble.d.ts) [CSS3 InfoBubble with tabs for Google Maps API V3](http://google-maps-utility-library-v3.googlecode.com/svn/trunk/infobubble/src) by [Johan Nilsson](https://github.com/Dashue)
* [:link:](csurf/csurf.d.ts) [csurf](https://www.npmjs.org/package/csurf) by [Hiroki Horiuchi](https://github.com/horiuchi)
* [:link:](csv-stringify/csv-stringify.d.ts) [csv-stringify](https://github.com/wdavidw/node-csv-stringify) by [rogierschouten](https://github.com/rogierschouten)
* [:link:](md5/md5.d.ts) [CybozuLabs.MD5](http://labs.cybozu.co.jp/blog/mitsunari/2007/07/md5js_1.html) by [MIZUNE Pine](https://github.com/pine613)
* [:link:](d3/d3.d.ts) [d3JS](http://d3js.org) by [Boris Yankov](https://github.com/borisyankov)
* [:link:](d3.cloud.layout/d3.cloud.layout.d.ts) [d3JS cloud layout plugin by Jason Davies](https://github.com/jasondavies/d3-cloud) by [hans windhoff](https://github.com/hansrwindhoff)

View File

@ -0,0 +1,22 @@
/// <reference path="csv-stringify.d.ts" />
import stringify = require("csv-stringify");
stringify([["1", "2", "3"], ["4", "5", "6"]], (error: Error, output: string): void => {
// nothing
});
stringify([["1", "2", "3"], ["4", "5", "6"]], {
delimiter: ","
}, (error: Error, output: string): void => {
// nothing
});
var s = stringify({ delimiter: "," });
s.write(["1", "2", "3"]);

83
csv-stringify/csv-stringify.d.ts vendored Normal file
View File

@ -0,0 +1,83 @@
// Type definitions for csv-stringify 0.0.6
// Project: https://github.com/wdavidw/node-csv-stringify
// Definitions by: Rogier Schouten <https://github.com/rogierschouten>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
/// <reference path="../node/node.d.ts" />
declare module "csv-stringify" {
module stringify {
interface StringifyOpts {
/**
* List of fields, applied when transform returns an object, order matters, read the transformer documentation for additionnal information, columns are auto discovered when the user write object, see the "header" option on how to print columns names on the first line.
*/
columns?: string[];
/**
* Set the field delimiter, one character only, defaults to a comma.
*/
delimiter?: string;
/**
* Add the value of "options.rowDelimiter" on the last line, default to true.
*/
eof?: boolean;
/**
* Defaults to the escape read option.
*/
escape?: boolean;
/**
* Display the column names on the first line if the columns option is provided or discovered.
*/
header?: boolean;
/**
* String used to delimit record rows or a special value; special values are 'auto', 'unix', 'mac', 'windows', 'unicode'; defaults to 'auto' (discovered in source or 'unix' if no source is specified).
*/
lineBreaks?: string;
/**
* Defaults to the quote read option.
*/
quote?: string;
/**
* Boolean, default to false, quote all the non-empty fields even if not required.
*/
quoted?: boolean;
/**
* Boolean, no default, quote empty fields? If specified, overrides quotedString for empty strings.
*/
quotedEmpty?: boolean;
/**
* Boolean, default to false, quote all fields of type string even if not required.
*/
quotedString?: boolean;
/**
* String used to delimit record rows or a special value; special values are 'auto', 'unix', 'mac', 'windows', 'unicode'; defaults to 'auto' (discovered in source or 'unix' if no source is specified).
*/
rowDelimiter?: string;
}
interface Stringifier extends NodeJS.ReadWriteStream {
// Stringifier stream takes array of strings
write(line: string[]): boolean;
// repeat declarations from NodeJS.WritableStream to avoid compile error
write(buffer: Buffer, cb?: Function): boolean;
write(str: string, cb?: Function): boolean;
write(str: string, encoding?: string, cb?: Function): boolean;
}
}
/**
* Callback version: string in --> callback with string out
*/
function stringify(input: any[][], opts: stringify.StringifyOpts, callback: (error: Error, output: string) => void): void;
function stringify(input: any[][], callback: (error: Error, output: string) => void): void;
/**
* Streaming stringifier
*/
function stringify(opts: stringify.StringifyOpts): stringify.Stringifier;
export = stringify;
}