diff --git a/types/papaparse/index.d.ts b/types/papaparse/index.d.ts index 183720367e..a5eb70cf29 100644 --- a/types/papaparse/index.d.ts +++ b/types/papaparse/index.d.ts @@ -8,6 +8,7 @@ // Behind The Math // 3af // Janne Liuhtonen +// Raphaƫl Barbazza // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.2 @@ -35,10 +36,12 @@ export const unparse: (data: Array | Array> | UnparseObject, export const BAD_DELIMETERS: Array; // The true delimiter. Invisible. ASCII code 30. Should be doing the job we strangely rely upon commas and tabs for. -export const RECORD_SEP: string; +declare type RECORD_SEP_TYPE = ''; +export const RECORD_SEP = ''; // Also sometimes used as a delimiting character. ASCII code 31. -export const UNIT_SEP: string; +declare type UNIT_SEP_TYPE = ''; +export const UNIT_SEP = ''; // Whether or not the browser supports HTML5 Web Workers. If false, worker: true will have no effect. export const WORKERS_SUPPORTED: boolean; @@ -51,6 +54,9 @@ export let SCRIPT_PATH: string; declare type NODE_STREAM_INPUT_TYPE = 1; export const NODE_STREAM_INPUT = 1; +// The possible values for the ParseConfig property delimitersToGuess +declare type GuessableDelimiters = ',' | '\t' | '|' | ';' | RECORD_SEP_TYPE | UNIT_SEP_TYPE; + /** * Configurable Properties */ @@ -104,6 +110,7 @@ export interface ParseConfig { skipEmptyLines?: boolean | 'greedy'; // default: false fastMode?: boolean; // default: undefined withCredentials?: boolean; // default: undefined + delimitersToGuess?: GuessableDelimiters[]; // default: [',', '\t', '|', ';', Papa.RECORD_SEP, Papa.UNIT_SEP] // Callbacks step?(results: ParseResult, parser: Parser): void; // default: undefined diff --git a/types/papaparse/papaparse-tests.ts b/types/papaparse/papaparse-tests.ts index 966e185adb..e6d19dbe80 100644 --- a/types/papaparse/papaparse-tests.ts +++ b/types/papaparse/papaparse-tests.ts @@ -41,6 +41,18 @@ Papa.parse('3,3,3', { dynamicTyping: { 5: true }, }); +Papa.parse('4,4,4', { + delimitersToGuess: [';', ','], +}); + +Papa.parse('4,4,4', { + delimitersToGuess: [Papa.RECORD_SEP, '|', ',', ';'], +}); + +Papa.parse('4;4;4', { + delimitersToGuess: ['\t', Papa.UNIT_SEP], +}); + var file = new File(null, null, null); Papa.parse(file, {