{"id":15551350,"url":"https://github.com/biyuqi/js-wheels","last_synced_at":"2026-04-29T15:33:30.500Z","repository":{"id":57148982,"uuid":"127157889","full_name":"BiYuqi/js-wheels","owner":"BiYuqi","description":":tada: 常用的js方法集合","archived":false,"fork":false,"pushed_at":"2019-07-11T15:52:14.000Z","size":280,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-03-29T01:45:47.460Z","etag":null,"topics":["javascript","javascript-library","js-tool","webpack","webpack4"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/js-wheels","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/BiYuqi.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}},"created_at":"2018-03-28T15:05:48.000Z","updated_at":"2019-07-11T15:52:17.000Z","dependencies_parsed_at":"2022-09-06T00:02:50.389Z","dependency_job_id":null,"html_url":"https://github.com/BiYuqi/js-wheels","commit_stats":null,"previous_names":["biyuqi/js-utils"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BiYuqi%2Fjs-wheels","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BiYuqi%2Fjs-wheels/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BiYuqi%2Fjs-wheels/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BiYuqi%2Fjs-wheels/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BiYuqi","download_url":"https://codeload.github.com/BiYuqi/js-wheels/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246126669,"owners_count":20727594,"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":["javascript","javascript-library","js-tool","webpack","webpack4"],"created_at":"2024-10-02T14:04:21.504Z","updated_at":"2026-04-29T15:33:30.437Z","avatar_url":"https://github.com/BiYuqi.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## 前言\n日常使用的函数方法集合\n\n### 安装\n```js\nnpm i js-wheels -S\n```\n### 模块引入\n```js\n// webpack es6\nimport JSW from 'js-wheels'\nconst JSW = require('js-wheels')\n```\n### 直接引入\n```html\n\u003c!-- 直接引入的全局变量为 JsWheels --\u003e\n\u003cscript src=\"./dist/js-wheels.js\"\u003e\u003c/script\u003e\nJsWheels.chunck([1, 2, 3, 4, 5], 2) // [[1, 2], [3, 4], [5]]\n```\n\n## 用法(Usage Example)\n#### Array\n```js\nJSW.chunck([1, 2, 3, 4, 5], 2) // [[1, 2], [3, 4], [5]]\nJSW.difference([1, 2, 3], [2, 3, 4]) // [1, 4] 差集\nJSW.differenceWith([1, 2, 3], [2, 3, 4]) // [2, 3] 并集\nJSW.flattenArray([1, [2, 3]]) // [1, 2, 3] 扁平化数组\nJSW.myFilter([1, 2, 3], (index, item) =\u003e item \u003e 2) // [3]\nJSW.spliceByVal(arr, target) // 删除指定元素\nJSW.binarySearch(arr, item) // 二分查找\n```\n#### Object\n###### filterObjectBy\n```js\n/**\n* @param arrayObj 数组包裹的对象\n* @param mark 对象的key\n*/\nJSW.filterObjectBy([{a:1},{a:1},{a:3},{a:3},{a:4}], 'a')\n// [{a:1},{a:3},{a:4}] 根据对象某一个属性进行去重\n```\n###### cloneDeep\n```js\n/**\n* @param {Array Object} obj 数组或者对象\n*/\nJSW.cloneDeep(obj)\n```\n##### chaining\n解决ajax数据异步返回，导致渲染模板报错undefined\n```html\n用Vue举个例子\n\u003cdiv\u003e{{{ chaining(data, 'name.age.go', '加载中...') }}}\u003c/div\u003e\n```\n```js\n/**\n* https://github.com/tc39/proposal-optional-chaining\n* https://www.mmxiaowu.com/article/5b18d19f2f52003e4d38c639\n* @param {target} source data\n* @param {props}\n* @param {def}\n* use:\n* const data = {\n*  name: {\n*    age: {\n*      go: 27\n*    }\n*  },\n*  age: 38\n* }\n*/\nJSW.chaining(data, 'name.age.go', '加载中...') // 27\nJSW.chaining(data, 'name.g.g.b.c', '加载中...') // 加载中...\nJSW.chaining(data, 'age', '暂无数据') // 38\n```\n##### proxy\n```js\n/**\n * @param {Object} obj\n * @param {} path\n * @example 拦截由于数据为空导致报错undefined 与chaining方法功能一样\n * const test = {\n *  a: 123,\n *  b: 456,\n *  list: {\n *    dog: '旺旺'\n *  }\n * }\n */\n// 最后调用放入无参数时默认值\nJSW.proxy(test).a() // 123\nJSW.proxy(test).a.list() // {dog: '旺旺'}\nJSW.proxy(test).a.list.cat('默认值') // 默认值\n```\n##### arrToHash\n数组对象 =\u003e 转为双map结构\n```js\n/**\n * @param {Array} arr\n * @param {String} key\n * 数组对象转map map 结构\n * @example\n * [{\n *   id: 1,\n *   name: 'biyuqi',\n *   age: 26\n * },\n * {\n *  id: 2,\n *  name: 'bailemen',\n *  age: 101\n * }\n * @return\n * {\n * 1: {\n *   name: 'biyuqi',\n *   age: 26\n * },\n * 2:{\n *    name: 'bailemen',\n *    age: 101\n *   }\n * }\n */\n JSW.arrToHash(before, 'id')\n```\n#### Browser\n```js\nJSW.inBrowser // boolean\nJSW.inWeex // boolean\nJSW.weexPlatform // boolean\nJSW.UA // String\nJSW.isIE // boolean\nJSW.isIE9 // boolean\nJSW.isIE10 // boolean\nJSW.isIE11 // boolean\nJSW.isEdge // boolean\nJSW.isAndroid // boolean\nJSW.isIOS // boolean\nJSW.isChrome // boolean\n```\n#### Is\n```js\nJSW.isArray([]) // true\nJSW.isObject({}) // true\nJSW.isString('') // true\nJSW.isNumber(123) // true\nJSW.isSet(new Set) // true\nJSW.isMap(new Map) // true\nJSW.isUndefined(undefined) // true\nJSW.isDate(new Date()) // true\nJSW.isFunction(null) // false\nJSW.isRegExp(/\\d+/) // true\nJSW.isNaN(0/0) // true\n```\n#### Time\n```js\nJSW.timeAgo('2018-07-7 02:09:23') // 5 days ago\nJSW.timeAgo('2018-07-7 02:09:23', 'cn') // 5天前\n```\n#### String\n```js\nJSW.trimLeft(' 123') // 123\nJSW.trimRight('456  ') // 456\nJSW.trimAll(' 7 8 9 ') // 789\nJSW.repeatStr('js', 2) // jsjs\n```\n#### Other\n\n```js\n/**\n* 格式化请求参数\n* @param {{ query }} Object\n* {\n*   key: '123',\n*   name: 'byq',\n*   test: ''\n* }\n* key=123\u0026name=byq\n*/\nJSW.formatQuery(query)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbiyuqi%2Fjs-wheels","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbiyuqi%2Fjs-wheels","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbiyuqi%2Fjs-wheels/lists"}