Add @types/objects-to-csv (#45973)

* Added types for objects-to-csv

* removed leftover type

* Updated after running npm test properly
This commit is contained in:
Tom Plant 2020-07-10 23:39:07 +10:00 committed by GitHub
parent de475b6d82
commit 4c83502843
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 91 additions and 0 deletions

55
types/objects-to-csv/index.d.ts vendored Normal file
View File

@ -0,0 +1,55 @@
// Type definitions for objects-to-csv 1.3
// Project: https://github.com/anton-bot/objects-to-csv#readme
// Definitions by: Tom Plant <https://github.com/pl4nty>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
declare class ObjectsToCsv {
/**
* Creates a new instance of the object array to csv converter.
*/
constructor(data: object[]);
/**
* Holds data to be converted.
*/
data: object[];
/**
* Saves the CSV file to the specified file.
* @param filename The path and filename of the new CSV file.
* @param options The options for writing to disk.
* @param options.append Whether to append to file. Default is overwrite (false).
* @param options.bom Append the BOM mark so that Excel shows
* @param options.allColumns Whether to check all items for column names or only the first. Default is the first.
* @returns Data converted to a CSV string.
*/
toDisk(
filename: string,
options?: {
append?: boolean;
bom?: boolean;
allColumns?: boolean;
},
): Promise<string>;
/**
* Returns the CSV file as string.
* @param header - If false, omit the first row containing the
* column names.
* @param allColumns - Whether to check all items for column names.
* Uses only the first item if false.
*/
toString(header?: boolean, allColumns?: boolean): Promise<string>;
/**
* Private method to run the actual conversion of array of objects to CSV data.
* @param data Data to be converted.
* @param header Whether the first line should contain column headers.
* @param allColumns Whether to check all items for column names.
* Uses only the first item if false.
* @returns Data converted to a CSV string.
*/
convert(data: object[], header?: boolean, allColumns?: boolean): Promise<string>;
}
export = ObjectsToCsv;

View File

@ -0,0 +1,12 @@
import ObjectsToCsv = require('objects-to-csv');
const SAMPLE_ASCII = [
{ code: 'HK', name: 'Hong Kong' },
{ code: 'KLN', name: 'Kowloon' },
{ code: 'NT', name: 'New Territories' },
];
const ascii = new ObjectsToCsv(SAMPLE_ASCII); // $ExpectType ObjectsToCsv
const asciiFile = ascii.toDisk('name'); // $ExpectType Promise<string>
const asciiString = ascii.toString(); // $ExpectType Promise<string>
const convertAscii = ascii.convert(SAMPLE_ASCII); // $ExpectType Promise<string>

View File

@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"objects-to-csv-tests.ts"
]
}

View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }