Lodash教程

Lodash conforms method

语法

_.conforms(source)
Creates a function that invokes the predicate properties of source with the corresponding property values of a given object, returning true if all predicates return truthy, else false.

参数

source (Object) − The object of property predicates to conform to.

输出

(Function) − Returns the new spec function.

实例

var _ = require('lodash');
var check = _.cond([
   [_.matches({ 'a': 1 }), _.constant('matches A')],
   [_.conforms({ 'b': _.isNumber }), _.constant('matches B')],
   [_.stubTrue, _.constant('no match')]
]);
 
console.log(check({ 'a': 1, 'b': 2 }));
console.log(check({ 'a': 0, 'b': 1 }));
console.log(check({ 'a': '1', 'b': '2' }));
Save the above program in tester.js. Run the following command to execute this program.

Command

\>node tester.js

输出

matches A
matches B
no match
昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4