mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-23 21:00:01 +08:00
Merge pull request #17940 from arjenvanderende/master
[csv-stringify] Add formatter options for boolean, date and object types
This commit is contained in:
@@ -12,9 +12,22 @@ stringify([["1", "2", "3"], ["4", "5", "6"]], {
|
||||
// nothing
|
||||
});
|
||||
|
||||
stringify([["1", true, new Date()], ["4", false, new Date()]], {
|
||||
delimiter: ",",
|
||||
formatters: {
|
||||
bool: value => value ? 'yes' : 'no',
|
||||
date: value => value.toISOString()
|
||||
}
|
||||
}, (error: Error, output: string): void => {
|
||||
// nothing
|
||||
});
|
||||
|
||||
stream = stringify({ delimiter: "," });
|
||||
|
||||
stream.write(["1", "2", "3"]);
|
||||
stream.write(["4", true, new Date()], 'utf8', (err: Error, output: string): void => {
|
||||
// nothing
|
||||
});
|
||||
|
||||
const transform: NodeJS.ReadWriteStream = stream;
|
||||
|
||||
|
||||
20
types/csv-stringify/index.d.ts
vendored
20
types/csv-stringify/index.d.ts
vendored
@@ -1,6 +1,7 @@
|
||||
// Type definitions for csv-stringify 1.0
|
||||
// Type definitions for csv-stringify 1.4
|
||||
// Project: https://github.com/wdavidw/node-csv-stringify
|
||||
// Definitions by: Rogier Schouten <https://github.com/rogierschouten>
|
||||
// Arjen van der Ende <https://github.com/arjenvanderende>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/// <reference types="node" />
|
||||
@@ -55,15 +56,24 @@ declare namespace stringify {
|
||||
* special values are 'auto', 'unix', 'mac', 'windows', 'unicode'; defaults to 'auto' (discovered in source or 'unix' if no source is specified).
|
||||
*/
|
||||
rowDelimiter?: string;
|
||||
/**
|
||||
* Override serialization of boolean, dates and complex objects.
|
||||
*/
|
||||
formatters?: FormatterOpts;
|
||||
}
|
||||
|
||||
interface FormatterOpts {
|
||||
bool?: (value: boolean) => string;
|
||||
date?: (value: Date) => string;
|
||||
object?: (value: any) => string;
|
||||
}
|
||||
|
||||
interface Stringifier extends NodeJS.ReadWriteStream {
|
||||
// Stringifier stream takes array of strings or Object
|
||||
write(line: string[] | any): boolean;
|
||||
// Stringifier stream takes array of strings or Object, and optional encoding and callback
|
||||
write(line: string[] | any, encoding?: string, cb?: (error: Error | undefined, output: string) => void): boolean;
|
||||
|
||||
// repeat declarations from NodeJS.WritableStream to avoid compile error
|
||||
write(buffer: string | Buffer, cb?: () => void): boolean;
|
||||
write(str: string, encoding?: string, cb?: () => void): boolean;
|
||||
write(buffer: string | Buffer, cb?: (error: Error | undefined, output: string) => void): boolean;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1 +1,6 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {
|
||||
"prefer-method-signature": false
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user