1.0.5 • Published 6 years ago
unlunar v1.0.5
Unlunar
Installation
You can install with npm:
$ npm install unlunar
Usage
import B from 'unlunar'
Function
query(name, querystring)
- Function for gets the value of the specified name in the specified querystring
B.query('name', '?name=js') //return 'js'
serialize(data)
- Function for turn the object into a url string
B.serialize({hello: 'js'}) //return '?hello=js'
$(selector)
- Function for simulating jQuery
B.$(selector) //return {DOM|null}
removeNode(node)
- Function for Deleting DOM node
B.removeNode(node) //return {DOM|null}
insertAfter(node)
- Function for inserting the node node after the target node
B.insertAfter(node, target) //return {null|true}
addClass(node, className)
- Function for add class name
B.addClass(node, className) //return {null}
removeClass(node, className)
- Function for remove class name
B.removeClass(node, className) //return {null}
getAbsoluteUrl(url)
- Function for get absolute url
B.getAbsoluteUrl('/hello') //return 'http://localhost/hello'
debounce(callback, time)
- Function for avoiding shake
- example:
test('test true', (done) => {
let total = 0
const debounce = B.debounce(() => {
total += 1
expect(total).toBe(1)
done()
}, 200)
for (let i = 0; i < 100; i++) {
debounce()
}
expect(total).toBe(0) // 调用一百次 debouce ,马上检测 total
})
removeItemByIndex(index, arr)
- Function for remove item by index
B.removeItemByIndex(1, [1, 2, 3]) //return [1, 3]
isDigit(string)
- Function to make sure the string's letters are all numbers
expect(B.isDigit('123')).toBe(true)
expect(B.isDigit('12s3')).toBe(false)
filter(string)
- Function for XSS filter
B.filter('<script>alert</script><a href="a.com" onclick="alert(1)">test</a>')
// return '<a href="a.com" >test</a>'
htmlEncode(string)
- Function for htmlEncode
B.htmlEncode('<script></script>') // return '<script></script>'
JavaScriptEncode(string)
- Function for JavaScriptEncode
B.JavaScriptEncode('<script>alert</script><a href="a.com" onclick="alert(1)">test</a>')
// return '\\x3Cscript\\x3Ealert\\x3C\\x2Fscript\\x3E\\x3Ca href=\\x22a.com\\x22 onclick=\\x22alert(1)\\x22\\x3Etest\\x3C\\x2Fa\\x3E'
URLEncode(string)
- Function for URLEncode
B.URLEncode('http://www.w3school.com.cn/My first/')
// return 'http://www.w3school.com.cn/My%20first/'