Security News
cURL Project and Go Security Teams Reject CVSS as Broken
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
替换js数学计算中产生的错误,比如:0.09999999 + 0.00000001
加法
减法
乘法
除法
用一个或多个其他对象来扩展一个对象,返回被扩展的对象。
如果第一个参数设置为true,则返回一个深层次的副本,递归地复制找到的任何对象。
否则的话,副本会与原对象共享结构。 未定义的属性将不会被复制,然而从对象的原型继承的属性将会被复制。
utils.extend({},{a:1},{b:2});
//结果
{
a:1,
b:2
}
深度冻结对象
Object.freeze的深度实现
例:utils.freeze({a:1});
深度拷贝对象
Object.assign的深度实现
例:utils.copy({a:1});
获取深度path的对象值
utils.getKeyValue({id:{v:'a'},b:2},"id.v");
//'a'
utils.getKeyValue({id:{v:['a','b']},b:2},"id.v[1]");
//'b'
对深度path的对象赋值
utils.setKeyValue({id:{v:1},b:2}, 'id.v', 2);
//{id:{v:2},b:2}
utils.setKeyValue({id:{v:['a','b']},b:2}, "id.v[1]", 'c');
//{id:{v:['a','c']},b:2}
将object转换成array.
toArray(object,keyName,valueName)
例:
utils.toArray({a:1,b:1},'key','value');
//结果
[{
key:'a',
value:1
},{
key:'b',
value:1
}]
utils.toArray({a:{b:2,d:4},b:{c:2,e:5}},'id');
//结果
[{
id:'a',
b:2,
d:4
},{
id:'b',
c:2,
e:5
}]
将array转换成object.
例:
utils.toObject(['a','b','c']);
//结果
{
a:'a',
b:'b',
c:'c'
}
utils.toObject([{id:'a',b:2},{id:'b',b:2}],'id');
//结果
{
a:{
id:'a',
b:2
},
b:{
id:'b',
b:2
}
}
utils.toObject([{id:'a',b:2},{id:'b',b:2}],'id',true);
//结果
{
a:{
id:'a',
b:2,
count:0
},
b:{
id:'b',
b:2,
count:1
}
}
保存本地localStorage
获取本地localStorage,如果type=='json',这转换出json对象。
获取本地localStorage,并转换出json对象。
删除本地localStorage。
保存本地cookie,path默认为/,minSec默认无限
保存获取cookie
清除所有cookie
删除cookie
获取对应的key数组
如果数组存在这个值,则删除,如果没有,则添加
左边填充0
删除cookie,path默认为/
let a = [{ title: '选择0', key: 0 }, { title: '选择1', key: 'a1', other: '其他值' }, { title: '选择2', key: 'a2' }, { title: '选择3', key: 'a3' }];
utils.dictMapping({value: 'a1', dict: a, titleField: 'title'})
//'选择1'
utils.dictMapping({value: ['a1', 'a2'], dict: a, titleField: 'title'})
//'选择1, 选择2'
utils.dictMapping({value: 'a1|a2', dict: a, titleField: 'title', connector: '|'})
//'选择1, 选择2'
生成唯一值
获取url参数,例:aa.com?a=1
utils.getURLParam('a', window.location.search) //1
获取author, 配合umock系统
FAQs
js-utils, js, util
The npm package hey-utils receives a total of 62 weekly downloads. As such, hey-utils popularity was classified as not popular.
We found that hey-utils 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
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Security News
Biden's executive order pushes for AI-driven cybersecurity, software supply chain transparency, and stronger protections for federal and open source systems.