Skip to content

crshmk/locals

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

basic everyday js utils; not much to see in this repo

i have some interesting js utils here

Client


getCookies

client

getCookies()
// { k: 'v' }

isEmail

isEmail('[email protected]')
// true

localStorage

assumes set item is safely stringified

storage.setItem('user', { email: '[email protected]'})
storage.getItem('user')
storage.removeItem('user')

scrollToSelector

String => Function

const scrollToFirstInvalidField = scrollToSelector('.invalid')

useEffect(scrollToFirstInvalidField, [invalidFields])

stampToLabel

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'

ucFirst

String => String

ucFirst('abcDe')
// 'AbcDe'
 useInterval(() => {
    ...
  }, 1000);

Server


log

a better console.log for Node using util.inspect

const logDepth = 3
log(nestedObject, logDepth)

writeTempFile

const filePath = await writeTempFile(fileName,  dataUrl, 'base64')

About

everyday javascript utils

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published