Skip to content

Instantly share code, notes, and snippets.

@Blezzoh
Last active February 25, 2020 00:09
Show Gist options
  • Save Blezzoh/34e3717738ed79beac06f4ed992077a5 to your computer and use it in GitHub Desktop.
Save Blezzoh/34e3717738ed79beac06f4ed992077a5 to your computer and use it in GitHub Desktop.
Date.prototype.isValid = function() {
// An invalid date object returns NaN for getTime() and NaN is the only
// object not strictly equal to itself.
// eslint-disable-next-line
return this.getTime() === this.getTime();
};
const filterTypes = {
year: (rows, id, filterValue) => {
return rows.filter(row => {
const rowValue = row.values[id];
return rowValue !== undefined &&
Number(filterValue) &&
new Date(rowValue) &&
new Date(rowValue).isValid()
? new Date(rowValue).getFullYear() === Number(filterValue)
: true;
});
},
//default
text: (rows, id, filterValue) => {
return rows.filter(row => {
const rowValue = row.values[id];
return rowValue !== undefined
? String(rowValue)
.toLowerCase()
.startsWith(String(filterValue).toLowerCase())
: true;
});
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment