Skip to content

Releases: losandes/polyn-blueprint

Fixes Blueprint Handling of Prototypes

20 May 15:38
Compare
Choose a tag to compare

When objects with a prototype are validated with blueprint, the output
values now implement that prototype.

Validates String Length for Type 'string'

17 May 14:11
f4bef10
Compare
Choose a tag to compare

While empty strings are of type string, that is rarely if ever a valid
input. This library is meant to keep validation simple, and to lean
towards common use, so it will prefer non-empty strings by default.

Adds TypeScript Definitions For Optionals

16 May 12:52
Compare
Choose a tag to compare

The optional features released in v2.1.0, and v2.1.1 are now available in TypeScript.

Adds Support for `withDefault` Factories

16 May 04:41
7651684
Compare
Choose a tag to compare

withDefault also accepts functions, and will execute them if they
are used as the value, so your default values can be factories
(i.e. to generate ids, calculate based on local scope, etc.)

const uuid = require('uuid/v4')
const { blueprint, optional } = require('@polyn/blueprint')
const UUID_REGEX = /^[0-9A-F]{8}-[0-9A-F]{4}-[4][0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i

const optionalValues = blueprint('optionalValues', {
  idOrNewId: optional(UUID_REGEX).withDefault(uuid) // will generate a new uuid as default
})

Adds `optional` and `optional.withDefault`

16 May 04:03
76c796f
Compare
Choose a tag to compare

The optional function allows you to make any validator, even function, and expression based validators, optional. It also supports default values, which are used in the even that the given inputs are null, or undefined. If an input is defined, and it doesn't pass validation, the default value is not used: an error will still be produced.

const { blueprint, gt, optional } = require('@polyn/blueprint')

const optionalValues = blueprint('optionalValues', {
  stringOrDefault: optional('string').withDefault('foo'),
  maybeGt20: optional(gt(20)),
  gt20OrDefault: optional(gt(20)).withDefault(42),
  maybeEnum: optional(/^book|magazine$/),
  enumOrDefault: optional(/^book|magazine|product$/).withDefault('product'),
  maybeCustom: optional(({ value }) => typeof value === 'string')
    .withDefault('custom')
})

Fixes Error Messages For Nested Blueprints

13 May 14:31
Compare
Choose a tag to compare

Registered blueprint error messages were different than simply nesting an object in a blueprint: the property names weren't qualified. This fixes that so properties that are validated against a registered blueprint have qualified error messages (i.e. instead of "expected id {null} to be {string}", we see "expected user.id {null} to be {string}").

NPM Publishing Cleanup

12 May 16:11
0b294cb
Compare
Choose a tag to compare
  • Removes unnecessary files from npm
  • Updates README with more examples, and a TOC

Guards The Args For Default Validation Messages

10 May 04:22
d0f9210
Compare
Choose a tag to compare

Removes the possibility of a null pointer exception in the default error messages

Guards The Args For Default Validation Messages

10 May 04:18
64033ae
Compare
Choose a tag to compare

Removes the possibility of a null pointer exception in the default error messages

Improves Validation Messages

10 May 04:10
719f934
Compare
Choose a tag to compare

Makes validation messages more consistent, and concise. Also adds more context about
what was expected, and what was encountered.