{"id":29404535,"url":"https://github.com/geniusmanyxh/tj-jstools","last_synced_at":"2025-07-10T20:13:05.873Z","repository":{"id":59799538,"uuid":"536389156","full_name":"geniusmanyxh/tj-jstools","owner":"geniusmanyxh","description":"A diverse JS tool library","archived":false,"fork":false,"pushed_at":"2025-04-04T03:56:34.000Z","size":4349,"stargazers_count":28,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-09T03:29:58.814Z","etag":null,"topics":["js","tool"],"latest_commit_sha":null,"homepage":"https://geniusmanyxh.github.io/tj-jstools/","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/geniusmanyxh.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-09-14T02:48:11.000Z","updated_at":"2025-05-03T03:20:45.000Z","dependencies_parsed_at":"2024-12-31T10:24:25.802Z","dependency_job_id":"16609dcd-b2da-4523-b7b5-00c32d441ce0","html_url":"https://github.com/geniusmanyxh/tj-jstools","commit_stats":{"total_commits":94,"total_committers":3,"mean_commits":"31.333333333333332","dds":0.3829787234042553,"last_synced_commit":"8a8eec86ed1cc99fe8a1adaf972f0eee93469e44"},"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"purl":"pkg:github/geniusmanyxh/tj-jstools","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/geniusmanyxh%2Ftj-jstools","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/geniusmanyxh%2Ftj-jstools/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/geniusmanyxh%2Ftj-jstools/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/geniusmanyxh%2Ftj-jstools/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/geniusmanyxh","download_url":"https://codeload.github.com/geniusmanyxh/tj-jstools/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/geniusmanyxh%2Ftj-jstools/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264465888,"owners_count":23612585,"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":["js","tool"],"created_at":"2025-07-10T20:13:05.036Z","updated_at":"2025-07-10T20:13:05.862Z","avatar_url":"https://github.com/geniusmanyxh.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# tj-jstools 工具库\nA diverse JS tool library\n\n![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/geniusmanyxh/tj-jstools/main.yml?style=plastic)\u0026nbsp;\n![npm](https://img.shields.io/npm/dw/tj-jstools?style=plastic)\u0026nbsp;\n[![codecov](https://codecov.io/gh/geniusmanyxh/tj-jstools/branch/master/graph/badge.svg?token=EXYI8985P8)](https://codecov.io/gh/geniusmanyxh/tj-jstools)\u0026nbsp;\n![NPM](https://img.shields.io/npm/l/tj-jstools?style=plastic)\u0026nbsp;\n![npm](https://img.shields.io/npm/v/tj-jstools?style=plastic)\u0026nbsp;\n![node-current](https://img.shields.io/node/v/tj-jstools?style=plastic)\u0026nbsp;\n![GitHub Repo stars](https://img.shields.io/github/stars/geniusmanyxh/tj-jstools?style=social)\u0026nbsp;\n![GitHub commit merge status](https://img.shields.io/github/commit-status/geniusmanyxh/tj-jstools/master/8dabedcffbc9f97c03ad4bed35b828a39530e0f1)\u0026nbsp;\n![GitHub language count](https://img.shields.io/github/languages/count/geniusmanyxh/tj-jstools?style=plastic)\u0026nbsp;\n![GitHub top language](https://img.shields.io/github/languages/top/geniusmanyxh/tj-jstools?style=plastic)\u0026nbsp;\n![GitHub commit activity](https://img.shields.io/github/commit-activity/m/geniusmanyxh/tj-jstools?style=plastic)\u0026nbsp;\n![GitHub last commit](https://img.shields.io/github/last-commit/geniusmanyxh/tj-jstools?style=plastic)\u0026nbsp;\n![GitHub Release Date](https://img.shields.io/github/release-date/geniusmanyxh/tj-jstools?style=plastic)\n\n- [官方使用文档地址：http://jstools.itbooks.work](http://jstools.itbooks.work)\n- [GitHub 使用文档地址：https://geniusmanyxh.github.io/tj-jstools/](https://geniusmanyxh.github.io/tj-jstools/)\n\n前端业务工具库\n\n使用`TypeScript`编写有关js数据类型、浏览器信息、浏览器存储、url、字符串、数值、数组、对象等相关操作，让业务逻辑简单化。\n\n---\n\n[TOC]\n\n----\n\n## 🛠️安装\n\n**npm方式**\n\n```sh\nnpm install tj-jstools\n```\n\n**浏览器方式**\n\n- [jsdelivr的umd格式地址](https://cdn.jsdelivr.net/npm/tj-jstools@1.2.1/static/umd/index.js)\n```js\n\u003cscript src=\"https://cdn.jsdelivr.net/npm/tj-jstools@1.3.2/static/umd/index.js\"\u003e\u003c/script\u003e\n\u003cscript\u003e\n  const {_tj} = window\n  console.log(_tj);\n\u003c/script\u003e\n```\n引入后，查看全局变量中的`window._tj`对象，里面包含了所有工具函数。\n\n---\n\n## 📖简单使用的Demo\n\n#### 判断数据类型Demo\n\n```typescript\nimport { isInt, isFloat, isNumber} from 'tj-jstools'\n\nconst isNumRes = isNumber(12.9); // true\nconst isIntRes = isInt(12.9); // false\nconst isFloatRes = isFloat(12.9); // true\n\n```\n\n当你想确定某一个变量或者值，是否和你预想的一样是可以使用以上这些数据类型判断函数。\n\n当你想获取某一个变量或者值具体的数据类型时，你可以使用以下函数：\n\n```typescript\nimport { getType, getArrayAllType, getObjectAllType} from 'tj-jstools'\n\nconst getTypeRes1 = getType(Array(1)) // array\nconst getTypeRes2 = getType({}) // object\nconst getTypeRes3 = getType() // undefined\nconst getTypeRes4 = getType(1/0) // infinite\n\n// 判断数组里面的数据类型\n const arr = [true,null,undefined,1/0,5,5.01,{},[],()=\u003e{},NaN,'']\n const arrRes = getArrayAllType(arr) \n  //['boolean', 'null', 'undefined', 'infinite', 'int', 'float','object',\n  // 'array','function','NaN','string']\n \n// 判断对象里面的数据类型\n const testObj = {\n    a: true,\n    b: null,\n    c: undefined,\n    d: 6,\n    e: 6.01,\n    f: 1/0,\n    g: {},\n    h: [],\n    i: () =\u003e {}\n  }\n  const objRes = getObjectAllType(testObj)\n  /*\n[\n  'boolean', 'null', 'undefined', 'int', 'float','infinite',\n  'object',  'array', 'function'\n]\n  */\n```\n\n---\n\n#### 浏览器缓存（cookie/localStorage/sessionStorage）Demo\n\n```typescript\nimport { newStorage } from 'tj-jstools'\nconst Coptions = {\n  prefix:'tj',\n  linkSign: '@',\n  suffix:'jstools',\n  expireTime: 2,\n  unitTime: 'd'\n}\n// 创建一个操作Cookie的实例\nconst CInstance = newStorage('cookie',Coptions)\n\n//创建一个操作localStorage的实例\nconst LInstance = newStorage('local',Coptions)\n\n// 创建一个操作sessionStorage的实例\nconst SInstance = newStorage('session',Coptions)\n\n// 保存和获取cookie值\nCInstance.setFun('test','testValue')\nCInstance.getFun('test') // tj@test@jstools: testValue ; 过期时间：2天\n\n// 保存和获取localStorage值\nLInstance.setFun('test','testValue')\nLInstance.getFun('test') // tj@test@jstools: testValue ; 过期时间：2天\n\n// 保存和获取sessionStorage值\nSInstance.setFun('test','testValue')\nSInstance.getFun('test') // tj@test@jstools: testValue ; 过期时间：2天\n```\n\n**注意：**\n\n- **对sessionStorage设置过期时间，其实效果不大，会随着浏览器的关闭而消亡**\n\n- **如果cookie不设置expires，cookie 会在对话结束时过期**\n\n- **具体操作可以查看文档：[https://geniusmanyxh.github.io/tj-jstools/](https://geniusmanyxh.github.io/tj-jstools/)**\n\n---\n\n\n\n## 👉各类API列表\n\n### 数据类型篇(DataType)\n\n| 序号 |    名称      | 功能简介                    |\n| ---- | :--------------:  | --------------------------- |\n| 1    |  `isBoolean` | 判断数据是否是`boolean`类型 |\n| 2    |  `isString`  | 判断数据是否是`string`类型  |\n| 3    |  `isNumber`  | 判断数据是否是`number`类型  |\n| 4    |  `isSymbol`  | 判断数据是否是`symbol`类型  |\n| 5    |  `isUndefined` | 判断数据是否是`undefined`类型  |\n| 6    |  `isBigint` | 判断数据是否是`bigint`类型  |\n| 7    |  `isInt` | 判断数据是否是`int`类型  |\n| 8    |  `isFloat` | 判断数据是否是`float`类型  |\n| 9    |  `isNaN`| 判断数据是否是`NaN`类型  |\n| 10   |  `isFinite`| 判断数据是否是`finite`类型  |\n| 11   |  `isNull` | 判断数据是否是`null`类型  |\n| 12   |  `isArray` | 判断数据是否是`array`类型  |\n| 13   |  `isDate` | 判断数据是否是`date`类型  |\n| 14   |  `isFunction` | 判断数据是否是`function`类型  |\n| 15   |  `isObject` | 判断数据是否是`object`类型  |\n| 16   |  `getType` | 判断数据是否是`returnTypeStr`类型，并返回类型 |\n| 17   |  `getArrayAllType` | 判断数组值是否是`returnTypeStr`类型，并返回类型 |\n| 18   |  `getArrayTypeDetail` | 判断数组值是否是`returnTypeStr`类型，并返回类型 |\n| 19   |  `getObjectAllType`| 判断对象属性是否是`returnTypeStr`类型，并返回类型 |\n| 20   |  `getObjectTypeDetail`| 判断对象属性是否是`returnTypeStr`类型，并返回类型 |\n\n### 字符串篇(String)\n\n| 序号 |    名称       | 功能简介                    |\n| ---- | :--------------: | --------------------------- |\n| 1    | `charInCounts` | 计算字符串中指定字符出现的次数 |\n| 2    | `DTMobile` | 手机号脱敏处理  |\n| 3    | `createRandomVerifyCode` | 生成随机字符串验证码  |\n\n### 数值篇(Number)\n\n\n| 序号 |    名称     |  功能简介                    |\n| ---- | :--------------: |  --------------------------- |\n| 1    | `formatChineseRMB` | 数字金额转换为大写人民币汉字 |\n| 2    | `numberThousandsFormat`| 数值千分位格式化处理 |\n\n### 数组篇(Array)\n\n| 序号 |    名称    | 功能简介                    |\n| ---- | :--------------: | --------------------------- |\n| 1    | `toTreeData` | 将特定数组转为树形结构 |\n| 2    | `treeToFlat` | 将树形结构扁平化一维数组  |\n| 3    | `findTreeData`| 查找符合条件的树形节点  |\n\n### URL篇\n\n| 序号 |    名称      | 功能简介                    |\n| ---- | :--------------: | --------------------------- |\n| 1    | `getUrlParams` | 获取url路径参数 |\n| 2    | `converParamsToUrl` | 拼接参数到url路径上  |\n\n### 浏览器篇\n\n| 序号 |    名称      | 功能简介                    |\n| ---- | :--------------: | --------------------------- |\n| 1    | `isFull` | 判断当前是否全屏 |\n| 2    | `getFullEl` | 获取全屏元素  |\n| 3    | `isFullEnabled` | 判断当前是否支持全屏功能  |\n| 4    | `openFull` | 打开全屏  |\n| 5    | `closeFull` | 关闭全屏  |\n| 6    | `toggleFull` | 打开或者关闭全屏  |\n| 7    | `scrollBackTop`| 返回浏览器顶部  |\n| 8    | `scrollProgressBar`| 计算当前页面已读内容的百分比占比  |\n\n### 浏览器缓存篇(Cookie/LoaclStorage/SessionStorage)\n\n| 序号 |    名称     | 功能简介                    |\n| ---- | :--------------: | --------------------------- |\n| 1    | `newStorage`| 生成一个可操作的浏览器缓存实例 |\n\n**实例方法-列表**\n\n| 序号 |    名称      | 功能简介                    |\n| ---- | :--------------: | --------------------------- |\n| 1    | `setFun`| 设置浏览器缓存的方法 |\n| 2    | `getFun` | 获取浏览器缓存的方法 |\n| 3    | `delFun`| 移除浏览器缓存的方法 |\n| 4    | `existFun`| 监测浏览器缓存的方法 |\n| 5    | `allkey`| 获取浏览器缓存的key值唯一标识的方法 |\n| 6    | `clearFun` | 批量清除浏览器缓存的方法 |\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgeniusmanyxh%2Ftj-jstools","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgeniusmanyxh%2Ftj-jstools","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgeniusmanyxh%2Ftj-jstools/lists"}