html5csv icon indicating copy to clipboard operation
html5csv copied to clipboard

refactor common code that teases numbers from strings in table or CSV input

Open DrPaulBrewer opened this issue 11 years ago • 0 comments

These are mostly notes I am making to myself, but if anyone wants to comment, go ahead.

affected functions:

  • shared.parseCSV
  • `shared.fromTable`
    
  • editor()'s private func onCellChange()
  • If meta data were created about header rows on CSV object creation (at begin or after reading a line in fetch) then the code would have better direction of when and in what columns to tease numbers from strings. However, not all data has a header row. Some data has rows whose column types, number of columns, and meanings vary from one row to the next and I think it is desirable to support arbitrary comma separated data, including non-square data.
  • There is duplication of need to tease numbers, or null/undefined in input from tables and input CSV files and similar code in shared.parseCSV and shared.fromTable. code in onCellChange() is a little simpler.
  • In the shared routines cells are set to null or undefined when encountering a string "null" or "undefined".
  • In light of how JSON-serialization works, setting anything to undefined is probably a bad idea. undefined does not JSON-serialize across bare values, objects, and arrays (at least on chrome, the results are undefined, an omitted key:value pair, and a null element and the last two are obviously not invertible). JSON is used in the interactions with Storage and future ajax.
  • The goals should be: tease numbers from strings consistently in user, table, or file input; handle empty or null elements in a way that makes sense; avoid use of undefined as it tends to create inconsistencies

Question whose answers should be determined before refactoring:

  • When, if ever, should null be converted consistently to a blank string or a blank string to null or anything else to/from null when reading or writing data? Should null be avoided completely and all CSVs be in terms of string/number?
  • If something is undefined or the string "undefined", what should happen? Perhaps string "undefined" or even string "null" is valid data in some use cases.

DrPaulBrewer avatar Aug 11 '13 06:08 DrPaulBrewer