项目作者: nuxy

项目描述 :
Create JavaScript functions with built-in argument type detection.
高级语言: JavaScript
项目地址: git://github.com/nuxy/DataType-FU.git
创建时间: 2014-11-26T20:08:30Z
项目社区:https://github.com/nuxy/DataType-FU

开源协议:Other

下载


DataType-FU Build Status

One of the most annoying things I find about the JavaScript language is the lack of support for strict typing when declaring function variable arguments. Because of this I’m forced to litter my code with conditions that contain typeof and instanceof to type check each argument.

This is my attempt to resolve this madness.

Installation

This package can be easily installed using:

Bower

  1. $ bower install datatype-fu

NPM

  1. $ npm install datatype-fu

Use Example

  1. var fu = require('datatype-fu').fu; // NodeJS usage
  2. // standard types
  3. var doSomething = fu(
  4. ['Array', 'Boolean', 'Function', 'Number', 'Object', 'String', 'undefined'],
  5. function(arr, bool, func, num, obj, str, und) {
  6. // do something with the values
  7. }
  8. );
  9. doSomething(
  10. ['bucket1', 'bucket2', 'bucket3'],
  11. true,
  12. function() {},
  13. 1234567890,
  14. { key: 'value' },
  15. 'Hello World',
  16. undefined
  17. );
  18. // Wildcard and conditional types
  19. var doSomething = fu(
  20. ['*', 'Array|Boolean|undefined'],
  21. function(any, cond) {
  22. // do something with the values
  23. }
  24. );

Performance

General test cases have been created on jsPerf to measure fu’d operations across supported web browsers.

Maintainer

For feedback, bug reports, or other comments, feel free to contact me at: devel at mbrooks dot info

License and Warranty

This package is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose.

DataType-FU is provided under the terms of the MIT license

Author

Marc S. Brooks