-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
stringObjs support #14
Comments
worth adding, i think |
just realized the solution is to add one line to modify the inferred schema to set all columns to string type: https://jsfiddle.net/zv89euo5/ const { inferSchema, initParser } = uDSV;
const csvStr = `
a,b
1,50000
10,5
`.trim();
const schema = inferSchema(csvStr);
// set all columns as strings
schema.cols.forEach(c => { c.type = 's'; });
const parser = initParser(schema);
const data = parser.typedObjs(csvStr);
console.log(data); |
This is obviously a very simple fix, thanks @leeoniya ! Though it definitely feels like the interface of the library should allow this more explicitly, or that at least it would be worth giving this as an example explicitly in the docs. I was initially confused and wondering if I was missing something in the docs about such a functionality, until I found this issue. The main use case where this comes in handy is where I don't know the list of columns, but I know that all of the should be read as strings. But also, it's easiest for me to just get an array of objects from the parser. This feels like a very common case? In terms of an interface, if
|
added in 55686c5 |
Hello!
I need to convert CSV to key:value dictionary. Values need to be string-typed.
From the example, I realized that there are two options:
There is no way to parse csv to objects where values are strings.
The text was updated successfully, but these errors were encountered: