import { assertNotNil } from "@uxf/core/utils/assert-not-nil";
const testObject: { value: number | null } = { value: 10 };
assertNotNil(testObject.value);
// is the same as
if (isNil(testObject.value)) {
throw new Error("Value is null");
}
import { camelCaseToDash } from "@uxf/core/utils/camelCaseToDash";
const example = camelCaseToDash("fooBar"); /* returns "foo-bar" */
import { capitalize } from "@uxf/core/utils/capitalize";
const example = capitalize("hello world"); /* returns "Hello world" */
import { composeRefs } from "@uxf/core/utils/composeRefs";
const firstRef = useRef<HTMLDivElement>(null);
const secondRef = useRef<HTMLDivElement>(null);
const example = <div ref={composeRefs(firstRef, secondRef)} />;
import { cx } from "@uxf/core/utils/cx";
/* fork of https://github.com/lukeed/clsx */
const example = cx("foo", true && "bar", "baz", false && "bam", undefined); /* returns "foo bar baz" */
import { filterNullish } from "@uxf/core/utils/filter-nullish";
filterNullish([0, "text", null, undefined, [], {}]); /* returns [0, "text", [], {}] */
import { forwardRef } from "@uxf/core/utils/forwardRef";
interface Props {
className?: string;
}
// will enforce 'displayName'
export const ExampleComponent = forwardRef<HTMLDivElement, Props>("ExampleComponent", (props, ref) => {
return <div className={props.className} ref={ref} />;
});
import { isEmpty } from "@uxf/core/utils/is-empty";
isEmpty("not-empty"); /* returns false */
isEmpty(""); /* returns true */
isEmpty(["1"]); /* returns false */
isEmpty([]); /* returns true */
import { isBrowser } from "@uxf/core/utils/isBrowser";
import { isServer } from "@uxf/core/utils/isServer";
const browserExample = isBrowser; /* returns true if DOM is available */
const serverExample = isServer; /* returns true if DOM is NOT available */
import { isNil } from "@uxf/core/utils/is-nil";
isNil(null); /* returns true */
isNil(undefined); /* returns true */
isNil(true); /* returns false */
isNil(1); /* returns false */
isNil(0); /* returns false */
isNil([]); /* returns false */
isNil("string"); /* returns false */
import { isNotNil } from "@uxf/core/utils/is-not-nil";
isNotNil(null); /* returns false */
isNotNil(undefined); /* returns false */
isNotNil(true); /* returns true */
isNotNil(1); /* returns true */
isNotNil(0); /* returns true */
isNotNil([]); /* returns true */
isNotNil("string"); /* returns true */
import { last } from "@uxf/core/utils/last";
last([1, 2]); /* returns 2 */
last([]); /* returns undefined */
import { slugify } from "@uxf/core/utils/slugify";
const example = slugify("Jak se dnes máte?"); /* returns "jak-se-dnes-mate" */
import { trimTrailingZeros } from "@uxf/core/utils/trimTrailingZeros";
const example = trimTrailingZeros("120,450"); /* returns "120,45" */