2.0.2 • Published 6 years ago

basejs3 v2.0.2

Weekly downloads
2
License
ISC
Repository
-
Last release
6 years ago

Basejs

  • a wrapper function package(自己写的封装一些实用函数的包)
  • npm-url:npm
  • git-url:github

Installation

You can install with npm:

$ npm install basejs3

Usage

import Basedam from 'basejs3'

Function

query(name, querystring)

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

serialize(data)

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

$(selector)

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

On(element,type,handler)

  • Function for addEventListener
Base.On(element,type,function())) //to make most of Browsers conpatible in Event binding

insertAfter(node)

  • Function for inserting the node node after the target node
Base.insertAfter(node, target) 

addClass(node, className)

  • Function for add class name
Base.addClass(node, className) 

removeClass(node, className)

  • Function for remove class name
Base.removeClass(node, className) 

getAbsoluteUrl(url)

  • Function for get absolute url
Base.getAbsoluteUrl('/f3-t1') //return 'http://git.imweb.io/f3-t1'

debounce(callback, time)

  • Function for avoiding shake
  • example:
 test('Normal', (done) => {
    var total = 0
    const debounce = Base.createDebounce(() => {
      total += 1
      expect(total).toBe(1)
      done()
    }, 300)
    for (let i = 0; i < 10; i++) {
      debounce()
    }
    expect(total).toBe(0)
    debounce()
    expect(total).toBe(0)
  })

removeItemByIndex(index, arr)

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

HtmlEncode(str)

  • Function for filter Html Tag
Base.HtmlEncode(<a></a>)//return "&lt;a&gt;a&lt;/a&gt;"

fliter(str)

  • Function for filter appointed Tag and attributes
Base.fliter(`<script>alert</script><a href="a.com" onclick="alert(1)">test</a>`)//return `<a href="a.com" >test</a>`
2.0.2

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.0.0

6 years ago