diff --git a/types/papaparse/index.d.ts b/types/papaparse/index.d.ts index 89f2efa639bde02..62c468f2a7c16fa 100644 --- a/types/papaparse/index.d.ts +++ b/types/papaparse/index.d.ts @@ -119,7 +119,7 @@ export interface ParseConfig { chunk?(results: ParseResult, parser: Parser): void; // default: undefined beforeFirstChunk?(chunk: string): string | void; // default: undefined transform?(value: string, field: string | number): any; // default: undefined - transformHeader?(header: string): string; // default: undefined + transformHeader?(header: string, index: number): string; // default: undefined } export interface UnparseConfig { diff --git a/types/papaparse/papaparse-tests.ts b/types/papaparse/papaparse-tests.ts index ea3249e8e783b44..4eacdb5ecb4bc6a 100644 --- a/types/papaparse/papaparse-tests.ts +++ b/types/papaparse/papaparse-tests.ts @@ -1,24 +1,15 @@ - - -import Papa = require("papaparse"); -import { - ParseConfig, - UnparseConfig, - UnparseObject, - ParseError, - ParseMeta, - ParseResult -} from "papaparse"; -import { Readable } from "stream"; +import Papa = require('papaparse'); +import { ParseConfig, UnparseConfig, UnparseObject, ParseError, ParseMeta, ParseResult } from 'papaparse'; +import { Readable } from 'stream'; /** * Parsing */ -var res = Papa.parse("3,3,3"); +var res = Papa.parse('3,3,3'); res.errors[0].code; -Papa.parse("3,3,3", { +Papa.parse('3,3,3', { delimiter: ';', comments: false, trimHeaders: false, @@ -26,11 +17,11 @@ Papa.parse("3,3,3", { p.abort(); results.data.length; }, - dynamicTyping: true + dynamicTyping: true, }); -Papa.parse("3,3,3", { - dynamicTyping: (field: string | number): boolean => /headerName/i.test(field.toString()) +Papa.parse('3,3,3', { + dynamicTyping: (field: string | number): boolean => /headerName/i.test(field.toString()), }); Papa.parse('3,3,3', { @@ -56,8 +47,8 @@ Papa.parse('4;4;4', { var file = new File(null, null, null); Papa.parse(file, { - transform: function(value, field) {}, - transformHeader: function(header) { + transform: function (value, field) {}, + transformHeader: function (header, index) { return header; }, complete: function (a, b) { @@ -67,14 +58,10 @@ Papa.parse(file, { }); // .pipe to make sure it returns a stream -Papa.parse(Papa.NODE_STREAM_INPUT, { -}).pipe +Papa.parse(Papa.NODE_STREAM_INPUT, {}).pipe; -const readable = new Readable() -const rows = [ - "1,2,3", - "4,5,6" -] +const readable = new Readable(); +const rows = ['1,2,3', '4,5,6']; rows.forEach(r => { readable.push(r); @@ -85,45 +72,55 @@ const papaStream: NodeJS.ReadWriteStream = Papa.parse(Papa.NODE_STREAM_INPUT); readable.pipe(papaStream); // generic -Papa.parse("a,b,c", { - step: function(a) { - a.data[0] - } -}) - -Papa.parse("a,b,c", { - chunk: function(a) { - a.data[0] - } -}) - -Papa.parse<[string, string, string]>("a,b,c", { - complete: function(a) { - a.data[0][0] - a.data[0][1] - a.data[0][2] - } -}) +Papa.parse('a,b,c', { + step: function (a) { + a.data[0]; + }, +}); + +Papa.parse('a,b,c', { + chunk: function (a) { + a.data[0]; + }, +}); +Papa.parse<[string, string, string]>('a,b,c', { + complete: function (a) { + a.data[0][0]; + a.data[0][1]; + a.data[0][2]; + }, +}); /** * Unparsing */ Papa.unparse([{ a: 1, b: 1, c: 1 }]); -Papa.unparse([[1, 2, 3], [4, 5, 6]]); +Papa.unparse([ + [1, 2, 3], + [4, 5, 6], +]); Papa.unparse({ - fields: ["3"], - data: [] + fields: ['3'], + data: [], }); Papa.unparse([{ a: 1, b: 1, c: 1 }], { quotes: false }); Papa.unparse([{ a: 1, b: 1, c: 1 }], { quotes: [false, true, true] }); -Papa.unparse([[1, 2, 3], [4, 5, 6]], { delimiter: "," }); -Papa.unparse({ - fields: ["3"], - data: [] -}, { newline: "\n" }); - +Papa.unparse( + [ + [1, 2, 3], + [4, 5, 6], + ], + { delimiter: ',' }, +); +Papa.unparse( + { + fields: ['3'], + data: [], + }, + { newline: '\n' }, +); /** * Properties @@ -134,7 +131,7 @@ Papa.LocalChunkSize; /** * Parser */ -var parser = new Papa.Parser({}) +var parser = new Papa.Parser({}); parser.getCharIndex(); parser.abort(); -parser.parse("", 0, false); +parser.parse('', 0, false);