tt

tower-type

API for defining/sanitizing custom resource attribute types.

Showing:

Popularity

Downloads/wk

0

Maintenance

No Maintenance Data Available

Package

Dependencies

3

License

Type Definitions

Tree-Shakeable

No?

Categories

Readme

Tower Type

API for defining/sanitizing custom resource attribute types.

Installation

node.js:

$ npm install tower-type

browser:

$ component install tower/type

Example

Define comparators/validators for basic types:

var type = require('tower-type');

type('string')
  .validator('gte', function gte(a, b){
    return a.length >= b.length;
  })
  .validator('gt', function gt(a, b){
    return a.length > b.length;
  });

Define a custom type with custom validators:

var now = Date.parse('2013-05-01');

type('birthdate')
  .validator('can-drive', function(val){
    return now >= val;
  });

var validate = type.validator('birthdate.can-drive');
validate(Date.parse('1950-12-21')); // true

Sanitize values:

type('digits')
  .use(stripWhitespace)
  .use(stripLetters);

type('digits').sanitize('  1  foo b2a3r'); // 123

function stripWhitespace(val) {
  return val.replace(/\s+/g, '');
}

function stripLetters(val) {
  return val.replace(/[a-z]+/g, '');
}

Testing

Install testem:

$ npm install -g testem

Run tests:

$ testem

Then, open all the browsers you want to test by going to the outputted url defaulted to http://localhost:7357

Tests will run on any open browser linked to the stated url and your current Node environment.

Contributing

Before you send a pull request, make sure your code meets the style guidelines at https://github.com/tower/style-guide and all tests pass.

License

MIT

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100
No reviews found
Be the first to rate

Alternatives

No alternatives found

Tutorials

No tutorials found
Add a tutorial