UNPKG

1.26 kBJavaScriptView Raw
1'use strict'
2
3/**
4 * adonis-framework
5 *
6 * (c) Harminder Virk <virk@adonisjs.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10*/
11
12const _ = require('lodash')
13
14const toStr = Object.prototype.toString
15const fnToStr = Function.prototype.toString
16const isFnRegex = /^\s*(?:function)?\*/
17
18const util = exports = module.exports = {}
19
20/**
21 * tells whether value exists or not by checking
22 * it type
23 *
24 * @param {Mixed} value
25 * @return {Boolean}
26 *
27 * @private
28 */
29util.existy = function (value) {
30 return value !== undefined && value !== null
31}
32
33/**
34 * @description returns an array from method arguments
35 *
36 * @method spread
37 *
38 * @return {Array}
39 *
40 * @private
41 */
42util.spread = function () {
43 return _.isArray(arguments[0]) ? arguments[0] : _.toArray(arguments)
44}
45
46/**
47 * tells whether a method is a genetator function or
48 * not
49 *
50 * @method isGenerator
51 *
52 * @param {Function} method
53 * @return {Boolean}
54 *
55 * @private
56 */
57util.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}