{"id":19384108,"url":"https://github.com/ljcheibao/node-utils","last_synced_at":"2025-04-23T21:32:07.238Z","repository":{"id":57262311,"uuid":"99594927","full_name":"ljcheibao/node-utils","owner":"ljcheibao","description":"javascript工具库","archived":false,"fork":false,"pushed_at":"2018-07-01T04:03:44.000Z","size":22,"stargazers_count":12,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-17T18:13:59.789Z","etag":null,"topics":["common","frontend","javascript","jquery","tool","tools","util","utils"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/ljcheibao.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}},"created_at":"2017-08-07T15:52:59.000Z","updated_at":"2018-08-29T06:54:49.000Z","dependencies_parsed_at":"2022-08-25T06:11:06.595Z","dependency_job_id":null,"html_url":"https://github.com/ljcheibao/node-utils","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ljcheibao%2Fnode-utils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ljcheibao%2Fnode-utils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ljcheibao%2Fnode-utils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ljcheibao%2Fnode-utils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ljcheibao","download_url":"https://codeload.github.com/ljcheibao/node-utils/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250518027,"owners_count":21443883,"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":["common","frontend","javascript","jquery","tool","tools","util","utils"],"created_at":"2024-11-10T09:29:04.557Z","updated_at":"2025-04-23T21:32:06.900Z","avatar_url":"https://github.com/ljcheibao.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"### JavaScript工具类库\n\n从jQuery中整理的部分的工具函数以及平时积累的部分工具函数，方便开发使用\n\n[![npm](https://img.shields.io/npm/l/heibao-utils.svg)](LICENSE)\n[![NPM Version](https://img.shields.io/npm/v/heibao-utils.svg)](https://www.npmjs.com/package/heibao-utils)\n[![npm](https://img.shields.io/npm/dt/heibao-utils.svg)](https://www.npmjs.com/package/heibao-utils)\n\n###测试\n```\nnpm run test\n```\n\n### 如何使用\n\n- 安装\n\n  ```\n  cnpm install heibao-utils --save-dev;\n  ```\n\n- 引用\n\n  ```\n  import Utils from \"heibao-utils\";\n\n  Utils.xxx\n  ```\n\n  **备注：由于该包没有添加类型定义文件，并且是commonjs的方式，所以使用typescript的话，请使用require的方式进行引入**\n\n### 提供了哪些方法\n\n- type(obj)\n\n  判断js对象类型，比如：object，array，string，function等\n\n  ```js\n  let type = Utils.type([]);\n  console.log(type);//返回 array\n\n  let type = Utils.type(\"hello\");\n  console.log(type);//返回 string\n\n  ......\n  ```\n\n- isNull(obj)\n\n  判断对象是否为null，返回boolean值\n\n  **参数说明：**\n\n  ```\n  obj:要判断的值\n  ```\n\n- isPlainObject(obj)\n\n  判断值是否为字面量对象，即 {}，返回boolean值\n\n  **参数说明：**\n\n  ```\n  obj:要判断的值\n  ```\n\n- isEmptyObject(obj)\n\n  判断是否是空对象，比如：[],{}等，返回boolean值\n\n  **参数说明：**\n\n  ```\n  obj:要判断的值\n  ```\n\n- isFunction(obj)\n\n  判断是否为function，返回boolean值\n\n  **参数说明：**\n\n  ```\n  obj:要判断的值\n  ```\n\n- isNumeric(obj)\n\n  判断是否为数字，返回boolean值\n\n  **参数说明：**\n\n  ```\n  obj:要判断的值\n  ```\n\n- isArray(obj)\n\n  判断是否为数组，返回boolean值\n\n  **参数说明：**\n\n  ```\n  obj:要判断的值\n  ```\n\n- isBoolean(obj)\n\n  判断是否为boolen，返回boolean值\n\n  **参数说明：**\n\n  ```\n  obj:要判断的值\n  ```\n\n- isDate(obj)\n\n  判断是否为Date，返回boolean值\n\n  **参数说明：**\n\n  ```\n  obj:要判断的值\n  ```\n\n- contain(ele,array,i)\n\n  判断元素是否包含在数组中，存在反正元素在数组中的索引，不存在返回-1\n\n  **参数说明：**\n\n  ```\n  ele:要比较的元素\n  array:比较的数组\n  i:比较arrary中哪个位置\n\n  比如:\n  let arr=[1,2,3];\n  console.log(Utils.contain(2,arr));//返回 1\n  console.log(Utils.contain(2,arr,1));//返回 1\n  ```\n\n- merge(first,second)\n\n  数组合并，返回合并后的新数组\n\n  **参数说明：**\n\n  ```\n  first:目标数组，即被合并的数组\n  second:要合并的数组\n  ```\n\n- trim(text)\n\n  去除字符串两端的空白，返回去除空白后的字符串\n\n  **参数说明：**\n\n  ```\n  text:要出去空白的字符串\n  ```\n\n- makeArray(arr,results)\n\n  合并数组或者对象，返回合并后的数组或者类数组对象\n\n  **参数说明：**\n\n  ```\n  arr：数组或者对象\n  results：数组或者对象\n  ```\n\n- unique(arr)\n\n  数组去重，返回去重后的数组\n\n  **参数说明：**\n\n  ```\n  返回去重后的数组\n  ```\n\n- findElementIndex(arr.element)\n\n  查找数组中的元素，返回查找到的元素的索引\n\n  **参数说明：**\n\n  ```\n  arr：被查询的数组\n  element：要查询的元素\n  ```\n\n- removeElement(array, element)\n\n  移除数组的元素，返回移除元素后的数组\n\n  **参数说明：**\n\n  ```\n  array：要移除元素的数组\n  element：要移除的元素\n  ```\n\n- copyDate(date)\n\n  复制一个时间对象，返回复制后的时间对象Date\n\n  **参数说明：**\n\n  ```\n  date:被复制的Date对象\n  ```\n\n- createCorrectDate(strFormatDate, dateArr)\n\n  创建Date对象，返回创建成功的Date对象\n\n  **参数说明：**\n\n  ```\n  strFormatDate:时间格式，支持的时间格式有如下几种：\n  \t2017-11-19 12:20:30:333\n      2017/11/19 12:20:30:333\n      2017.11.19 12:20:30:333\n      2017-11-19\n      2017/11/19\n      2017.11.19\n  dateArr：设置的时间格式数组，支持设置时、分、秒\n  \t[23,59,59]\n  ```\n\n- dateFormat(fmt, objDate)\n\n  Date对象转换成时间字符串格式，返回转换后的时间字符串\n\n  **参数说明：**\n\n  ```\n  fmt：格式化标识符\n  \tyyyy-MM-dd hh:mm:ss = 2017-01-01 21:32:32\n  \tyyyy-MM-dd          = 2017-01-01 21:32:32\n  \tyyyy年MM月dd日       = 2017年11月21日\n  \t\n  \tyyyy-MM             = 2017-01\n  \tyyyy-M              = 2017-1\n  \tMM-dd               = 01-01\n  \tM-d                 = 1-1\n  \thh时                = 23时\n  \thh                  = 23\n  \t\n  \t....\n  \t根据 y(年)、M(月)、d(日)、h(时)、m(分)、s(秒)、S(毫秒)、q(季度)这几个占位符的组合，可以返回任     何格式的Date对象的值\n  objDate：Date时间对象\n  ```\n\n- isLeapYear(objDate)\n\n  判断是否是闰年，返回boolean值\n\n  **参数说明：**\n\n  ```\n  objDate：Date时间对象\n  ```\n\n- diffDate(interval, beginDate, endDate)\n\n  比较两个时间的间隔，返回时间间隔\n\n  **参数说明：**\n\n  ```\n  interval：时间间隔占位符\n  \ts：返回两个日期相差的秒数\n      n：返回两个日期相差的分钟数\n      h：返回两个日期相差的小时数\n      d：返回两个日期相差的天数\n      w：返回两个日期相差的周数\n      m：返回连个日期相差的月数\n      y：返回连个日期相差的年数\n  beginDate：开始时间，可以是Date对象，也可以是时间字符串\n  endDate：结束时间，可以是Date对象，也可以是时间字符串\n  ```\n\n- clone()\n\n  对象拷贝\n\n- getQuery(queryKey, target, pattern)\n\n  查询querystring参数，返回查询到的值\n\n  **参数说明：**\n\n  ```\n  queryKey：要查询的key\n  target：从哪个目标字符串查询，可选参数，默认是window.location\n  pattern：匹配的截取正则，可选参数\n\n  一般前端只要传入第一个参数，就可以获取当前页面window.location的querystring的值\n  ```\n\n- getOffset(element)\n\n  获取元素的offsetTop跟offsetLeft\n\n  **参数说明：**\n\n  ```\n  element：dom元素\n  ```\n\n- getScrollOffsets(w)\n\n  获取元素的滚动对象scrollX、scrollY\n\n  **参数说明：**\n\n  ```\n  w:dom对象，默认为window\n\n  我们一般也就是获取整个页面的scrollX、scrollY\n  ```\n\n- getViewPortSize(w)\n\n  获取页面可见视口，返回width、height\n\n  **参数说明：**\n\n  ```\n  w：dom对象，可选参数，默认window\n\n  我们一般都是获取整个页面的可见视口\n  ```\n\n  ​\n\n  ​\n\n  ​\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fljcheibao%2Fnode-utils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fljcheibao%2Fnode-utils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fljcheibao%2Fnode-utils/lists"}