quoti-scripts
v0.4.0
Published
Utility functions to be used in `quoti` ecosystem
Downloads
4
Readme
Quoti-scripts
Utility functions to be used in quoti
ecosystem
Badges
Functions
isDue
startDate: string | number | Date | Dayjs;
currentDate: string | number | Date | Dayjs;
frequencyType: "D" | "d" | "W" | "w" | "M" | "m" | "Y" | "y";
frequencyValue: number;
// day of the weeks, 0 (sun) to 6 (sat)
dayOfWeek?: number[] = [];
const { isDue } = require("quoti-scripts");
// Tue Nov 20 2012
const startDate = new Date(2012, 10, 20)
// Fri Nov 23 2012
const currentDate = new Date(2012, 10, 23);
// Every 3 days
console.log(isDue(startDate, currentDate, "D", 3)); // true
const { isDue } = require("quoti-scripts");
// Tue Nov 20 2012
const startDate = new Date(2012, 10, 20)
// Fri Nov 23 2012
const currentDate = new Date(2012, 10, 23);
// Fri & Sat, every 5 weeks
const weekdays = [5, 6]
console.log(isDue(startDate, currentDate, "W", 3, [5])); // true
const { isDue } = require("quoti-scripts");
// Tue Nov 20 2012
const startDate = new Date(2012, 10, 20);
// Wed Mar 20 2013
const currentDate = new Date(2013, 2, 20);
// Every 5 months
console.log(isDue(startDate, currentDate, "M", 5)); // true
const { isDue } = require("quoti-scripts");
// Sun Apr 28 2013
const startDate = new Date(2013, 3, 28);
// Wed Apr 28 2021
const currentDate = new Date(2021, 3, 28);
// Every 8 years
console.log(isDue(startDate, currentDate, "Y", 8)); // true
color
darken
and lighten
Adjust the shade of the colour to a lighter or darker shade.
color: string;
percent?: number - default value is 20
type?: "rgb" | "hsl" | "hex" | "keyword" - default value is "hex"
the default value of type
is hex
const { darkenColor } = require("quoti-scripts")
// css colour keywords
const initialColour = "blue";
const finalColour = darkenColor(initialColour, 50, "keyword")
console.log(finalColour); // "#000080"
const { lightenColor } = require("quoti-scripts")
// hex colour
const initialColour = "#fa5a51";
const finalColour = lightenColor(initialColour, 45)
console.log(finalColour); // "#FEE4E3"
const { darkenColor } = require("quoti-scripts")
// hsl
const initialColour = "hsl(234 79% 55%)";
const finalColour = darkenColor(initialColour, 45, "hsl")
console.log(finalColour); // "hsl(234deg 79% 30.25%)"
const { lightenColor } = require("quoti-scripts")
// rgb
const initialColour = "rgb(140, 37, 14)";
const finalColour = lightenColor(initialColour, 45, "rgb")
console.log(finalColour); // "rgb(202, 53, 20)"
contrastColor
Returns a contrast colour that is best for accessibility. It only returns white
if the colour provided is too dark or black
if the colour is too light.
color: string;
type?: "rgb" | "hsl" | "hex" | "keyword";
const { contrastColor } = require("quoti-scripts")
const firstColour = "rgb(140, 37, 14)";
const secondColour = "rgb(202, 100, 120)";
const firstResult = contrastColor(firstColour, "rgb");
const secondResult = contrastColor(secondColour, "rgb");
console.log(firstResult); // white
console.log(secondResult); // black
const { contrastColor } = require("quoti-scripts")
const firstColour = "hsl(140deg 37% 14%)";
const secondColour = "hsl(202deg 100% 78%)";
const firstResult = contrastColor(firstColour, "hsl");
const secondResult = contrastColor(secondColour, "hsl");
console.log(firstResult); // white
console.log(secondResult); // black
const { contrastColor } = require("quoti-scripts")
const firstColour = "#ade";
const secondColour = "#ad301a";
const firstResult = contrastColor(firstColour);
const secondResult = contrastColor(secondColour);
console.log(firstResult); // black
console.log(secondResult); // white
const { contrastColor } = require("quoti-scripts")
const firstColour = "pink";
const secondColour = "forestgreen";
const firstResult = contrastColor(firstColour, "keyword");
const secondResult = contrastColor(secondColour, "keyword");
console.log(firstResult); // black
console.log(secondResult); // white