🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

sp-fe-func

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
Package was removed
Sorry, it seems this package was removed from the registry

sp-fe-func

Common Functions for Url, Validate, Ajax etc

unpublished
latest
Source
npmnpm
Version
1.0.11
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

sp-fe-func

Common Functions for Url, Validate, Ajax etc

Install

NPM

npm install --save sp-fe-func
// or yarn add sp-fe-func

CDN

<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script src="https://unpkg.com/sp-fe-func/index.min.js"></script>
<script>
  __FUNC.serviceAPI(options = {
    url: '/',
    method: 'get',
    data: {},
    success: function () {},
    fail: function () {},
    headers: {}
  });
  __FUNC.serviceAPI({url: 'http://test.com/test.json'})
</script>

Usage

 //__FUNC: {serviceAPI, Validate, Url, Validate}
const __FUNC = require('sp-fe-func')

API Request

Based on axios.

  • serviceAPI (options = {})
    • options
      • [url]: String
      • [method]: String
      • [data]: Object
      • [success]: Function
      • [fail]: Function
  __FUNC.serviceAPI({
    url: 'http://test.com/test.json',
    success: (res) => {
      console.log(res)
    }
  })

Validate

  • isEmail (email)
    • email: String
  __FUNC.Validate.isEmail('test@test.com')
  //=> true
  • isEqual (str, compare, isDeep)
    • str: String
    • compare: String
    • [isDeep]: Boolean
  __FUNC.Validate.isEqual('123','123')
  //=> true

  __FUNC.Validate.isEqual('123',123,true)
    //=> false

Chinese IdCard Validate (length = 18)

  • isIdCard (id)
    • id: String

  __FUNC.Validate.isIdCard('51018419700106006X')
  //=> return {areaCode:510184,year:1970,month:01,day:06, gender:0}
  //Boolean(return) = true

  __FUNC.Validate.isIdCard('510184197001060060')
  //=> false
  • isNumber (num, length)
    • num: String
    • [length]: Number default is num.length

  __FUNC.Validate.isNumber('13619120030')
  //=> true

  __FUNC.Validate.isNumber('12132535x')
  //=> false

  __FUNC.Validate.isNumber('12132535x', 5)
  //=> true

Chinese PhoneNumber Validate (length = 11)

  • isPhoneNumber (num)
    • num: String

  __FUNC.Validate.isPhoneNumber('13619120030')
  //=> true

  __FUNC.Validate.isPhoneNumber('12132535')
  //=> false
  • isEmpty (str)
    • str: String

  __FUNC.Validate.isEmpty('')
  //=> true

  __FUNC.Validate.isEmpty('1')
  //=> false

Url

  • getParams (url, keyName)
    • url: String
    • [keyName]: String
  __FUNC.Url.getParams('http://test.com/user?id=23&name=alice')
  //=> {id: 23, name: alice}

  __FUNC.Url.getParams('http://test.com/user?id=23&name=alice', 'name')
  //=> alice

Storage

  • setStorage (name, value, isSession)
    • name: String
    • value: String
    • isSession: Boolean
  __FUNC.Storage.setStorage('age','18')
  //=> sessionStorage.age = 18

  __FUNC.Storage.setStorage('age','19', false)
  //=> localStorage.age = 19
  • getStorage (name, isSession)
    • name: String
    • isSession: Boolean
  __FUNC.Storage.getStorage('age')
  //=> sessionStorage.age = 18

  __FUNC.Storage.getStorage('age', false)
  //=> localStorage.age = 19

License

MIT

Keywords

sp-fe-func

FAQs

Package last updated on 12 Dec 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts