Acme.BookStore.HttpApi.Host/node_modules/value-or-function/README.md

(开头部分) 4KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

<p align="center">
  <a href="http://gulpjs.com">
    <img height="257" width="114" src="https://raw.githubusercontent.com/gulpjs/artwork/master/gulp-2x.png">
  </a>
</p>

# value-or-function

[![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Build Status][travis-image]][travis-url] [![AppVeyor Build Status][appveyor-image]][appveyor-url] [![Coveralls Status][coveralls-image]][coveralls-url] [![Gitter chat][gitter-image]][gitter-url]

Normalize a value or function, applying extra args to the function

## Example

```js
var normalize = require('value-or-function');

// Values matching type are returned
var isEnabled = normalize('boolean', true);
// isEnabled === true

// Values not matching type return undefined
var isEnabled = normalize('boolean', 1);
// isEnabled === undefined

// Functions are called
var isEnabled = normalize('boolean', function() {
  return false;
});
// isEnabled === false

// Extra arguments are applied to function
var count = normalize('number', function(a, b) {
  return a + b;
}, 1, 2);
// count === 3

// Supply the function with context
var context = { c: 3 };
var count = normalize.call(context, 'number', function(a, b) {
  return a + b + this.c;
}, 1, 2);
// count === 6

// Values one of multiple types are returned
var isEnabled = normalize(['string', 'boolean'], true);
// isEnabled === true

// Provide a function as first argument to do custom coercion
var now = new Date();
var enabledSince = normalize(function(value) {
  if (value.constructor === Date) {
    return value;
  }
}, now);
// enabledSince === now

// Convenience methods are available for the built-in types
var result = normalize.object({});
var result = normalize.number(1);
后面还有 72 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。