npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

sp-func

v1.0.15

Published

Common Functions for Url, Validate, Ajax etc

Downloads

4

Readme

sp-func

Common Functions for Url, Validate, Ajax etc


Install

NPM

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

CDN

<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script src="https://unpkg.com/sp-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-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('[email protected]')
  //=> 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
  • Form.getData (name)
    • name: String
  __FUNC.Form.getData('age')
  //=> 18
  • Form.setData (name, value)
    • name: String
    • value: String
  __FUNC.Form.setData('age', 21)
  __FUNC.Form.getData('age')
  //=> 21

## License

MIT