Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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.
- Host: GitHub
- URL: https://github.com/liushuangls/tools.js
- Owner: liushuangls
- License: mit
- Created: 2018-05-04T08:29:47.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-03T17:26:11.000Z (about 2 years ago)
- Last Synced: 2024-11-10T21:06:52.524Z (about 2 months ago)
- Topics: javascript, library, utility
- Language: JavaScript
- Homepage:
- Size: 687 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 20
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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: StringExample:
format(1528128000000)
// 2018-06-05 00:00format(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 => nowforNow('2018/01/01', '2018/01/02')
// 2018/01/01 => 2018/01/02
```## Number
### isNumber(num)
判断`num`是否为`Number`。
```js
Arguments: num: anyReturns: Boolean
Example:
isNumber('') //false
isNumber(Infinity) //false
isNumber('123') // true
```