{"id":22014112,"url":"https://github.com/laqudee/common-toolbox","last_synced_at":"2026-04-11T08:06:55.054Z","repository":{"id":161575440,"uuid":"636279059","full_name":"laqudee/common-toolbox","owner":"laqudee","description":"A reusable tool library that focuses on serving Vue projects","archived":false,"fork":false,"pushed_at":"2023-06-13T06:05:34.000Z","size":178,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-04-25T18:43:31.480Z","etag":null,"topics":["axios","date","dom","encrypt","toolbox","validate","vite","vue"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/laqudee.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-05-04T13:47:58.000Z","updated_at":"2023-05-08T12:06:56.000Z","dependencies_parsed_at":"2023-05-27T21:45:30.122Z","dependency_job_id":"2b88e346-b378-41c6-a196-86e9a343b446","html_url":"https://github.com/laqudee/common-toolbox","commit_stats":{"total_commits":39,"total_committers":2,"mean_commits":19.5,"dds":0.05128205128205132,"last_synced_commit":"bb1bc719c45d10d20be3ef2af2f18c09a646925b"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/laqudee%2Fcommon-toolbox","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/laqudee%2Fcommon-toolbox/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/laqudee%2Fcommon-toolbox/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/laqudee%2Fcommon-toolbox/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/laqudee","download_url":"https://codeload.github.com/laqudee/common-toolbox/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245075295,"owners_count":20556904,"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":["axios","date","dom","encrypt","toolbox","validate","vite","vue"],"created_at":"2024-11-30T03:26:23.382Z","updated_at":"2026-04-11T08:06:50.019Z","avatar_url":"https://github.com/laqudee.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Common-toolbox\n\n专注服务于Vue项目的可复用工具库\n\n\u003e 目前仅支持前端项目，不支持纯Node.js项目【后续会修复这个问题】\n\n## Axios相关API\n\n### Usage\n\n```js\nimport { createAxios } from 'common-toolbox'\nimport { getToken } from './token.js'\nimport router from '../router/index.js'\nimport { ElMessage } from 'element-plus'\n\n// messageTip可以自己进行封装\n// 例如\nconst messageTip = ({type, message}) =\u003e {\n  alert(message)\n  console.log('type: ', type)\n}\n\n// example\nconst axios = createAxios({\n  baseURL: '',\n  timeout: 50000,\n  tokenName: 'token',\n  getToken: getToken,\n  router,\n  messageTip: ElMessage\n})\n\nexport default axios\n\n// use axios\nimport axios form './utils/axios.js'\n\nexport const getList = (params) =\u003e {\n  return axios.post(url, params, config)\n}\n// config可选可配置\n```\n\n### API\n\n| API         | USAGE                                | REMARK        |\n| :---------- | :----------------------------------- | :------------ |\n| createAxios | `const axios = createAxios(options)` | 生成axios实例 |\n| ...         | ...                                  | ...           |\n\n## DOM处理相关API\n\n### Usage\n\n```js\nimport { domHandler } from 'common-box'\n\n// vue main.js\ndomHandler.setFontSize()\n\n// some page need setting fullscreen\nconst play = () =\u003e {\n  domHandler.settingFullscreen()\n}\n\n// more ...\n```\n\n### API\n\n| API               | USAGE                           | REMARK                         |\n| :---------------- | :------------------------------ | :----------------------------- |\n| setFontSize       | `setFontSize()`                 | 以1920*1080为基准设置自适应    |\n| settingFullscreen | `settingFullscreen()`           | 开启与关闭全屏                 |\n| on                | `on(window, 'resize', resize)`  | 用于Echart图表随窗口大小自适应 |\n| off               | `off(window, 'resize', resize)` | 用于Echart图表随窗口大小自适应 |\n| ...               | ...                             | ...                            |\n\n## Form表单校验相关API\n\n### Usage\n\n```js\nimport { validator } from 'common-toolbox'\n\n//example\nconst trueOrFalseOfMobile = validator.isMobile(userPhone)\n\nconst trueOrFalseOfIdCard = validator.isIdCard(userIdCard)\n\n// more ...\n```\n\n### 说明\n\n- 邮箱、手机号、身份证号、中文姓名、密码复杂度等的校验函数返回均为Boolean类型，并没有专门去适配`Element-ui`、`Element-plus`、`Vant`等UI框架，使用时应根据个人需求通过包装下面这些函数实现适配UI框架的校验函数\n\n### API\n\n| API                        | USAGE                                                     | REMARK                                                                      |\n| :------------------------- | :-------------------------------------------------------- | :-------------------------------------------------------------------------- |\n| isMobile                   | `isMobile(value): boolean`                                | 用于校验手机号                                                              |\n| isEmail                    | `isEmail(value): boolean`                                 | 用于校验邮箱号                                                              |\n| isName                     | `isName(value): boolean`                                  | 用于校验中文姓名                                                            |\n| isIdCard                   | `isIdCard(value): boolean`                                | 用于校验身份证号                                                            |\n| passwordComplexityValidate | `passwordComplexityValidate(value, messageTool): boolean` | 用于校验密码的复杂程度是否符合，messageTool参数是个消息提示弹窗实例或者函数 |\n| isDate                     | `isDate(value): boolean`                                  | 用于校验日期                                                                |\n| isNumeric                  | `isNumeric(value): boolean`                               | 判断值是否为数字                                                            |\n| isNaN                      | `isNaN(value): boolean`                                   | 判断值是否为NaN                                                             |\n| inBrowser                  | `inBrowser(): boolean`                                    | 判断是否为浏览器                                                            |\n| isAndroid                  | `isAndroid(): boolean`                                    | 判断是否为安卓                                                              |\n| isIOS                      | `isIOS(): boolean`                                        | 判断是否为IOS                                                               |\n| ...                        | ...                                                       | ...                                                                         |\n\n## File处理相关API\n\n### `fileHandler`\n\n#### Usage\n\n```js\nimport { fileHandler } from 'common-toolbox'\n\n// example\nconst downloadWord = async () =\u003e {\n  const res = await axios.get('/api/download/file?id')\n  if (res.success) {\n    fileHandler.blobFile(res, 'example.docx', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' )\n  }\n}\n```\n\n### API\n\n| API           | USAGE                                       | REMARK                                                 |\n| :------------ | :------------------------------------------ | :----------------------------------------------------- |\n| dataURLtoFile | `const file = dataURLtoFile(url, filename)` | 将URL转为file                                          |\n| blobFile      | `blob(url, name, type)`                     | 下载文件，name: 下载存储的文件名；type: 下载的文件类型 |\n| ...           | ...                                         | ...                                                    |\n\n### `nodeFileHandler`\n\n#### Usage\n\n```js\nimport { nodeFileHandler } from 'common-toolbox'\n\n// example\nnodeFileHandler.isFileExist('/path')\n\nnodeFileHandler.getFolderExcludeSome('parentPath', /^example/)\n```\n\n### API\n\n| API                  | USAGE                                                               | REMARK                                                 |\n| :------------------- | :------------------------------------------------------------------ | :----------------------------------------------------- |\n| isFileExist          | `isFileExist(path): boolean`                                        | 判断文件是否存在                                       |\n| getFolderExcludeSome | `getFolderExcludeSome(parentPath, excludeRegex): Promise\u003cstring[]\u003e` | 获取parentPath下的除了excludeRegex正则表达式包含的目录 |\n| hasFolder            | `hasFolder(parentPath, excludeRegex, name): boolean`                | 判断参数name的目录是否存在                             |\n| ...                  | ...                                                                 | ...                                                    |\n\n## Cookie与LocalStorage相关API\n\n### Usage\n\n```js\nimport { cookieAndStorage } from 'common'\n\n// example\nconst cs = cookieAndStorage\n\ncs.getLocalStorage('userInfo')\ncs.setLocalStorage('userInfo', info)\ncs.clearAllLocalStorage()\n\ncs.getCookie('token')\ncs.setCookie('token', token)\ncs.clearAllCookies()\n\ncs.clearAllStorage()\n```\n\n### API\n\n| API                  | USAGE                            | REMARK |\n| :------------------- | :------------------------------- | :----- |\n| getLocalStorage      | `getLocalStorage(key)`           |        |\n| setLocalStorage      | `setLocalStorage(key, data)`     |        |\n| removeLocalStorage   | `removeLocalStorage(key)`        |        |\n| clearAllLocalStorage | `clearAllLocalStorage()`         |        |\n| getCookie            | `getCookie(key)`                 |        |\n| setCookie            | `setCookie(key, value, expires)` |        |\n| removeCookie         | `removeCookie(key)`              |        |\n| clearAllCookies      | `clearAllCookies()`              |        |\n| clearAllStorage      | `clearAllStorage()`              |        |\n| ...                  | ...                              | ...    |\n\n## Browser处理相关API\n\n### Usage\n\n```js\nimport { browserHandler } from 'common-toolbox'\nimport { ElMessage } from 'element-plus'\n\n// example\nbrowserHandler.getPositionByGeolocation(ElMessage)\n```\n\n### API\n\n| API                      | USAGE                                                     | REMARK                                                    |\n| :----------------------- | :-------------------------------------------------------- | :-------------------------------------------------------- |\n| getPositionByGeolocation | `getPositionByGeolocation(messageTool): {Promise\u003cObject\u003e` | 获取定位坐标；messageTool参数应传入一个消息弹窗实例或函数 |\n| ...                      | ...                                                       | ...                                                       |\n\n## Date相关接口\n\n### Usage\n\n```js\nimport { dateHandler } from 'common-toolbox'\n\n// example\nconst date = dateHandler.getDateAndWeek()\nconsole.log(date)\n/**\n * date: '2023年5月1日'\n * week: '周一'\n * time: '12:45'\n */\n```\n\n### API\n\n| API            | USAGE                           | REMARK             |\n| :------------- | :------------------------------ | :----------------- |\n| getDateAndWeek | `const date = getDateAndWeek()` | 返回当前日期与周几 |\n| ...            | ...                             | ...                |\n\n## Encrypt加密相关API\n\n### Usage\n\n```js\nimport { createEncrypter, encryptHandler } from 'common-toolbox'\n\n// example\nconst PUBLIC_KEY = 'PUBLIC_KEY'\n\nexport const setRas = createEncrypter(PUBLIC_KEY)\n\n// 通过*加密文本，例如手机号、邮箱\nconst encodeMobile = encryptHandler.encryptText('13356789900', 'mobile', '请绑定手机号')\n\nconst encodeEmail = encryptHandler.encryptEmail('example@mail.com', '请绑定邮箱')\n```\n\n### API\n\n| API             | USAGE                                           | REMARK                      |\n| :-------------- | :---------------------------------------------- | :-------------------------- |\n| createEncrypter | `const setRAS = createEncrypter(publicKey)`     | 目前使用JSEncrypt进行加密   |\n| encryptText     | `encodeText = encryptText(text, flag, tipText)` | 通过*对指定文本进行加密     |\n| encryptName     | `encodeName = encryptName(name, tipText)`       | 通过*对指定中文姓名进行加密 |\n| encryptMobile   | `encodeMobile = encryptMobile(mobile, tipText)` | 通过*对指定手机号进行加密   |\n| encryptEmail    | `encodeEmail = encryptEmail(email, tipText)`    | 通过*对指定邮箱进行加密     |\n| ...             | ...                                             | ...                         |\n\n## 其他API\n\n### Usage\n\n```js\nimport { getPdf, sleep } from 'common-toolbox'\n\n// example\n// type: file: 表示下载pdf\n// type: base64: 表示生成base64码\nconst pdfBase64 = getPdf('#container', 'base64', 'example-pdf')\n\nconst sleepPromise = sleep(50000)\n\n// more ...\n```\n\n### API\n\n| API     | USAGE                      | REMARK                    |\n| :------ | :------------------------- | :------------------------ |\n| getPdf  | `getPdf(ref, type, title)` | 将指定div元素转为pdf      |\n| sleep   | `sleep(timeout)`           | 设置休眠时间，返回promise |\n| getType | `getType(value)`           | 返回value的类型           |\n| ...     | ...                        | ...                       |\n\n## 打包方式\n- 目前打包成两种格式：\n  - ESM\n  - CJS\n\n## Examples\n\n```sh\n- examples/vue3-example\n\n# dev\npnpm dev\n```\n\n## 补充\n\u003e 进行中...\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flaqudee%2Fcommon-toolbox","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flaqudee%2Fcommon-toolbox","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flaqudee%2Fcommon-toolbox/lists"}