[csv-stringify] Add formatter options for boolean, date and object types

This commit is contained in:
Arjen van der Ende
2017-07-11 14:53:12 +02:00
parent b190b8fc78
commit 8455dafd74
3 changed files with 27 additions and 1 deletions

View File

@@ -12,6 +12,16 @@ 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"]);

View File

@@ -1,6 +1,7 @@
// Type definitions for csv-stringify 1.0
// 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,6 +56,16 @@ 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 {

View File

@@ -1 +1,6 @@
{ "extends": "dtslint/dt.json" }
{
"extends": "dtslint/dt.json",
"rules": {
"prefer-method-signature": false
}
}