19 lines
819 B
TypeScript
19 lines
819 B
TypeScript
export function isNullishOrEmpty(input: unknown): boolean {
|
|
return (
|
|
input === null || input === undefined || (typeof input === "string" && input.trim() === "")
|
|
);
|
|
}
|
|
|
|
// Función genérica para asegurar valores básicos
|
|
export function ensure<T>(value: T | undefined | null, defaultValue: T): T {
|
|
return value ?? defaultValue;
|
|
}
|
|
|
|
// Implementaciones específicas para tipos básicos
|
|
export const ensureString = (value?: string): string => ensure(value, "");
|
|
export const ensureNumber = (value?: number): number => ensure(value, 0);
|
|
export const ensureBoolean = (value?: boolean): boolean => ensure(value, false);
|
|
export const ensureBigInt = (value?: bigint): bigint => ensure(value, BigInt(0));
|
|
export const ensureSymbol = (value?: symbol, defaultSymbol = Symbol()): symbol =>
|
|
ensure(value, defaultSymbol);
|