Coder Social home page Coder Social logo

jutils's Introduction

logo

jutils

npm Build Status LICENSE MIT

JavaScript常用函数库

在日常工作生活中,会经常用到一些日期格式化url相关操作浏览器类型判断常用验证格式等等函数,虽然大部分只需谷歌/百度一下就能找到,但是大多数都存在着一些问题,于是整理了网上和自己平常用到的工具类,方便大家以后的使用,提升开发效率。

安装

直接用 <script> 引入

直接下载并用 <script> 标签引入,jutils 会被注册为一个全局变量。

<script src="jutils.min.js"></script>
<script>
  var browser = jutils.getBrowserInfo()
</script>

CDN

你也可以这样使用最新版本:

<script src="https://cdn.jsdelivr.net/npm/jutils-src"></script>

NPM

NPM 能很好地和 webpack 模块打包器配合使用。

# 最新稳定版
$ npm install jutils-src

API 目录

浏览器

数组

日期

  • formatDate 时间戳的转换(自定义格式)
  • getTimeInterval 获取两个时间的间隔的天、小时、分钟和秒

API 说明

getBrowserInfo

获取浏览器信息

jutils.getBrowserInfo();
//{name: "Chrome", version: "76.0.3809.100"}

isCss3Support

判断是否支持css3

jutils.isCss3Support() ? true : false

arrayUniq

高性能数组去重

jutils.arrayUniq([0,1,2,2,3,4,4,5,6]);
// [0, 1, 2, 3, 4, 5, 6]

formatDate

时间戳的转换(自定义格式)

年、月、日、时、分、秒

var date = jutils.formatDate(new Date(1533686888*1000),"YYYY-MM-DD HH:ii:ss");
console.log(date);
// 2019-07-09 19:44:01

getTimeInterval

获取两个时间的间隔,返回间隔的天、小时、分钟和秒。 注意:结束时间要大于开始时间否则返回空

jutils.getTimeInterval("开始时间", "结束时间");
//例:
jutils.getTimeInterval(1567562605000, 1567649014000)
//1天0小时0分钟9秒

jutils's People

Contributors

dong-sir 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.