Adamjs
一些实用工具函数封装库
Installation
You can install with npm:
npm install adam-noah
also yarn:
yarn add adam-noah
Usage
import Adam from 'adam-noah'
Function
query(name, querystring)
Function for gets the value of the specified name in the specified querystring
Adam.query('name', '?name=js')
serialize(data)
Function for turn the object into a url string
Adam.serialize({hello: 'js'})
$(selector)
Function for simulating jQuery
adam.$(selector)
removeNode(node)
Function for Deleting DOM node
adam.removeNode(node)
insertAfter(node)
Function for inserting the node node after the target node
Adam.insertAfter(node, target)
addClass(node, className)
Function for add class name
Adam.addClass(node, className)
removeClass(node, className)
Function for remove class name
adam.removeClass(node, className)
getAbsoluteUrl(url)
Function for get absolute url
Adam.getAbsoluteUrl('/hhh')
debounce(callback, time)
Function for avoiding shake
Example:
test('test true', () => {
const debounce = Adam.debounce
jest.useFakeTimers()
const callback = jest.fn()
const createDebounce = debounce(callback, 300)
expect(callback).not.toBeCalled()
for (let i = 0; i < 11; i++) {
createDebounce()
jest.advanceTimersByTime(299)
}
expect(callback).not.toBeCalled()
jest.advanceTimersByTime(1)
expect(callback).toBeCalled()
expect(callback).toHaveBeenCalledTimes(1)
})
removeItemByIndex(index, arr)
Function for remove item by index
adam.removeItemByIndex(1, [1, 2, 3])