1.3.2 • Published 6 years ago
@amipei/adam v1.3.2
amipei-adamjs
Install/安装
You can install with npm(你可以使用npm安装:)
$ npm install @amipei/adam
Usage/用法
import { base } from '@amipei/adam' //base lib
import { array } from '@amipei/adam' //数组处理
import { cookie } from '@amipei/adam' //cookie处理
import { dom }array from '@amipei/adam' //dom处理
import { url } from '@amipei/adam' //url处理
功能
isString(obj/string)
- Function for Determine if it is a string/string object
base.isString('string') //return true
debounce(callback,time)
- Function for avoiding shake
- test example:
describe('debounce', () => {
test('多次调用', (done) => {
let count = 0
function callback() {
count += 1
expect(count).toBe(1)
done()
}
const db = debounce(callback)
for (let i = 0; i < 100; i++) {
db()
}
})
test('超出延迟调用', (done) => {
let count = 0
function callback() {
count += 1
}
const db = debounce(callback)
db() //300ms后 count 加 1 = 1
setTimeout(() => {
db()
}, 300); //300ms后开始执行db() 600ms后count 加 1 = 2
setTimeout(() => {
expect(count).toBe(2)
done()
}, 800);
})
})
removeItemByIndex(index, arr)
- Function for Deleting item by index
array.removeItemByIndex(1, [1,2,3]) //return [1,3]
setCookie(key,value)
- Function for set cookie
cookie.setCookie('name','amipei')
getCookie(key)
- Function for get cookie
cookie.getCookie('name') //return amipei
delCookie(key)
- Function for del cookie
cookie.delCookie('name')
$(string)
- Function for select element
dom.$('#id') //return {DOM|undefined}
removeNode(node)
- Function for deleting dom node
dom.removeNode(node) //return {Dom}
removeClass(node, className)
- Function for deleting className of node
dom.removeClass(node,'className')
addClass(node, className)
- Function for add className
dom.addClass(node,'className')
insertAfter(node)
- Function for inserting the node after the target node
dom.insertAfter(node, target)
getAbsoluteUrl(url)
- Function for get absolute url
url.getAbsoluteUrl('/amipei') //return http://www.amipei.xyz/amipei
serialize(data)
- Function for turn the object into a url string
url.getAbsoluteUrl({name:'amipei'}) //?name=amipei
query(url)
- Function for gets the value of the specified name in the specified querystring
url.query('name', '?name=js') //return 'js'