basic everyday js utils; not much to see in this repo
i have some interesting js utils here
client
getCookies()
// { k: 'v' }
isEmail('[email protected]')
// true
assumes set item is safely stringified
storage.setItem('user', { email: '[email protected]'})
storage.getItem('user')
storage.removeItem('user')
String => Function
const scrollToFirstInvalidField = scrollToSelector('.invalid')
useEffect(scrollToFirstInvalidField, [invalidFields])
String => unixTimestampMilliseconds => String
Unless handling dates across time zones to the hour, date libraries are overkill. Some version of this is often fine.
const timestamp = '1677104219000'
const makeMonthDayLabel = stampToLabel('md')
makeMonthDayLabel(timestamp)
// '1/22'
const makeMonthDayYearLabel = stampToLabel('mdy-')
makeMonthDayYearLabel(timestamp)
// '1-22-2023'
String => String
ucFirst('abcDe')
// 'AbcDe'
useInterval(() => {
...
}, 1000);
a better console.log for Node using util.inspect
const logDepth = 3
log(nestedObject, logDepth)
const filePath = await writeTempFile(fileName, dataUrl, 'base64')