Skip to main content

misc

AsChildProp

type AsChildProp = boolean;

Defined in: src/utils/misc/misc.ts:32

When true, the component will render its child as the root element instead of creating a new DOM element. This allows passing the component's props and styling to a custom child component using Radix UI's Slot pattern.

Two major use cases:

  • to reuse styles of a component, but render it using different element
  • to inject event handlers without passing them manually

Example

// Renders a link as a badge
<Badge asChild>
<a href="https://example.com">Link Badge</a>
</Badge>

Default

false

InitialState

type InitialState<T> = T | () => T;

Defined in: src/utils/misc/misc.ts:44

Type representing a value that can be either a direct value or a function that returns that value. Useful for lazy initialization of state values.

Type Parameters

Type Parameter
T

Nil

type Nil<T> = T | null | undefined;

Defined in: src/utils/misc/misc.ts:50

Type representing a value that can be null or undefined. Shorthand for T | null | undefined.

Type Parameters

Type Parameter
T

Url

type Url = string | UrlObject;

Defined in: src/utils/misc/misc.ts:55

Type representing a URL that can be either a string or a URL object.


PartialSome

type PartialSome<T, K> = Omit<T, K> & Partial<Pick<T, K>>;

Defined in: src/utils/misc/misc.ts:65

Make some fields in the object partial.

Type Parameters

Type Parameter
T
K extends keyof T

Example

PartialSome<{ a: string, b: string, c: string }, 'a'> => { a?: string, b: string, c: string }

RequiredSome

type RequiredSome<T, K> = Partial<Omit<T, K>> & Required<Pick<T, K>>;

Defined in: src/utils/misc/misc.ts:76

Make provided fields in the object required and the rest of fields partial.

Type Parameters

Type Parameter
T
K extends keyof T

Example

RequiredSome<{ a: string, b: string, c: string }, 'a'> => { a: string, b?: string, c?: string }

Prettify

type Prettify<T> = { [K in keyof T]: T[K] } & object;

Defined in: src/utils/misc/misc.ts:91

Prettify makes complex object types easier to read by flattening intersections. Use this when you export or inspect inferred types. This only affects type presentation in tooling.

Type Parameters

Type Parameter
T

Example

type A = { a: string };
type B = { b: number };
type Mixed = A & B;
type Readable = Prettify<Mixed>; // { a: string; b: number }

isEmpty

const isEmpty: IsEmptyFunction;

Defined in: src/utils/misc/misc.ts:191

Checks if a value is empty. Handles strings, null/undefined, arrays, objects, and collections with size property.

Example

isEmpty(""); // true
isEmpty(null); // true
isEmpty([]); // true
isEmpty({}); // true
isEmpty(new Set()); // true
isEmpty("hello"); // false
isEmpty([1, 2, 3]); // false

not()

function not(value): boolean;

Defined in: src/utils/misc/misc.ts:38

Negates value. Useful for functional patterns and state callbacks.

Parameters

ParameterType
valueunknown

Returns

boolean


copyToClipboard()

function copyToClipboard(value): Promise<void>;

Defined in: src/utils/misc/misc.ts:96

Handles copying to clipboard and show confirmation toast.

Parameters

ParameterType
valuestring

Returns

Promise<void>


upperFirst()

function upperFirst(value): string;

Defined in: src/utils/misc/misc.ts:112

Makes first letter uppercased.

Parameters

ParameterType
valuestring

Returns

string

Example

upperFirst("lorem ipsum") => "Lorem ipsum"

times()

function times<T>(length, callback): T[];

Defined in: src/utils/misc/misc.ts:118

Generates an array with a specified length.

Type Parameters

Type Parameter
T

Parameters

ParameterType
lengthnumber
callback(index) => T

Returns

T[]


strategy()

function strategy<T, F>(record, enumValue): Record<T, F>[T];

Defined in: src/utils/misc/misc.ts:138

Utility to dynamically resolve a strategy pattern.

Provides correct types for enums, guaranteeing that record provides every enum key.

Type Parameters

Type Parameter
T extends string | number | symbol
F

Parameters

ParameterType
recordRecord<T, F>
enumValueT

Returns

Record<T, F>[T]

Example

enum Message {
success
error
}
strategy({
[Message.success]: "Saving file worked!",
[Message.error]: "Saving file failed. Please try again later!",
}, Message.error) // "Saving file failed. Please try again later!"

ensureString()

function ensureString(value): string | undefined;

Defined in: src/utils/misc/misc.ts:152

Ensures a value is a string, returning undefined if it's not.

Parameters

ParameterType
valueunknown

Returns

string | undefined

Example

ensureString("hello"); // "hello"
ensureString(123); // undefined

isObject()

function isObject(value): value is object;

Defined in: src/utils/misc/misc.ts:166

Type guard to check if a value is an object (and not null).

Parameters

ParameterType
valueunknown

Returns

value is object

Example

isObject({}); // true
isObject([]); // true
isObject(null); // false
isObject("string"); // false

formatBoolean()

function formatBoolean(value): "true" | "false";

Defined in: src/utils/misc/misc.ts:211

Formats a boolean value into a string representation. Returns "true" or "false" based on the boolean value.

Parameters

ParameterType
valueboolean

Returns

"true" | "false"

Example

formatBoolean(true); // "true"
formatBoolean(false); // "false"

formatNilBoolean()

function formatNilBoolean(value): "true" | "false" | null;

Defined in: src/utils/misc/misc.ts:224

Formats a boolean like formatBoolean, but returns null for nil values.

Parameters

ParameterType
valueNil<boolean>

Returns

"true" | "false" | null

Example

formatNilBoolean(true); // "true"
formatNilBoolean(false); // "false"
formatNilBoolean(null); // null
formatNilBoolean(undefined); // null

joinPaths()

function joinPaths(...segments): string;

Defined in: src/utils/misc/misc.ts:251

Joins path segments, handling leading/trailing slashes between segments. It accepts strings and numbers; ignores null/undefined/empty segments.

Parameters

ParameterType
...segmentsNil<string | number>[]

Returns

string

Examples

joinPaths("/api/v1/", "/users", "123"); // "/api/v1/users/123"
joinPaths("api", "users"); // "api/users"
joinPaths("https://example.com/", "/users/", "123"); // "https://example.com/users/123"
joinPaths("/a", "b?x=1#top"); // "/a/b?x=1#top"