mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-04 06:47:03 +00:00
Merge pull request #32650 from markdreyer/master
@types/papaparse: Update ParseConfig dynamicTyping configuration option.
This commit is contained in:
Vendored
+1
-1
@@ -97,7 +97,7 @@ export interface ParseConfig {
|
||||
quoteChar?: string; // default: '"'
|
||||
header?: boolean; // default: false
|
||||
trimHeaders?: boolean; // default: false
|
||||
dynamicTyping?: boolean; // default: false
|
||||
dynamicTyping?: boolean | { [headerName: string]: boolean; [columnNumber: number]: boolean;} | ((field: string | number) => boolean); // default: false
|
||||
preview?: number; // default: 0
|
||||
encoding?: string; // default: ""
|
||||
worker?: boolean; // default: false
|
||||
|
||||
@@ -2,12 +2,12 @@
|
||||
|
||||
import Papa = require("papaparse");
|
||||
import {
|
||||
ParseConfig,
|
||||
UnparseConfig,
|
||||
UnparseObject,
|
||||
ParseError,
|
||||
ParseMeta,
|
||||
ParseResult
|
||||
ParseConfig,
|
||||
UnparseConfig,
|
||||
UnparseObject,
|
||||
ParseError,
|
||||
ParseMeta,
|
||||
ParseResult
|
||||
} from "papaparse";
|
||||
import { Readable } from "stream";
|
||||
|
||||
@@ -19,14 +19,26 @@ var res = Papa.parse("3,3,3");
|
||||
res.errors[0].code;
|
||||
|
||||
Papa.parse("3,3,3", {
|
||||
delimiter: ';',
|
||||
comments: false,
|
||||
delimiter: ';',
|
||||
comments: false,
|
||||
trimHeaders: false,
|
||||
step: function (results, p) {
|
||||
p.abort();
|
||||
results.data.length;
|
||||
},
|
||||
dynamicTyping: true
|
||||
});
|
||||
|
||||
step: function (results, p) {
|
||||
p.abort();
|
||||
results.data.length;
|
||||
}
|
||||
Papa.parse("3,3,3", {
|
||||
dynamicTyping: (field: string | number): boolean => /headerName/i.test(field.toString())
|
||||
});
|
||||
|
||||
Papa.parse("3,3,3", {
|
||||
dynamicTyping: {'headerName': true}
|
||||
});
|
||||
|
||||
Papa.parse("3,3,3", {
|
||||
dynamicTyping: {5: true}
|
||||
});
|
||||
|
||||
var file = new File(null, null, null);
|
||||
@@ -35,20 +47,20 @@ Papa.parse(file, {
|
||||
transform: function(value, field) {
|
||||
|
||||
},
|
||||
complete: function (a, b) {
|
||||
a.meta.fields;
|
||||
b.name;
|
||||
}
|
||||
complete: function (a, b) {
|
||||
a.meta.fields;
|
||||
b.name;
|
||||
}
|
||||
});
|
||||
|
||||
const readable = new Readable()
|
||||
const rows = [
|
||||
"1,2,3",
|
||||
"4,5,6"
|
||||
"1,2,3",
|
||||
"4,5,6"
|
||||
]
|
||||
|
||||
rows.forEach(r => {
|
||||
readable.push(r);
|
||||
readable.push(r);
|
||||
});
|
||||
|
||||
const papaStream: NodeJS.ReadWriteStream = Papa.parse(Papa.NODE_STREAM_INPUT);
|
||||
@@ -61,16 +73,16 @@ readable.pipe(papaStream);
|
||||
Papa.unparse([{ a: 1, b: 1, c: 1 }]);
|
||||
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: []
|
||||
fields: ["3"],
|
||||
data: []
|
||||
}, { newline: "\n" });
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user