sator-packages
TypeScript icon, indicating that this package has built-in type declarations

0.0.7 • Public • Published

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

Readme

Keywords

Package Sidebar

Install

npm i sator-packages

Weekly Downloads

0

Version

0.0.7

License

ISC

Unpacked Size

34.5 kB

Total Files

52

Last publish

Collaborators

  • diorla