Skip to content

v0.4.0

Choose a tag to compare

@themgoncalves themgoncalves released this 09 Jun 09:02
· 8 commits to main since this release

@cookbook/pathkit

0.4.0

Minor Changes

  • dcc0878: Add support for numeric value constraints with the new min and max constraints.

    Examples:

    {
      pattern: '/products/{value:decimal:max(10)}',
      path: '/products/9.99',
      matches: {
        match: true,
        params: { value: '9.99' },
      },
    }
    
    {
      pattern: '/products/{value:decimal:min(1)}',
      path: '/products/9.99',
      matches: {
        match: true,
        params: { value: '9.99' },
      },
    }
    
    {
      pattern: '/products/{value:decimal:min(1):max(10)}',
      path: '/products/9.99',
      matches: {
        match: true,
        params: { value: '9.99' },
      },
    }

    Both constraints expect a numeric argument and validate the route parameter value itself.

    min validates that the parameter value is greater than or equal to the specified number, while max validates that it is less than or equal to the specified number.

    These constraints are different from minlength and maxlength, which validate the length of the parameter value instead.

  • 21e7658: Add support for minimum- and maximum-length route parameters through the new minlength and maxlength constraints.

    Usage:

    /product/{slug:minlength(3)}
    /product/{slug:maxlength(50)}
    /product/{slug:minlength(3):maxlength(50)}

    Both constraints expect a positive integer argument. minlength validates that the route parameter value has at least the specified number of characters, while maxlength validates that it has no more than the specified number of characters.

  • 64d4844: Add support for UUID route parameters with the new uuid constraint.

    Examples:

    {
      pattern: '/users/{id:uuid}',
      path: '/users/7d444840-9dc0-11d1-b245-5ffdce74fad2',
      matches: {
        match: true,
        params: { id: '7d444840-9dc0-11d1-b245-5ffdce74fad2' },
      },
    }

    The uuid constraint validates that the route parameter value matches the canonical UUID format:

    xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

    This constraint accepts UUID-like values such as UUID v1, v3, v4, and v5, as long as they use the standard hyphenated UUID format.

Patch Changes

  • 21e7658: Fix decimal constraint validation to accept negative values and add tests coverage.
  • 4953807: Fix int constraint validation to accept negative values and add tests coverage.