1.1.0 • Published 4 months ago

launchable v1.1.0

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

Launchable

NPM Bundle

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:

  1. Open this repository in Cursor.
  2. Type ⌘K and paste "Create a brief documentation for docs of how to use with examples".
  3. Paste the output here.
1.1.0

4 months ago

1.0.1

5 months ago

1.0.0

5 months ago