
Security News
The Next Open Source Security Race: Triage at Machine Speed
Claude Opus 4.6 has uncovered more than 500 open source vulnerabilities, raising new considerations for disclosure, triage, and patching at scale.
属于自己用的一个辅助性类库,类似underscore。
cup.is.obj或cup.isObject检查一个变量是否是对象(该检测只针对{}的情况,array非对象)
cup.is.obj({}) //true
cup.is.obj([]) //false
cup.is.arr或cup.isArray检查一个变量是否是数组
cup.is.obj([]) //true
cup.is.obj({}) //false
cup.is.func或cup.isFunction检查一个变量是否是函数
cup.is.obj(function () {}) //true
cup.is.str或cup.isString检查一个变量是否是字符串
cup.is.str('') //true
cup.is.num或cup.isNumber检查一个变量是否是数字
cup.is.num(1) //true
cup.is.ip或cup.isIP检查一个变量是否是合法IP地址
cup.is.ip('192.168.1.1') //true
默认使用localStorage实现,如果浏览器不支持localStorage则用cookie
cup.db.set设置存储区内容,如果内容是对象或者数组会自动序列化成字符串
cup.set('a', {x: 1, y: 2});
cup.set('b', [1, 2, 3]);
cup.set('c', 1);
cup.set('d', 'hello')
cup.db.get获取存储区里面的内容,如果内容是对象或者数组会自动序列化成对象或者数组
cup.db.get('a') // {x: 1, y: 2}
cup.db.get('b') // [1, 2, 3]
cup.db.get('c') // 1
cup.db.get('d') // 'hello'
cup.db.del删除存储区内容
cup.db.del('a')
cup.db.get('a') //undefined
采用正则替换生成函数,函数再生成HTML字符串方式,并未加上安全性的措施,请用于可信任的内容生成。
cup.template.parsecup.template.parse('<h1><% title %></h1>', {title: 'hxy'})
//<h1>hxy</h1>
语法为在<% %>里面放置对象变量名则为直接输出变量内容,
可以在<% %>里面使用var|if|for|else|switch|case|break等js语句会转换成相应地逻辑。
var tmpl = '<h1><% title %></h1>'
+'<ul>'
+'<% for(vari=0;i<list.length;i++) {%>'
+'<li><% list[i].url %></li>'
+'<% } %>'
+'</ul>';
var data = {
title: 'hxy',
list: [
{url: 'www.google.com'},
{url: 'www.facebook.com'},
{url: 'www.twitter.com'}
]}
var html = cup.template.parse(tmpl, data);
/*
<h1>hxy</h1>
<ul>
<li>www.google.com</li>
<li>www.facebook.com</li>
<li>www.twitter.com</li>
</ul>
*/
如果模板比较大,里面的逻辑结构比较多和复杂的话,推荐使用缓存机制,这样效率会大大提升, 如果只是很简单的模板,则不推荐用缓存。
首次模板渲染的时候会将编译好的模板函数放入cup.db中,第二次渲染时则直接在cup.db中获取模板函数执行
cup.template.parse('<h1><% title %></h1>', {title: 'hxy'}, 'pagetitle')
FAQs
javascript helper
We found that cupjs demonstrated a healthy version release cadence and project activity because the last version was released less than 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
Claude Opus 4.6 has uncovered more than 500 open source vulnerabilities, raising new considerations for disclosure, triage, and patching at scale.

Research
/Security News
Malicious dYdX client packages were published to npm and PyPI after a maintainer compromise, enabling wallet credential theft and remote code execution.

Security News
gem.coop is testing registry-level dependency cooldowns to limit exposure during the brief window when malicious gems are most likely to spread.