{"id":13789157,"url":"https://github.com/Rabbitzzc/always-helper","last_synced_at":"2025-05-12T03:31:30.652Z","repository":{"id":41973159,"uuid":"297322936","full_name":"Rabbitzzc/always-helper","owner":"Rabbitzzc","description":"前端项目开发中，经常会用到一些工具函数的合集。","archived":false,"fork":false,"pushed_at":"2023-10-24T06:07:44.000Z","size":1301,"stargazers_count":17,"open_issues_count":0,"forks_count":4,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-04-26T06:21:22.726Z","etag":null,"topics":["always","always-helper","array","chart","color","cookie","css","device","dom","function","helper","hex-rgb","listen","number","random","regex","string","web"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Rabbitzzc.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2020-09-21T11:46:51.000Z","updated_at":"2023-04-08T11:34:14.000Z","dependencies_parsed_at":"2022-09-26T16:21:24.969Z","dependency_job_id":"985a13ac-9c8f-4e67-a3e7-f10c9a66fe03","html_url":"https://github.com/Rabbitzzc/always-helper","commit_stats":null,"previous_names":["rabbitzzc/always"],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Rabbitzzc%2Falways-helper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Rabbitzzc%2Falways-helper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Rabbitzzc%2Falways-helper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Rabbitzzc%2Falways-helper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Rabbitzzc","download_url":"https://codeload.github.com/Rabbitzzc/always-helper/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225117135,"owners_count":17423344,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["always","always-helper","array","chart","color","cookie","css","device","dom","function","helper","hex-rgb","listen","number","random","regex","string","web"],"created_at":"2024-08-03T21:00:59.177Z","updated_at":"2024-11-18T02:32:31.588Z","avatar_url":"https://github.com/Rabbitzzc.png","language":"TypeScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":" \u003cdiv align=\"center\"\u003e\n \u003cimg align=\"center\" width=\"180\" src=\"https://github.com/Rabbitzzc/image-hosting-service/blob/master/images/always-avator.png?raw=true\" /\u003e\n  \u003ch2\u003ealways-helper\u003c/h2\u003e\n  \u003cblockquote\u003e前端项目开发中，经常会用到一些工具函数的合集。\u003c/blockquote\u003e\n  \u003cimg alt=\"npm bundle size\" src=\"https://img.shields.io/bundlephobia/minzip/always-helper\"\u003e\n  \u003cimg alt=\"GitHub top language\" src=\"https://img.shields.io/github/languages/top/Rabbitzzc/always-helper\"\u003e\n  \u003cimg alt=\"Travis (.com)\" src=\"https://img.shields.io/travis/com/Rabbitzzc/always-helper\"\u003e\n  \u003cimg alt=\"GitHub issues\" src=\"https://img.shields.io/github/issues/Rabbitzzc/always-helper\"\u003e\n  \u003cimg alt=\"node-current\" src=\"https://img.shields.io/node/v/always-helper\"\u003e\n  \u003cimg alt=\"npm\" src=\"https://img.shields.io/npm/dm/always-helper\"\u003e\n  \u003cimg alt=\"NPM\" src=\"https://img.shields.io/npm/l/always-helper\"\u003e\n  \u003cimg alt=\"GitHub Repo stars\" src=\"https://img.shields.io/github/stars/Rabbitzzc/always-helper\"\u003e\n\u003c/div\u003e\n\n前端项目开发中，总会碰到这一类问题，所以为了提高前端的开发效率，减少代码重复率，所以这里统一封装了这些方法。\n\n## ⭐️ 特性\n \n- [x] 使用 typescript 编写，提供更好的代码提示和类型检查。\n- [x] 测试全覆盖，代码可用性得到保证。\n- [x] 不重复建设，利用现有的优秀开源库开发一些函数（大项目中经常会用到的一些库，比如 `lodash`、`dayjs`、`js-cookie` 等）。\n- [x] 覆盖 `日期格式化`、`url参数转换`、`浏览器类型判断`、`节流函数`、`字符串/数组处理`、`本地缓存`、`Cookie 增删改查`、`颜色转换`、`DOM 操作`、`随机数生成`、`金额转换` 等前端常用工具函数。\n\n\n\n## 📦 开始\n\n### 安装\n```sh\n# npm \nnpm install --save always-helper\n\n# yarn\nyarn add always-helper\n```\n\n### 使用\n\n```sh\nimport {setCookie} from 'always-helper'\n```\n\n### 备注\n\n* 如果使用了 `Cookie` 相关函数，需要提前安装 `js-cookie`\n* 如果使用了「日期相关」函数，需要提前安装 `dayjs`\n\n### API 文档\n\n#### `Cookie` 相关\n\n* `setCookie` \t设置 cookie\n* `getCookie`     获取 cookie\n* `removeCookie`    删除 cookie\n* `checkCookie`    检查浏览器是否支持 cookie\n\n#### 日期相关\n\n* `today`    获取今天日期\n* `yestoday`    获取昨天日期\n* `beforeDay`    获取前 n 天日期\n* `currentWeek` 获取本周起止时间\n* `lastWeek`    获取上周起止时间\n* `nextWeek`    获取下周起止时间\n* `beforeWeek`   获取过去第 n 周的起止日期\n* `beforeDays`    获取过去 n 天的起止时间\n* `currentMonth`     获取本月起止时间\n* `lastMonth`    获取上个月的起止时间\n* `nextMonth`    获取下个月的起止时间\n* `beforeMonth`    获取过去 n 个月起止时间\n* `sofarYear`     获取今天至今的起止时间\n* `getDay`    获取星期几\n* `getMonth`    获取本月份\n* `getCurrentWeek` 获取今年第几周\n* `timeAgo`    格式化时间展示范围\n\n#### 样式相关\n\n* `addClass`     元素添加类\n* `removeClass`    元素删除类\n* `hasClass`     判断元素是否存在某个类\n* `toggleClass`    元素切换类名\n* `replaceClass`    替换元素某个类为另一个类\n* `setStyle`    设置元素样式\n* `getStyle`    获取元素样式\n* `insertCss`    将 CSS 字符串插入到 `\u003chead\u003e` 中\n* `loadCss`     将 CSS 链接插入到 `\u003chead\u003e` 中\n\n#### `URL` 相关\n\n* `parseQueryString`     解析 URL 查询字符串\n* `stringifyQueryString`     对象转化为 URL 查询字符串\n\n#### 随机数相关\n\n* `randomInt`    随机生成一个整数\n* `randomString`    随机生成一个字符串（包含大写、小写、数字）\n* `randomCnChar`     随机生成中文串\n* `randomColor`     随机生成颜色（16 进制）\n* `uuid`     生成一个 uuid\n* `randomAvatar`     随机生成头像 avatar 链接，包含 http 或者 https 协议头\n\n#### `DOM` 相关\n\n* `fullscreen`    进入全屏/退出全屏\n* `copyElement2Clipboard`     复制 DOM 元素到剪贴板\n* `copyElementImage2Clipboard`     将 DOM 元素生成图片并复制到剪贴板\n* `downloadElementImage`     将 DOM 元素转化为图片并下载到本地\n* `inDarkMode`     将页面切换为暗黑模式\n* `inview`    判断一个 DOM 元素是否在可是区域内\n* `scrollTop`    将页面滚动到顶部\n* `scrollBottom`    将页面滚动到底部\n\n#### 颜色转换相关\n\n* `hexToRgb`  HEX 格式转化为 RGB 格式\n* `rgbToHex`  RGB 格式转化为 HEX 格式\n\n#### 数字相关\n\n* `fileSize`  字节单位转换\n* `commafy`    数字每三位增加逗号\n\n#### 正则相关\n\n* `verifyIdCard` 身份证验证\n* `verifyEmail`  邮箱验证\n* `verifyCellNumber`  手机号验证\n* `verifyUrl`   网页地址验证\n\n#### 设备相关\n\n* `getOS`  获取操作系统\n* `isAndroid`  是否为 `Android` 设备\n* `isIos` 是否为 `iOS` 设备\n* `isIpv4` ipv4 检测\n* `isIpv6` ipv6 检测\n* `isMobile`   是否为移动端\n* `isWeixin`  是否为微信内置浏览器打开\n\n#### 对象相关\n\n* `objEmpty`  判断对象是否为空\n\n## ⚙️ CHANGELOG\n\n[CHANGELOG](./CHANGLOG.md)\n\n## LICENSE\n\n[MIT](./LICENSE)\n\n## ✈️  TODO\n\n[TODO](./TODO.md)\n\n## 🚩 FAQ\n\n* [Q] 为什么使用 `dayjs` 作为时间处理工具？\n  * 大多数项目在最开始启动的时候，可能都是使用 `moment.js`。但其无法与现代的 `Tree Shanking` 算法配合使用，导致打包后的体积非常大，同时最近 `moment.js` 官方已经宣布停止更新进入维护阶段，并推荐了其他的相似库，其中就包括 `dayjs`。\n  * `dayjs` 本身非常轻量（2KB），功能上也不差，语法也非常友好，支持链式操作，同时兼容性也是非常优秀的。基于上面两个原因，所以选择了 `dayjs`。\n* [Q] 为什么使用 `js-cookie` 作为 cookie 处理工具？\n  * `js-cookie` 在 cookie 库中一枝独秀，有着非常好的影响力。同时 `js-ccokie` 非常轻量（\u003c 1KB），我认为我们不需要重复建设。\n* [Q] 有没有更好的随机数工具库？\n  * 推荐使用[chancejs](https://github.com/chancejs/chancejs)，但是仓库比较大\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FRabbitzzc%2Falways-helper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FRabbitzzc%2Falways-helper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FRabbitzzc%2Falways-helper/lists"}