GithubHelp home page GithubHelp logo

yhtml5 / utils Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 0.0 50 KB

A modern JavaScript utility library delivering modularity, performance, & extras.

License: MIT License

JavaScript 26.71% CSS 23.53% TypeScript 45.36% Shell 4.39%

utils's Introduction

Common utils

Build Status Coverage Status

This repository contains common utility functions for front-end development.

isType

This file exports various functions for type checking. Here are the available functions:

  • isUndefined: Checks if the value is undefined.
  • isNull: Checks if the value is null.
  • isNumber: Checks if the value is a number.
  • isString: Checks if the value is a string.
  • isSymbol: Checks if the value is a symbol.
  • isFunction: Checks if the value is a function.
  • isArray: Checks if the value is an array.
  • isArrayEmpty: Checks if the array is empty.
  • isArrayNotEmpty: Checks if the array is not empty.
  • isObject: Checks if the value is an object.
  • isObjectEmpty: Checks if the object is empty.

formatNumber

This file exports a function formatNumber(number: number | string, option: Config) that formats a number according to the specified options. The available options are:

  • decimals: How many decimal places to keep, default is 0.
  • decPoint: Decimal point symbol, default is '.'.
  • roundtag: Rounding parameter, can be 'ceil' (round up), 'floor' (round down), 'round' (round), default is 'round'.
  • thousandsSep: Thousands separator symbol, default is an empty string.
  • util: How many digits to switch units, default is 10,000.

formatTime

This file exports a function formatTime(time: Date, format: string) that formats a date object according to the specified format. The format string can include the following placeholders:

  • M+: Month (1-12)
  • D+: Day of the month (1-31)
  • h+: Hour (0-23)
  • m+: Minute (0-59)
  • s+: Second (0-59)
  • q+: Quarter (1-4)
  • S: Milliseconds

The format string can also include the placeholder y+ for the year. For example, the format string 'yyyy-MM-dd hh:mm:ss' will format the date as '2022-01-01 12:00:00'.

validator.ts

This file exports various functions for validating different types of data. Here are the available functions:

  • isBankCardNum(str: string): boolean: Checks if the string is a valid bank card number.
  • isChinaName(str: string): boolean: Checks if the string is a valid Chinese name.
  • isChinaPhone(str: string): boolean: Checks if the string is a valid Chinese phone number.
  • isEmail(str: string): boolean: Checks if the string is a valid email address.
  • isIdCard(str: string): boolean: Checks if the string is a valid ID card number.
  • isNum(str: string): boolean: Checks if the string consists of only numbers.
  • isNumSixToTwenty(str: string): boolean: Checks if the string is a valid number with 6 to 20 characters.

Please refer to the code comments for more details on each function.

utils's People

Contributors

yhtml5 avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.