forked from adonisjs/core
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.js
More file actions
61 lines (54 loc) · 1.23 KB
/
util.js
File metadata and controls
61 lines (54 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
'use strict'
/**
* adonis-framework
*
* (c) Harminder Virk <virk@adonisjs.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
const _ = require('lodash')
const toStr = Object.prototype.toString
const fnToStr = Function.prototype.toString
const isFnRegex = /^\s*(?:function)?\*/
const util = exports = module.exports = {}
/**
* tells whether value exists or not by checking
* it type
*
* @param {Mixed} value
* @return {Boolean}
*
* @private
*/
util.existy = function (value) {
return value !== undefined && value !== null
}
/**
* @description returns an array from method arguments
*
* @method spread
*
* @return {Array}
*
* @private
*/
util.spread = function () {
return _.isArray(arguments[0]) ? arguments[0] : _.toArray(arguments)
}
/**
* tells whether a method is a genetator function or
* not
*
* @method isGenerator
*
* @param {Function} method
* @return {Boolean}
*
* @private
*/
util.isGenerator = function (method) {
const viaToStr = toStr.call(method)
const viaFnToStr = fnToStr.call(method)
return (viaToStr === '[object Function]' || viaToStr === '[object GeneratorFunction]') && isFnRegex.test(viaFnToStr)
}