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

Function isPattern

packages/effect/src/SchemaAST.ts:4329–4352  ·  view source on GitHub ↗
(regExp: globalThis.RegExp, annotations?: Schema.Annotations.Filter)

Source from the content-addressed store, hash-verified

4327 * @since 4.0.0
4328 */
4329export function isPattern(regExp: globalThis.RegExp, annotations?: Schema.Annotations.Filter) {
4330 const copy = new globalThis.RegExp(regExp)
4331 const payload = { source: copy.source, flags: copy.flags }
4332 return makeFilter(
4333 (s: string) => {
4334 copy.lastIndex = 0
4335 return copy.test(s)
4336 },
4337 {
4338 expected: `a string matching the RegExp ${payload.source}`,
4339 representation: {
4340 id: "effect/schema/isPattern",
4341 payload
4342 },
4343 // Keep the filter exportable so its JSON Schema annotations are preserved
4344 // when the RegExp constraint itself is omitted.
4345 toJsonSchema: () => [{}, true],
4346 arbitraryConstraint: {
4347 patterns: [payload]
4348 },
4349 ...annotations
4350 }
4351 )
4352}
4353
4354// Copies that update only context or encoding share a body.
4355// All other fields describe the body itself, including child contexts.

Callers 3

isStringFiniteFunction · 0.70
isStringBigIntFunction · 0.70
isStringSymbolFunction · 0.70

Calls 1

makeFilterFunction · 0.70

Tested by

no test coverage detected