Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/liushuangls/tools.js

A JavaScript utility library.
https://github.com/liushuangls/tools.js

javascript library utility

Last synced: about 2 months ago
JSON representation

A JavaScript utility library.

Awesome Lists containing this project

README

        

# tools.js
[![Coverage Status](https://coveralls.io/repos/github/liushuangbill/dates.js/badge.svg?branch=master)](https://coveralls.io/github/liushuangbill/dates.js?branch=master)

## Use
Install
```
yarn add tools.js or npm i -S tools.js
```

ES2015+:
```js
import { xxx } from 'tools.js'
```

## 目录
- [Date](#date)
- [format](#formatdate-template)
- [fromNow](#fromnowdate-date2)
- [Number](#number)
- [isNumber](#isnumbernum)

# API

## Date

### format([date, template])
返回指定格式的时间字符串。
```js
Arguments:
[date=new Date()](timestamp or Date)
[template='y-M-d h:m'](String): y: year, M: month, d: day, h: hour, m: minute, s: second

Returns: String

Example:
format(1528128000000)
// 2018-06-05 00:00

format(1528128000000, 'YYY/MM/DD h:m:s')
// 2018/06/05 00:00:00
```

### fromNow(date[, date2])
计算并返回可读时间差。
```js
Arguments:
date(timestamp or FormatDateTime)
[date2 = new Date()](timestamp or FormatDateTime)

Returns:
(String): "1秒以前 or 1分钟以前 or 1小时以前 or 1天以前 ..."

Example:
fromNow('2018/01/01');
// 2018/01/01 => now

forNow('2018/01/01', '2018/01/02')
// 2018/01/01 => 2018/01/02
```

## Number

### isNumber(num)
判断`num`是否为`Number`。
```js
Arguments: num: any

Returns: Boolean

Example:
isNumber('') //false
isNumber(Infinity) //false
isNumber('123') // true
```