Skip to content

Commit

Permalink
docs: update JSDoc
Browse files Browse the repository at this point in the history
  • Loading branch information
afiiif committed Feb 1, 2024
1 parent cacae9c commit 5a471db
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,27 @@
export type Maybe<T> = T | null | undefined;

/**
* Check if this runs on browser.
*/
export const isClient = typeof window !== 'undefined' && !('Deno' in window);

export const noop = () => {};

export const identityFn = <T>(value: T) => value;

/**
* Check if a value is not undefined and not null.
*
* ```ts
* const hasValue = (value: any) => value !== undefined && value !== null;
* ```
*/
export const hasValue = (value: any) => value !== undefined && value !== null;

/**
* If the value is a function, it will invoke the function.\
* If the value is not a function, it will just return it.
*/
export const getValue = <T, P extends any[]>(
valueOrComputeValueFn: T | ((...params: P) => T),
...params: P
Expand All @@ -12,10 +32,9 @@ export const getValue = <T, P extends any[]>(
return valueOrComputeValueFn;
};

export type Maybe<T> = T | null | undefined;

export const isClient = typeof window !== 'undefined' && !('Deno' in window);

/**
* Create an Error instance with custom props.
*/
export const createError = (message: string, props: Record<string, any>) => {
const error = Object.assign(new Error(message), props);
return error;
Expand Down

0 comments on commit 5a471db

Please sign in to comment.