MCPcopy
hub / github.com/Effect-TS/effect / pattern

Function pattern

packages/effect/src/Schema.ts:4396–4419  ·  view source on GitHub ↗
(
  regex: RegExp,
  annotations?: Annotations.Filter<Schema.Type<S>>
)

Source from the content-addressed store, hash-verified

4394 * @since 3.10.0
4395 */
4396export const pattern = <S extends Schema.Any>(
4397 regex: RegExp,
4398 annotations?: Annotations.Filter<Schema.Type<S>>
4399) =>
4400<A extends string>(self: S & Schema<A, Schema.Encoded<S>, Schema.Context<S>>): filter<S> => {
4401 const source = regex.source
4402 return self.pipe(
4403 filter(
4404 (a) => {
4405 // The following line ensures that `lastIndex` is reset to `0` in case the user has specified the `g` flag
4406 regex.lastIndex = 0
4407 return regex.test(a)
4408 },
4409 {
4410 schemaId: PatternSchemaId,
4411 [PatternSchemaId]: { regex },
4412 // title: `pattern(/${source}/)`, // avoiding this because it can be very long
4413 description: `a string matching the pattern ${source}`,
4414 jsonSchema: { pattern: source },
4415 ...annotations
4416 }
4417 )
4418 )
4419}
4420
4421/**
4422 * @category schema id

Callers 2

UUIDClass · 0.85
ULIDClass · 0.85

Calls 2

filterFunction · 0.70
pipeMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…