Hyperlinkv0.8.0-beta.28

Schema

Schema.isStartsWithfunctioneffect/Schema.ts:6845
(
  startsWith: string,
  annotations?: Annotations.Filter
): SchemaAST.Filter<string>

Validates at runtime that a string starts with the specified literal prefix.

Details

Notes: The JSON Schema and arbitrary metadata are built from ^${startsWith} without escaping regexp metacharacters. If the prefix contains regexp syntax, generated patterns may not be equivalent to the runtime startsWith check.

String checks
Source effect/Schema.ts:684520 lines
export function isStartsWith(startsWith: string, annotations?: Annotations.Filter) {
  const formatted = JSON.stringify(startsWith)
  return makeFilter(
    (s: string) => s.startsWith(startsWith),
    {
      expected: `a string starting with ${formatted}`,
      meta: {
        _tag: "isStartsWith",
        startsWith,
        regExp: new globalThis.RegExp(`^${startsWith}`)
      },
      arbitrary: {
        constraint: {
          patterns: [`^${startsWith}`]
        }
      },
      ...annotations
    }
  )
}
Referenced by 1 symbols