| 4429 | * @since 3.10.0 |
| 4430 | */ |
| 4431 | export const startsWith = <S extends Schema.Any>( |
| 4432 | startsWith: string, |
| 4433 | annotations?: Annotations.Filter<Schema.Type<S>> |
| 4434 | ) => |
| 4435 | <A extends string>(self: S & Schema<A, Schema.Encoded<S>, Schema.Context<S>>): filter<S> => { |
| 4436 | const formatted = JSON.stringify(startsWith) |
| 4437 | return self.pipe( |
| 4438 | filter( |
| 4439 | (a) => a.startsWith(startsWith), |
| 4440 | { |
| 4441 | schemaId: StartsWithSchemaId, |
| 4442 | [StartsWithSchemaId]: { startsWith }, |
| 4443 | title: `startsWith(${formatted})`, |
| 4444 | description: `a string starting with ${formatted}`, |
| 4445 | jsonSchema: { pattern: `^${startsWith}` }, |
| 4446 | ...annotations |
| 4447 | } |
| 4448 | ) |
| 4449 | ) |
| 4450 | } |
| 4451 | |
| 4452 | /** |
| 4453 | * @category schema id |