thunder-util

1.2.2 • Public • Published

English | 简体中文

thunder-util

A lightweight and daily-used JavaScript library for your prototype development, including password and email address verification, decimal formatting of numbers, and more

Installation

npm i thunder-util

Examples

  • formatAllThousandSeparator(number)
import { formatAllThousandSeparator } from 'thunder-util'

const num = 100010.02
formatAllThousandSeparator(num) // => 100,010.02
  • throttle(func, millisecond)
function expensiveTask() {...}

const LowcostTask = throttle(expensiveTask, 200)
  • validateEmail(email)
const isValidEmail = validateEmail(email) // => true or false
  • validatePwd(password)
const isValid = validatePwd(password) // => true or false
  • validateChinaPhone(phoneNum)
// Verify that the Chinese mobile phone number format
const isValid = validateChinaPhone(phoneNum) // => true or false
  • downloadFile(file, fileName)
// Only be used in the browser
// The first parameter is File or Blob type
// The second parameter is the name of the download file
fetch('http://localhost:8888/someapi')
  .then(res => {
    if (!response.ok) {
      throw new Error(`HTTP error! Status: ${response.status}`)
    }

    return response.blob()
  })
  .then(blob => {
    downloadFile(blob, 'my-custom.txt') // you'll get my-custom.txt
  })

Compatibility

Writen by pure Javascript, so it can work well in all modern browser and Node.js >=8.

Readme

Keywords

Package Sidebar

Install

npm i thunder-util

Weekly Downloads

2

Version

1.2.2

License

MIT

Unpacked Size

7.27 kB

Total Files

6

Last publish

Collaborators

  • moddx