@yoot/yoot
Version:
The core library for yoot, providing a CDN-agnostic, chainable API for image URL transformations and adapter integration.
100 lines (99 loc) • 3.3 kB
TypeScript
export { hasDimensions, hasIntrinsicDimensions, invariant };
export { isKeyOf, isEmpty, isFunction, isNullish, isNumber, isPlainObject, isString, isUrl };
/**
* Determines if a value is a plain object.
*
* @internal
* @param value - The value to check.
* @returns True if the value is a valid URL.
*/
declare function isPlainObject(value: unknown): value is Record<string, unknown>;
/**
* Determines if a value is a valid URL string.
*
* @internal
* @param value - The value to check.
* @returns True if the value is a valid URL.
*/
declare function isUrl(value: unknown): value is string;
/**
* Checks if the input object possesses defined numeric `width` and `height` properties.
*
* @remarks This is a type predicate that narrows the input's type if true. *
* @internal
* @typeParam Dimensions - The shape of the dimensions object.
* @typeParam Input - The shape of the input object.
* @param input - The object to check, potentially having optional width and height.
* @returns True if `input.width` and `input.height` are both valid numbers.
*/
declare function hasDimensions<Dimensions extends {
width: number;
height: number;
}, Input extends Record<string, unknown>>(input?: Input): input is Dimensions & Input;
/**
* @deprecated Use `hasDimensions` instead.
* @internal
*/
declare const hasIntrinsicDimensions: typeof hasDimensions;
/**
* Determines if a value is a function.
*
* @internal
* @param value - The value to check.
* @returns True if the value is a function.
*/
declare function isFunction(value: unknown): value is (...args: unknown[]) => unknown;
/**
* Determines if a value is a string.
*
* @internal
* @param value - The value to check.
* @returns True if the value is a string.
*/
declare function isString(value: unknown): value is string;
/**
* Determines if a value is a finite number.
*
* @internal
* @param value - The value to check.
* @returns True if the value is a number and finite.
*/
declare function isNumber(value: unknown): value is number;
/**
* Determines if a value is empty — `null`, `undefined`, or an empty string.
*
* @internal
* @param value - The value to check.
* @returns True if the value is nullish or an empty string.
*/
declare function isEmpty(value: unknown): value is null | undefined | '';
/**
* Determines if a value is `null` or `undefined`.
*
* @internal
* @param value - The value to check.
* @returns True if the value is nullish.
*/
declare function isNullish(value: unknown): value is null | undefined;
/**
* Returns true if `key` exists in `map`; narrows to known keys.
* @internal
*/
declare function isKeyOf<K extends keyof T, T extends object>(key: unknown, map: T): key is K;
/**
* Provide a condition and if that condition is falsey, this throws an error
* with the given message.
*
* @remarks
* Based on https://github.com/epicweb-dev/invariant/blob/main/src/index.ts
* License: MIT
*
* @example
* invariant(typeof value === 'string', `value must be a string`)
*
* @internal
* @param condition - Condition to check
* @param message - Message to throw (or a callback to generate the message)
* @throws InvariantError if condition is falsey
*/
declare function invariant(condition: unknown, message: string | (() => string)): asserts condition;