1.1.0 • Published 4 months ago
launchable v1.1.0
Launchable
All the Javascript shared logic and helpers used by Launchable Studio.
Installation
npm install launchable
yarn add launchable
Usage
cx(className, conditionals)
Generates a string of class names based on the provided base class name and a set of conditional class names.
We use it to conditionally style elements.
// returns "base-class conditional-class-1 conditional-class-3"
cx("base-class", {
"conditional-class-1": true,
"conditional-class-2": false,
"conditional-class-3": true,
});
dateFromNow(date)
Calculates the distance between the current date and the provided date.
// returns "5 days ago"
dateFromNow("2022-03-01");
// returns "2 months ago"
dateFromNow("2022-01-06");
defined(value)
Checks if a value is defined and not null.
We use it to conditionally render elements even when the value is an empty string or 0.
// returns true
defined(0);
// returns true
defined("");
// returns false
defined(undefined);
formatNumber(number)
Formats a number by inserting commas as thousand separators.
We use it to format large numbers in analytics stats, etc.
const num = 1234567890;
const formattedNum = formatNumber(num);
console.log(formattedNum); // Outputs: "1,234,567,890"
nullify(value)
Checks if the provided value is an empty string. If it is, it returns null; otherwise, it returns the original value.
We use it to prevent empty values in a nullable database column.
// returns null
nullify("");
// returns "Hello, World!"
nullify("Hello, World!");
Creating docs:
- Open this repository in Cursor.
- Type ⌘K and paste "Create a brief documentation for docs of how to use with examples".
- Paste the output here.