0.0.7 • Published 9 months ago

sator-packages v0.0.7

Weekly downloads
-
License
ISC
Repository
github
Last release
9 months ago

getContrastColor

// Returns black or white depending on the colour to get a good contrast

getContrastColor(#000) // #ffffff
getContrastColor(#000000) // #ffffff

getContrastColor(#fff) // #000000
getContrastColor(#ffffff) // #000000

getTimeValue

Used to get the value of time based on the provided hours, minutes, seconds and milliseconds

// it will return milliseconds by default
getTimeValue({ hr: 1 }) // 3600000

// add target to determine the value to return e.g. minute
getTimeValue({ hr: 1 }, "mm") // 60
getTimeValue({ hr: 1 }, "hr") // 1

// Note, it doesn't round off, always return whole numbers
// Below is 1 minute, not 1.98
getTimeValue({ mm: 1, ss: 59, }, "mm") // 1

getDateKey

The goal is to return a date that is readable by both man and machine and can be passed easily as an argument to new Date()

getDateKey() // 2023-08-01
getDateKey("2028-03-01") // 2028-03-01

getDateTimeKey

The goal is to return a date that is readable by both man and machine and can be passed easily as an argument to new Date(). It returns the date and time

getDateTimeKey() // 2023-08-01T20:26:57+01:00
getDateTimeKey("2028-03-01") // 2028-01-20T07:19:01+00:00
getDateTimeKey("2028-01-20T08:22:01+01:00") // 2028-01-20T07:19:01+00:00+01:00

formatTime

Formats a time value into hr, mm (minutes), ss (seconds) and ms (milliseconds)

// format(value, from)
/**
 * from: indicates the type of value, in this case, it is converting seconds
 */
formatTime(ss, "ss"); // { hr: 2, mm: 30, ss: 45, ms: 500 }

getDaysDiff

Get the number of days in between two dates

// No date is provided, so it uses today
getDaysDiff() // 0

getDaysDiff("2023-08-10") // 4

getDaysDiff("2023-08-20") // -5

getDaysDiff("2023-08-20", "2023-08-28") // 8
0.0.7

9 months ago

0.0.6

9 months ago

0.0.5

10 months ago

0.0.4

10 months ago

0.0.3

10 months ago

0.0.2

10 months ago

0.0.1

10 months ago