mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
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:
parent
de475b6d82
commit
4c83502843
55
types/objects-to-csv/index.d.ts
vendored
Normal file
55
types/objects-to-csv/index.d.ts
vendored
Normal 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;
|
||||
12
types/objects-to-csv/objects-to-csv-tests.ts
Normal file
12
types/objects-to-csv/objects-to-csv-tests.ts
Normal 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>
|
||||
23
types/objects-to-csv/tsconfig.json
Normal file
23
types/objects-to-csv/tsconfig.json
Normal 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"
|
||||
]
|
||||
}
|
||||
1
types/objects-to-csv/tslint.json
Normal file
1
types/objects-to-csv/tslint.json
Normal file
@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Loading…
Reference in New Issue
Block a user