1 | # xe-utils
|
2 |
|
3 | [![gitee star](https://gitee.com/x-extends/xe-utils/badge/star.svg?theme=dark)](https://gitee.com/x-extends/xe-utils/stargazers)
|
4 | [![npm version](https://img.shields.io/npm/v/xe-utils.svg?style=flat-square)](https://www.npmjs.com/package/xe-utils)
|
5 | [![npm build](https://travis-ci.com/x-extends/vxe-utils.svg?branch=master)](https://travis-ci.com/x-extends/xe-utils)
|
6 | [![npm downloads](https://img.shields.io/npm/dm/xe-utils.svg?style=flat-square)](http://npm-stat.com/charts.html?package=xe-utils)
|
7 | [![gzip size: JS](http://img.badgesize.io/https://unpkg.com/xe-utils/dist/xe-utils.umd.min.js?compression=gzip&label=gzip%20size:%20JS)](https://unpkg.com/xe-utils/dist/xe-utils.umd.min.js)
|
8 | [![npm license](https://img.shields.io/github/license/mashape/apistatus.svg)](LICENSE)
|
9 |
|
10 | JavaScript 函数库、工具类
|
11 |
|
12 | ## Browser Support
|
13 |
|
14 | ![IE](https://raw.github.com/alrra/browser-logos/master/src/archive/internet-explorer_7-8/internet-explorer_7-8_48x48.png) | ![Edge](https://raw.github.com/alrra/browser-logos/master/src/edge/edge_48x48.png) | ![Chrome](https://raw.github.com/alrra/browser-logos/master/src/chrome/chrome_48x48.png) | ![Firefox](https://raw.github.com/alrra/browser-logos/master/src/firefox/firefox_48x48.png) | ![Opera](https://raw.github.com/alrra/browser-logos/master/src/opera/opera_48x48.png) | ![Safari](https://raw.github.com/alrra/browser-logos/master/src/safari/safari_48x48.png)
|
15 | --- | --- | --- | --- | --- | --- |
|
16 | 7+ ✔ | Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ | 6+ ✔ |
|
17 |
|
18 | ## Docs
|
19 |
|
20 | [To view the document](https://x-extends.github.io/xe-utils/) [查看文档](https://x-extends.gitee.io/xe-utils/)
|
21 |
|
22 | ## Installing
|
23 |
|
24 | ```shell
|
25 | npm install xe-utils
|
26 | ```
|
27 |
|
28 | Using nodejs
|
29 |
|
30 | ```javascript
|
31 | const XEUtils = require('xe-utils')
|
32 | ```
|
33 |
|
34 | Get on [unpkg](https://unpkg.com/xe-utils/) and [cdnjs](https://cdn.jsdelivr.net/npm/xe-utils/)
|
35 |
|
36 | ```HTML
|
37 | <script src="https://cdn.jsdelivr.net/npm/xe-utils"></script>
|
38 | ```
|
39 |
|
40 | ### Import all methods
|
41 |
|
42 | ```javascript
|
43 | import _XEUtils_ from 'xe-utils'
|
44 |
|
45 | XEUtils.toDateString(Date.now())
|
46 | // 2018-01-01 10:30:28
|
47 | XEUtils.toStringDate('2018-01-01 10:30:00')
|
48 | // Mon Jan 01 2018 10:30:00 GMT+0800 (中国标准时间)
|
49 | ```
|
50 |
|
51 | ## Import on demand
|
52 |
|
53 | 这样按需引入方法,可以使体积达到最小
|
54 | 单个导入,包的大小 gzip >≈ 60B+,按需导入
|
55 |
|
56 | ```javascript
|
57 | import each from 'xe-utils/each'
|
58 | import toDateString from 'xe-utils/toDateString'
|
59 |
|
60 | each({ a: 11, b: 22, c: 33 }, function (item, key){
|
61 | console.log(item)
|
62 | })
|
63 | // 11
|
64 | // 22
|
65 | // 33
|
66 | toDateString(Date.now(), 'yyyy-MM-dd HH:mm:ss')
|
67 | // 2018-01-01 10:30:28
|
68 | ```
|
69 |
|
70 | ```javascript
|
71 | import XEUtils from 'xe-utils/ctor'
|
72 | import each from 'xe-utils/each'
|
73 | import toDateString from 'xe-utils/toDateString'
|
74 | import toFixedNumber from 'xe-utils/toFixedNumber'
|
75 |
|
76 | XEUtils.mixin({
|
77 | each,
|
78 | toDateString,
|
79 | toFixedNumber
|
80 | })
|
81 | XEUtils.toDateString(Date.now(), 'yyyy-MM-dd HH:mm:ss')
|
82 | // 2018-01-01 10:30:28
|
83 | ```
|
84 |
|
85 | 按功能导入所有方法
|
86 |
|
87 | ```javascript
|
88 | import XEUtils from 'xe-utils/ctor'
|
89 | import objectMethods from 'xe-utils/object'
|
90 | import arrayMethods from 'xe-utils/array'
|
91 | import baseMethods from 'xe-utils/base'
|
92 | import numberMethods from 'xe-utils/number'
|
93 | import dateMethods from 'xe-utils/date'
|
94 | import stringMethods from 'xe-utils/string'
|
95 | import functionMethods from 'xe-utils/function'
|
96 | import urlMethods from 'xe-utils/url'
|
97 | import webMethods from 'xe-utils/web'
|
98 |
|
99 | XEUtils.mixin(
|
100 | // Object
|
101 | objectMethods,
|
102 | // Array
|
103 | arrayMethods,
|
104 | // Base
|
105 | baseMethods,
|
106 | // Number
|
107 | numberMethods,
|
108 | // Date
|
109 | dateMethods,
|
110 | // String
|
111 | stringMethods,
|
112 | // Function
|
113 | functionMethods,
|
114 | // URL
|
115 | urlMethods,
|
116 | // Web
|
117 | webMethods
|
118 | )
|
119 | ```
|
120 |
|
121 | ## License
|
122 |
|
123 | [MIT](LICENSE) © 2017-present, Xu Liangzhan
|