openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 3.5 kB
JavaScript
import{a as normalizeOptionalString}from"./string-coerce-BBqv4GXj.mjs";
//!packages/normalization-core/src/number-coercion.ts
function asFiniteNumber(e){return typeof e===`number`&&Number.isFinite(e)?e:void 0}function asPositiveFiniteNumber(e){const t=asFiniteNumber(e);return t&&t>0?t:void 0}function floorPositiveFiniteNumber(e){const t=asPositiveFiniteNumber(e);return t===void 0?void 0:Math.floor(t)}function asNonNegativeFiniteNumber(e){const t=asFiniteNumber(e);return t&&t<0?void 0:t}function asFiniteNumberInRange(e,t){const n=asFiniteNumber(e);if(n===void 0)return;if(t.min!==void 0){if(t.minExclusive?n<=t.min:n<t.min)return}if(t.max!==void 0){if(t.maxExclusive?n>=t.max:n>t.max)return}return n}function asSafeIntegerInRange(e,t){if(typeof e!==`number`||!Number.isSafeInteger(e))return;if(t.min!==void 0&&e<t.min)return;if(t.max!==void 0&&e>t.max)return;return e}function parseStrictInteger(e){if(typeof e===`number`)return Number.isSafeInteger(e)?e:void 0;const t=normalizeOptionalString(e);if(!t||!/^[+-]?\d+$/.test(t))return;const n=Number(t);return Number.isSafeInteger(n)?n:void 0}function asPositiveSafeInteger(e){return typeof e===`number`&&Number.isSafeInteger(e)&&e>0?e:void 0}function asPositiveInteger(e){return typeof e===`number`&&Number.isInteger(e)&&e>0?e:void 0}function asNonNegativeInteger(e){return typeof e===`number`&&Number.isInteger(e)&&e>=0?e:void 0}const MAX_TIMER_TIMEOUT_MS=2147e6;const MAX_TIMER_TIMEOUT_SECONDS=Math.floor(MAX_TIMER_TIMEOUT_MS/1e3);const MAX_DATE_TIMESTAMP_MS=864e13;function asDateTimestampMs(e){return asFiniteNumberInRange(e,{min:-864e13,max:MAX_DATE_TIMESTAMP_MS})}function parseDateStringTimestampMs(e){return typeof e===`string`?asDateTimestampMs(Date.parse(e)):void 0}function clampTimerTimeoutMs(e,t=1){const n=asFiniteNumber(e);if(n===void 0)return;return Math.min(Math.max(Math.floor(n),Math.max(1,Math.floor(t))),MAX_TIMER_TIMEOUT_MS)}function clampPositiveTimerTimeoutMs(e){const t=asFiniteNumber(e);if(t===void 0||t<=0)return;return clampTimerTimeoutMs(t)}function resolvePositiveTimerTimeoutMs(e,t){return clampPositiveTimerTimeoutMs(e)??resolveTimerTimeoutMs(t,1)}function resolveTimerTimeoutMs(e,t,n=1){const r=asFiniteNumber(e)??asFiniteNumber(t);const i=Math.max(0,Math.floor(n));if(r===void 0)return i;return Math.min(Math.max(Math.floor(r),i),MAX_TIMER_TIMEOUT_MS)}function resolveIntegerOption(e,t,n={}){const r=asFiniteNumber(e)??t;const i=Math.floor(r);const a=n.min===void 0?i:Math.max(n.min,i);return n.max===void 0?a:Math.min(n.max,a)}function resolveOptionalIntegerOption(e,t={}){if(typeof e!==`number`||!Number.isFinite(e))return;return resolveIntegerOption(e,e,t)}function resolveNonNegativeIntegerOption(e,t){return resolveIntegerOption(e,t,{min:0})}function parseStrictPositiveInteger(e){const t=parseStrictInteger(e);return t!==void 0&&t>0?t:void 0}function parseStrictNonNegativeInteger(e){const t=parseStrictInteger(e);return t!==void 0&&t>=0?t:void 0}export{resolveOptionalIntegerOption as _,asNonNegativeInteger as a,asPositiveSafeInteger as c,floorPositiveFiniteNumber as d,parseDateStringTimestampMs as f,resolveNonNegativeIntegerOption as g,resolveIntegerOption as h,asNonNegativeFiniteNumber as i,asSafeIntegerInRange as l,parseStrictPositiveInteger as m,MAX_TIMER_TIMEOUT_MS as n,asPositiveFiniteNumber as o,parseStrictNonNegativeInteger as p,asFiniteNumber as r,asPositiveInteger as s,MAX_DATE_TIMESTAMP_MS as t,clampPositiveTimerTimeoutMs as u,resolvePositiveTimerTimeoutMs as v,resolveTimerTimeoutMs as y};