Skip to content

Instantly share code, notes, and snippets.

@jfolds
Created November 18, 2019 22:30
Show Gist options
  • Save jfolds/ac36276c0ef340f43d73797286c197e7 to your computer and use it in GitHub Desktop.
Save jfolds/ac36276c0ef340f43d73797286c197e7 to your computer and use it in GitHub Desktop.
Some utils
/**
*
* @param {object} obj data object to parse columns from
* parses columns from an object's keys
*/
export function parseColumns(obj) {
if (!obj) {
return null;
}
return Object.keys(obj).map(key => ({ title: key, data: key }));
}
/**
*
* @param {array} ids array of integers
* gets next sequential value of provided integers
*/
export function getNextId(ids) {
let nextId = 0;
ids.forEach(id => {
if (id >= nextId) {
nextId = id + 1;
}
});
return nextId;
}
/**
*
* @param {string} email email to validate
* validates an email to be of _@_._ format
*/
export function emailIsValid(email) {
return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment