Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
booleanjs是一个为Object和Array进行布尔运算(交/并/补)的轻量级工具库。
目前兼容commonjs AMD 以及普通的加载方式
使用npm进行安装
npm install booleanjs
var bool = require('booleanjs');
使用script标签引入
<script src="path/to/booleanjs/dist/boolean.min.js"></script>
var bool = window.bool;
下面是bool的方法列表:
{Object|Array} same({Object|Array}obj, ...{Object|Array|null}objs)
返回多个Object或多个Array的交集
注: 第一个参数必须是{Object}或者是{Array},否则会报错
当第一个参数为{Object}时,objs可传入的值为:
// a = {b: 2};
var a = bool.same(
{a: 1, b: 2, c: 3},
{a: 1, b: 2},
{b: 2, c: 4}
);
// a = {b: 2};
var a = bool.same(
{a: 1, b: 2, c: 3},
['b', 'c'],
{a: 1, b: 2}
);
当第一个参数为{Array}时,objs可传入的值为:
// a = ['1', 2];
var a = bool.same(
['1', 2, '3'],
[2, 4, '1']
);
// a = [];
var a = bool.same(
['1', 2, '3'],
[2, '1'],
[1]
);
{Object|Array} merge({Object|Array}obj, ...{Object|Array|null}objs)
返回多个Object或多个Array的并集
当第一个参数为{Object}时,效果跟Object.assign类似,区别在于,当属性的value为{Object}或{Array}时,不会对该属性做拷贝。
objs能传入的值为:
var a = {b: 1};
var x = {d: 1, e: a};
// c = {d: 2, e: {b: 1}, f: 3}
// c === x
var c = bool.merge(
x,
{d: 2},
{f: 3}
);
// c = {d: 2, e: {b: 2}, f: 3}
a.b = 2;
当第一个参数为{Array}时,objs可传入的值为:
var a = [1, 2, 3, 4];
// b = [1, 2, 3, 4, 7, 6]
// a === b
var b = bool.merge(
a,
[7, 4, 1],
[2, 6]
);
{Object|Array} exclude({Object|Array}obj, ...{Object|Array}objs)
返回obj与objs的补集
当第一个参数为{Object}时,objs可传入的值为:
// a = {d: 4}
var a = bool.exclude(
{a: 1, b: 3, c:3, d: 4},
{c: 4, d: 4},
['a', 'b']
);
当第一个参数为{Array}时,objs可传入的值为:
// a = [2]
var a = bool.exclude(
[1, 2, 3, 4],
[3, 1, 7],
[1, 4, 6]
);
{boolean} isEqual({*}obj1, {*}obj2)
判断两个对象是否深度相等,应该跟underscore实现的差不多
** 注 ** 能判断的类型有
// true
var a = bool.isEqual({}, {});
// false
var a = bool.isEqual(-0, +0);
// true
var a = bool.isEqual(NaN, NaN);
{boolean} isContain({*}obj1, {*}obj2)
判断obj1是否包含obj2
// true
var a = bool.isContain({}, null);
// true
var a = bool.isContain({a: 1, b: {c: 2}}, {b: {c: 2}});
// true
var a = bool.isContain([1, 2, 3, 4], [4, 3]);
FAQs
A boolean caculation tool for Object or Array. 对象或数组进行布尔运算的工具
The npm package booleanjs receives a total of 0 weekly downloads. As such, booleanjs popularity was classified as not popular.
We found that booleanjs demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.