@httpx/assert
Version:
Assertions and typeguards
2 lines • 1.01 kB
JavaScript
import {formatErrMsg}from'./messages/errorMessages.mjs';import {isStringNonEmpty,isParsableSafeInt}from'./string.guards.mjs';import {isoDateTimeZRegexp}from'./string.utils.mjs';import {createAssertException}from'./utils/createAssertException.mjs';function c(t,e){if(!isStringNonEmpty(t))throw createAssertException(e,formatErrMsg("non-empty string",t))}function m(t,e){if(!isParsableSafeInt(t))throw createAssertException(e,formatErrMsg("string containing a safe integer",t))}function y(t,e){let r;if(typeof t!="string")r="INVALID_ARGUMENT";else if(t.length===24&&isoDateTimeZRegexp.test(t))try{r=new Date(t).toISOString().toUpperCase()===t.toUpperCase()?!0:"INVALID_DATE";}catch{r="INVALID_DATE";}else r="INVALID_FORMAT";if(r!==true)throw createAssertException(e,formatErrMsg(`string containing a strict iso date (${r})`,t))}export{m as assertParsableSafeInt,y as assertParsableStrictIsoDateZ,c as assertStringNonEmpty};//# sourceMappingURL=string.asserts.mjs.map
//# sourceMappingURL=string.asserts.mjs.map