0.1.0 • Published 6 years ago

upwoardjs v0.1.0

Weekly downloads
7
License
ISC
Repository
github
Last release
6 years ago

upwardjs

一个封装函数包(自己写的封装一些实用函数的包)

安装

  • 你可以用npm来安装:

  • $ npm install upwardjs

用法

  • import upward from 'upwardjs'

#功能

查询(名称,查询字符串)

  • 函数for获取指定查询字符串中指定名称的值
  • upward.query('name', '?name=js') //return 'js'

序列化(数据)

  • 将对象转换为url字符串的函数
  • upward.serialize({hello: 'js'}) //return '?hello=js'

$(选择)

  • 模拟jQuery的函数
  • upward.$(selector) //return {DOM|undefined}

removeNode(节点)

  • 删除DOM节点的函数
  • upward.removeNode(node) //return {DOM}

insertAfter(节点)

  • 用于在目标节点之后插入节点节点的函数
  • upward.insertAfter(node, target) //return true or false

addClass(node,className)

  • 添加类名的函数
  • upward.addClass(node, className) //return true or false

removeClass(node,className)

  • 删除类名称的函数
  • upward.removeClass(node, className) //return true or false

getAbsoluteUrl(URL)

去抖(回调,时间)

  • 避免摇晃的功能 例: test('test true', () => { const debounce = upward.debounce jest.useFakeTimers() // 声明语句,启用jest伪装计时器函数,因为使用了advanceTimersByTime() const callback = jest.fn() // 声明语句,使用jest伪装函数 const createDebounce = debounce(callback, 300) expect(callback).not.toBeCalled() // callback还未被调用 for (let i = 0; i < 11; i++) { // 循环执行createDebounce 11次,每次都在经过299ms时setTimeout被刷新 createDebounce() jest.advanceTimersByTime(299) // 过了299ms } expect(callback).not.toBeCalled() // callback还未被调用 jest.advanceTimersByTime(1) // 再过1ms expect(callback).toBeCalled() // callback被调用 expect(callback).toHaveBeenCalledTimes(1) // callback只被调用1次 })

removeItemByIndex(index,arr)

  • 按索引删除项目的功能
  • upward.removeItemByIndex(1, 1, 2, 3) //return 1, 3