Product
Socket Now Supports uv.lock Files
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
用一个或多个其他对象来扩展一个对象,返回被扩展的对象。
如果第一个参数设置为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
获取对应的key数组
如果数组存在这个值,则删除,如果没有,则添加
左边填充0
删除cookie,path默认为/
生成唯一值
获取url参数,例:aa.com?a=1
getURLParam('a', window.location.search) //1
获取author, 配合umock系统
FAQs
js-utils, js, util
The npm package hey-utils receives a total of 13 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.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.
Security News
PEP 770 proposes adding SBOM support to Python packages to improve transparency and catch hidden non-Python dependencies that security tools often miss.