MCPcopy Create free account
hub / github.com/Effect-TS/effect / makeIsBetween

Function makeIsBetween

packages/effect/src/Schema.ts:7687–7730  ·  view source on GitHub ↗
(deriveOptions: {
  readonly order: Order.Order<T>
  readonly annotate?:
    | ((options: {
      readonly minimum: T
      readonly maximum: T
      readonly exclusiveMinimum?: boolean | undefined
      readonly exclusiveMaximum?: boolean | undefined
    }) => Annotations.Filter)
    | undefined
  readonly formatter?: Formatter<T> | undefined
})

Source from the content-addressed store, hash-verified

7685 * @since 4.0.0
7686 */
7687export function makeIsBetween<T>(deriveOptions: {
7688 readonly order: Order.Order<T>
7689 readonly annotate?:
7690 | ((options: {
7691 readonly minimum: T
7692 readonly maximum: T
7693 readonly exclusiveMinimum?: boolean | undefined
7694 readonly exclusiveMaximum?: boolean | undefined
7695 }) => Annotations.Filter)
7696 | undefined
7697 readonly formatter?: Formatter<T> | undefined
7698}) {
7699 const greaterThanOrEqualTo = Order.isGreaterThanOrEqualTo(deriveOptions.order)
7700 const greaterThan = Order.isGreaterThan(deriveOptions.order)
7701 const lessThanOrEqualTo = Order.isLessThanOrEqualTo(deriveOptions.order)
7702 const lessThan = Order.isLessThan(deriveOptions.order)
7703 const formatter = deriveOptions.formatter ?? format
7704 return (options: {
7705 readonly minimum: T
7706 readonly maximum: T
7707 readonly exclusiveMinimum?: boolean | undefined
7708 readonly exclusiveMaximum?: boolean | undefined
7709 }, annotations?: Annotations.Filter) => {
7710 const gte = options.exclusiveMinimum ? greaterThan : greaterThanOrEqualTo
7711 const lte = options.exclusiveMaximum ? lessThan : lessThanOrEqualTo
7712 return makeFilter<T>(
7713 (input) => gte(input, options.minimum) && lte(input, options.maximum),
7714 {
7715 expected: `a value between ${formatter(options.minimum)}${options.exclusiveMinimum ? " (excluded)" : ""} and ${
7716 formatter(options.maximum)
7717 }${options.exclusiveMaximum ? " (excluded)" : ""}`,
7718 arbitraryConstraint: {
7719 order: deriveOptions.order,
7720 minimum: options.minimum,
7721 maximum: options.maximum,
7722 ...(options.exclusiveMinimum && { exclusiveMinimum: true }),
7723 ...(options.exclusiveMaximum && { exclusiveMaximum: true })
7724 },
7725 ...deriveOptions.annotate?.(options),
7726 ...annotations
7727 }
7728 )
7729 }
7730}
7731/**
7732 * Creates a divisibility check for any numeric type from a remainder function
7733 * and a zero value.

Callers 1

Schema.tsFile · 0.85

Calls 4

gteFunction · 0.85
lteFunction · 0.85
makeFilterFunction · 0.70
annotateMethod · 0.65

Tested by

no test coverage detected