
Security News
PEP 810 Proposes Explicit Lazy Imports for Python 3.15
An opt-in lazy import keyword aims to speed up Python startups, especially CLIs, without the ecosystem-wide risks that sank PEP 690.
candy-bag,一个javascript
工具库。用了都说香。
使用npm
或yarn
包管理工具安装:
npm install candy-bag
在node
项目中使用CommonJS
导入方式:
const { firstUpperCase } = require('candy-bag')
在webpack
或vite
构建项目中使用ESM导入方式:
import { firstUpperCase } from 'candy-bag'
在html
静态页面中使用cdn
方式导入,同过该方式导入,将暴露一个全局对象CandyBag
所有的方法均可以从该对象中取出:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<!-- 通过cdn方式引入全局对象:CandyBag -->
<script src="https://cdn.jsdelivr.net/npm/candy-bag"></script>
<script>
const { firstUpperCase } = CandyBag
console.log(firstUpperCase('hello')) // Hello
</script>
</body>
</html>
获取一个number数组的求和: numArraySum
array :Number[]
:需要处理的数组,要求必须为number
类型组成,长度不限。
Number
:数组的总和
import { numArraySum } from 'candy-bag'
console.log(numArraySum([99, -1, 20])) // 118
将字符串的首字母转化为大写: firstUpperCase
message: String
:需要处理的字符串,由字母组成。
String
:首个字母被转化为大写的字符串
import { firstUpperCase } from 'candy-bag'
console.log(firstUpperCase('hello')) // Hello
防抖函数:debounce
fn: Function
:需要被执行的函数体, 必传
delay: Number
:每次触发函数延时多久,单位ms(毫秒),必传
immed: Boolean
:是否在首次立即执行,可选
resultCallback: Function
:执行后的回调函数,(result) => void
可从回调函数中拿到执行函数的返回值
Promise <any>
:返回Promise
,从then()
中可取出函数执行结果
import { debounce } from 'candy-bag'
const foo = () => {
console.log('foo 函数被执行');
};
const fooDebounce = debounce(foo, 500, true);
fooDebounce().then((res) => {
console.log(res); // "foo 函数被执行"
});
节流函数:throttle
fn: Function
:需要被执行的函数体, 必传
interval: Number
:每次触发间隔市场,单位ms(毫秒),必传
options: { leading: Boolean; trailing: Boolean; resultCallback?: (result: any) => void)}
:选项,可选。
leading:是否立即执行
trailing:最后是否执行一次
resultCallback:执行后的回调函数,(result) => void
可从回调函数中拿到执行函数的返回值
Promise <any>
:返回Promise
,从then()
中可取出函数执行结果
import { throttle } from 'candy-bag'
const foo = () => {
return 'foo 函数被执行';
};
const fooThrottle = throttle(foo, 1000, {
leading: true,
trailing: false
});
fooThrottle().then(res => {
console.log(res) // "foo 函数被执行"
})
本项目基于tools-base开发。
另招募大佬一起维护本项目。一起造轮子,我们不仅制造轮子,我们还要做轮子的搬运工
联系方式:wx:coder7915
觉得还不戳的话请留下一个star吧~
FAQs
candy-bag,一个`javascript`工具库。用了都说香。
We found that candy-bag 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
An opt-in lazy import keyword aims to speed up Python startups, especially CLIs, without the ecosystem-wide risks that sank PEP 690.
Security News
Socket CEO Feross Aboukhadijeh discusses the recent npm supply chain attacks on PodRocket, covering novel attack vectors and how developers can protect themselves.
Security News
Maintainers back GitHub’s npm security overhaul but raise concerns about CI/CD workflows, enterprise support, and token management.