Uecko_ERP/packages/rdx-utils/src/helpers/utils.ts

19 lines
812 B
TypeScript
Raw Normal View History

2025-09-01 14:07:59 +00:00
export function isNullishOrEmpty(input: unknown): boolean {
return (
input === null || input === undefined || (typeof input === "string" && input.trim() === "")
);
}
2025-02-20 18:55:24 +00:00
// Función genérica para asegurar valores básicos
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);