Skip to content

ljy1017010/thunder-util

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

A lightweight and daily-used JavaScript library for your prototype development.

Resources

License

Stars

Watchers

Forks

Packages

No packages published