1 | 'use strict'
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | const _ = require('lodash')
|
13 |
|
14 | const toStr = Object.prototype.toString
|
15 | const fnToStr = Function.prototype.toString
|
16 | const isFnRegex = /^\s*(?:function)?\*/
|
17 |
|
18 | const util = exports = module.exports = {}
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 | util.existy = function (value) {
|
30 | return value !== undefined && value !== null
|
31 | }
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 | util.spread = function () {
|
43 | return _.isArray(arguments[0]) ? arguments[0] : _.toArray(arguments)
|
44 | }
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 | util.isGenerator = function (method) {
|
58 | const viaToStr = toStr.call(method)
|
59 | const viaFnToStr = fnToStr.call(method)
|
60 | return (viaToStr === '[object Function]' || viaToStr === '[object GeneratorFunction]') && isFnRegex.test(viaFnToStr)
|
61 | }
|