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

Function isBetweenCodePoints

packages/effect/src/Schema.ts:8757–8778  ·  view source on GitHub ↗
(minimum: number, maximum: number, annotations?: Annotations.Filter)

Source from the content-addressed store, hash-verified

8755 * @since 4.0.0
8756 */
8757export function isBetweenCodePoints(minimum: number, maximum: number, annotations?: Annotations.Filter) {
8758 minimum = normalizeCardinality(minimum)
8759 maximum = normalizeCardinality(maximum)
8760 return makeFilter<string>(
8761 (input) => {
8762 const count = countCodePointsUpTo(input, maximum + 1)
8763 return count >= minimum && count <= maximum
8764 },
8765 {
8766 expected: minimum === maximum
8767 ? `a string with ${minimum} code points`
8768 : `a string with between ${minimum} and ${maximum} code points`,
8769 representation: {
8770 id: "effect/schema/isBetweenCodePoints",
8771 payload: { minimum, maximum }
8772 },
8773 toJsonSchema: () => ({ allOf: [{ minLength: minimum }, { maxLength: maximum }] }),
8774 arbitraryConstraint: { minCodePoints: minimum, maxCodePoints: maximum },
8775 ...annotations
8776 }
8777 )
8778}
8779
8780function countCodePointsUpTo(input: string, limit: number): number {
8781 if (limit === 0) return 0

Callers

nothing calls this directly

Calls 3

normalizeCardinalityFunction · 0.85
countCodePointsUpToFunction · 0.85
makeFilterFunction · 0.70

Tested by

no test coverage detected