Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions types/convert-array-to-csv/convert-array-to-csv-tests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { convertArrayToCSV } from 'convert-array-to-csv';

const header = ['number', 'first', 'last', 'handle'];
const dataArrays = [
[1, 'Mark', 'Otto', '@mdo'],
[2, 'Jacob', 'Thornton', '@fat'],
[3, 'Larry', 'the Bird', '@twitter'],
];

const dataObjects = [
{
number: 1,
first: 'Mark',
last: 'Otto',
handle: '@mdo',
},
{
number: 2,
first: 'Jacob',
last: 'Thornton',
handle: '@fat',
},
{
number: 3,
first: 'Larry',
last: 'the Bird',
handle: '@twitter',
},
];

// $ExpectType string
const csvFromArrayOfObjects = convertArrayToCSV(dataObjects);

// $ExpectType string
const csvFromArrayOfArrays = convertArrayToCSV(dataArrays, {
header,
separator: ';',
});

// When the param is incorrect
// @ts-expect-error
const csvFromString = convertArrayToCSV('1, Mark, Otto, @mdo');
12 changes: 12 additions & 0 deletions types/convert-array-to-csv/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Type definitions for convert-array-to-csv 2.0
// Project: https://github.com/aichbauer/node-convert-array-to-csv
// Definitions by: Qiming-Liu <https://github.com/Qiming-Liu>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped

export function convertArrayToCSV(
data: object[],
options?: {
header?: string[];
separator?: string;
},
): string;
23 changes: 23 additions & 0 deletions types/convert-array-to-csv/tsconfig.json
Original file line number Diff line number Diff line change
@@ -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",
"convert-array-to-csv-tests.ts"
]
}
3 changes: 3 additions & 0 deletions types/convert-array-to-csv/tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "@definitelytyped/dtslint/dt.json"
}