https://github.com/doodzik/hydraulik-types
https://github.com/doodzik/hydraulik-types
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/doodzik/hydraulik-types
- Owner: doodzik
- Created: 2015-05-28T10:12:17.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2015-08-10T13:44:38.000Z (almost 11 years ago)
- Last Synced: 2025-05-02T04:48:04.518Z (about 1 year ago)
- Language: JavaScript
- Size: 148 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# hydraulik-types
`$ npm i hydraulik-types --save`
```es6
import Str from 'hydraulik-types/lib/str'
// 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 - Str
anything that listens to toString is accepted
@min and @max decorators available for defining custom Types.
This is used to validate the string length.
### Boolean - Bool
Just True and False
### Error
empty strinsg is accepted
## Custom Types
```es6
import Str, { max } from 'hydraulik-types/lib/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
}
}
```