Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@renoirb/validatable

renoirb38MIT1.2.0TypeScript support: included

Add validation rules to an object, and ability to check if a given string passes the rules

readme

Validatable

Curries an object/function with a "validatable" property containing ValidatableRules and a "validate" function.

CAUTION: This has been written back in 2013 and dearly needs refactoring.

import validatable from './validatable'

// Notice this MUST either be a class, an object, or a Function, it cannot be an arrow function.
class UsernameValidator {
  constructor() {
    validatable(this)
    this.validatable.addRule('size', true, /^[0-9a-zA-z\-_]{8,19}$/)
    this.validatable.addRule(
      'billable_format',
      false,
      /^[ABGKNPQSTWXZ]{1}[0-9]{8}$/,
    )
  }
}

// ... later in the code

const validator = new UsernameValidator()

// With rules above, "jjjjjj" should fail because it has less than 9 characters
const check1 = validator.validate('jjjjjj')
check.hasPassed() // => false

Context

In this package, we've migrated ECMAScript from @bit/renoirb.curries.curries.validatable, and copied it here. We could have had written the code here and exported it in isolation to bit. That could be done. But it isn't, it's also copied over to GitHub.com/renoirb/bits curries/. The use-case here was to migrate ECMAScript with modules, managed by TypeScript, without being converted to it just yet. We also wanted to have Jest test to work.

Next Steps

Migrate to TypeScript?

Assuming we want to rework that package, we could migrate it to TypeScript

changelog

Change Log - @renoirb/validatable

This log was last generated on Mon, 17 Aug 2020 02:57:48 GMT and should not be manually modified.

1.2.0

Mon, 17 Aug 2020 02:57:48 GMT

Minor changes

  • Rewrite into TypeScript

1.1.2

Mon, 03 Aug 2020 23:53:08 GMT

Version update only

1.1.1

Tue, 14 Jul 2020 03:23:31 GMT

Patches

  • Upgrading deps

1.1.0

Mon, 29 Jun 2020 02:44:25 GMT

Minor changes

  • Upgrading deps, minor refactor

1.0.2

Thu, 02 Jan 2020 23:25:02 GMT

Patches

  • Make TypeScript and TSLib peerDependency