[Feature] Add automatic header detection
Author: cow1337killer3Created May 10, 2026Updated May 10, 2026
You can automatically detect headers like this:
For each cell, you can determine its “type”:
- Empty
- Boolean
- Number
- String: for strings, there’s 4 non-exclusive subtypes, and a cell can be more than 1 of them at the same time. Basically, each subtype is just if the cell contains certain kinds of characters, using the following patterns:
- Digit:
/\d/ - Letter:
/[a-zA-Z]/ - Word:
/(^|[ _\-\t])[a-zA-Z][a-zA-Z\-\‘]*([ _\-\t]|$)/ - Punctuation:
/[\?\!\.\,\:\;\’\”\/\-\(\)\&\[\]/ - Special char:
/\#\%\$\@\^\*\+\=\_\|\~\<\>\{\}\\/
- Digit:
Detecting a header:
- For the first row, find each column’s type(s)
- For all the other rows combined, find for each column:
- Possible types: add the type if it appears in any of the rows
- Universal types: add the type if it appears in every row
- Calculate a “difference score” for the first row:
- Each column of the first row is considered “different” if either:
- It has a type that doesn’t appear in the “possible types” of the other rows. Example: first row column contains a punctuation character but none of the other rows do
- It doesn’t have a type that appears in the “universal types” of the other rows. Example: every other row contains an @ symbol but the first row column doesn’t
- If a certain threshold of columns in the first row are different, it’s determined to be a header. Maybe that’d be by a certain % of columns, like >25% columns being different. Maybe you’d scale that based on the total # of rows, since there’s more certainty that the first row is different if there’s more rows to compare it to. Maybe scale the threshold from like 50% at <20 rows to 10% at >1000 rows
- Each column of the first row is considered “different” if either:
Source: mholt/PapaParse