mirror of
https://github.com/ente-io/ente.git
synced 2025-06-02 07:23:39 +00:00
29 lines
834 B
TypeScript
29 lines
834 B
TypeScript
/**
|
|
* Throw an exception if the given value is not a string.
|
|
*/
|
|
export const ensureString = (v: unknown): string => {
|
|
if (typeof v != "string")
|
|
throw new Error(`Expected a string, instead found ${String(v)}`);
|
|
return v;
|
|
};
|
|
|
|
/**
|
|
* Throw an exception if the given value is not a number.
|
|
*/
|
|
export const ensureNumber = (v: unknown): number => {
|
|
if (typeof v != "number")
|
|
throw new Error(`Expected a number, instead found ${String(v)}`);
|
|
return v;
|
|
};
|
|
|
|
/**
|
|
* Throw an exception if the given value is not an integral number.
|
|
*/
|
|
export const ensureInteger = (v: unknown): number => {
|
|
if (typeof v != "number")
|
|
throw new Error(`Expected a number, instead found ${String(v)}`);
|
|
if (!Number.isInteger(v))
|
|
throw new Error(`Expected an integer, instead found ${v}`);
|
|
return v;
|
|
};
|