1.2.2 • Published 3 months ago

thunder-util v1.2.2

Weekly downloads
1
License
MIT
Repository
github
Last release
3 months ago

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.

1.2.2

3 months ago

1.2.1

5 months ago

1.2.0

6 months ago

1.1.0

7 months ago

1.0.5

8 months ago

1.0.4

1 year ago

1.0.2

1 year ago

1.0.3

1 year ago

1.0.1

4 years ago

1.0.0

4 years ago