简介
findstreak 是一个用于计算 Github 用户代码连续贡献天数的 npm 包。它可以通过 Github API 获取用户的代码提交记录,计算出连续贡献天数,并提供了相应的 API。
安装
npm install findstreak --save-dev
使用
在 Node.js 中使用
导入 findstreak:
const findstreak = require('findstreak');
调用 API:
findstreak.getStreak({ username: 'github_username', token: 'github_token' }).then((res) => { console.log(res.streak); }).catch((err) => { console.error(err); });
其中,username
表示 Github 用户名,token
是 Github API 的个人访问令牌。
在浏览器中使用
引入 findstreak.js:
<script src="findstreak.js"></script>
调用 API:
findstreak.getStreak({ username: 'github_username', token: 'github_token' }).then((res) => { console.log(res.streak); }).catch((err) => { console.error(err); });
API
findstreak.getStreak(options)
计算 Github 用户的代码连续贡献天数。
参数:
options
:username
(必需):Github 用户名。token
(必需):Github API 的个人访问令牌。startDate
(可选):开始日期,格式为YYYY-MM-DD
,默认为 1 年之前。endDate
(可选):结束日期,格式为YYYY-MM-DD
,默认为今天。
返回值:
{ "streak": 10, "startDate": "2021-07-01", "endDate": "2021-07-10" }
其中,streak
表示连续贡献天数,startDate
和 endDate
表示计算连续贡献天数的起始日期和结束日期。
示例
在 Node.js 中使用
-- -------------------- ---- ------- ----- ---------- - ---------------------- ---------------------- --------- ---------- ------ ------------------- ------------- -- - ------------------------ -------------- -- - ------------------- ---
输出:
4
在浏览器中使用
-- -------------------- ---- ------- --------- ----- ------ ------ ----------------- --------------- ------- ----------------------------- -------- ---------------------- --------- ---------- ------ ------------------- ------------- -- - ------------------------ -------------- -- - ------------------- --- --------- ------- ------ ------- -------
打开
来源:JavaScript中文网 ,转载请注明来源 https://www.javascriptcn.com/post/60055fa181e8991b448dcf67