(regExp: globalThis.RegExp, annotations?: Schema.Annotations.Filter)
| 4327 | * @since 4.0.0 |
| 4328 | */ |
| 4329 | export 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. |
no test coverage detected