hydraulik-types

0.0.3 • Public • Published

hydraulik-types

$ npm i hydraulik-types --save

import { Str, Error, Type } from 'hydraulik-types'
 
// Type values shouldn't be reasigned.
new Str('hello world').validate
=> ''
new Str('hello world').isValid
=> true
 

API

#new value, [options]

#isValid: bool

#validate: string

returns the error message

#validation: string/null

Only relevant if you use your holds the tests.

Types

Type

any value is accepted

String

anything that listens to toString is accepted @min and @max decorators available for defining custom Types. This is used to validate the string length.

Error

empty strinsg is accepted

Custom Types

import Str, { max } from 'hydraulik-types/str'
 
@max(140)
class Tweet extends Str {
  constructor(...args){
    super(...args) // mandatory
    // access to options object through this.options
    // access to value through this.value
  }
 
  validation(){
    // The validation of the parent type is done before hand. no need to call super
    // Check out src/type.jsx to see how it is done
    // name is the name of the type, which can also be set througth options.name
    if (this.value.indexOf('i am being censored') > -1)
        return `${this.name} arn't censored` // return the error msg.
    // you don't have to specify a return value
  }
}

Readme

Keywords

none

Package Sidebar

Install

npm i hydraulik-types

Weekly Downloads

1

Version

0.0.3

License

GPL-3.0+

Last publish

Collaborators

  • doodzik