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

Function isStartingWith

packages/effect/src/Schema.ts:7297–7316  ·  view source on GitHub ↗
(startsWith: string, annotations?: Annotations.Filter)

Source from the content-addressed store, hash-verified

7295 * @since 4.0.0
7296 */
7297export function isStartingWith(startsWith: string, annotations?: Annotations.Filter) {
7298 const formatted = JSON.stringify(startsWith)
7299 const regExp = new globalThis.RegExp(`^${RegExp_.escape(startsWith)}`)
7300 const jsonSchemaLiteral = startsWith.replace(/[\uD800-\uDBFF]$/, "")
7301 return makeFilter(
7302 (s: string) => s.startsWith(startsWith),
7303 {
7304 expected: `a string starting with ${formatted}`,
7305 representation: {
7306 id: "effect/schema/isStartingWith",
7307 payload: { startsWith }
7308 },
7309 toJsonSchema: () => literalToJsonSchema(jsonSchemaLiteral, startsWith, `^${RegExp_.escape(jsonSchemaLiteral)}`),
7310 arbitraryConstraint: {
7311 patterns: [{ source: regExp.source, flags: regExp.flags }]
7312 },
7313 ...annotations
7314 }
7315 )
7316}
7317/**
7318 * Validates at runtime that a string ends with the specified literal suffix.
7319 *

Callers

nothing calls this directly

Calls 3

literalToJsonSchemaFunction · 0.85
makeFilterFunction · 0.70
replaceMethod · 0.45

Tested by

no test coverage detected