wyongjian

这里是十个常用函数

Usage no npm install needed!

<script type="module">
  import wyongjian from 'https://cdn.skypack.dev/wyongjian';
</script>

README

Henryjs

  • a wrapper function package(常用函数封装库)
  • npm-url:npm

Installation

You can install with npm:

$ npm install Henryjs

Usage

import Henryjs from 'Henryjs'

Function

query(name, querystring)

  • Function for gets the value of the specified name in the specified querystring
Henry.query('name', '?name=js') //return 'js'

serialize(data)

  • Function for turn the object into a url string
Henry.serialize({hello: 'js', hi: 'test'}) //return 'hello=js&hi=test'

$(selector)

  • Function for simulating jQuery
Henry.$(selector) //return {DOM|undefined}

removeNode(node)

  • Function for Deleting DOM node
Henry.removeNode(node) //return {DOM}

insertAfter(node)

  • Function for inserting the node node after the target node
Henry.insertAfter(node, target) //return {DOM|'参数错误'}

addClass(node, className)

  • Function for add class name
Henry.addClass(node, className) //return {DOMTokenList}

removeClass(node, className)

  • Function for remove class name
Henry.removeClass(node, className) //return {DOMTokenList}

getAbsoluteUrl(url)

  • Function for get absolute url
Henry.getAbsoluteUrl('/hhh') //return 'https://github.com/hhh'

debounce(callback, time)

  • Function for avoiding shake
  • example:
 describe('debounce', () => {
  test('检测累加结果', (done) => {
    var total = 0
    const debounce = Henry.debounce(() => {
      total += 1
      expect(total).toBe(1)
      done()
    }, 300)

    for (let i = 0; i < 10; i++) {
      debounce()
    }
    expect(total).toBe(0)
  })
})

removeItemByIndex(index, arr)

  • Function for remove item by index
Henry.removeItemByIndex(1, [1, 2, 3]) //return [1, 3]

strlen(str)

  • Function for get str length
Henry.strlen('啊') //return 3

以上