'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var validate_type = require('../validate/type.js');
require('@babel/runtime/helpers/typeof');

/**
 * 将函数转成 Promise
 * @param {function} promiseLike 任意函数，可以为 Promise
 * @returns Promise 函数
 * @example
 * ```
 * const bar = () => 1;
 * toPromise(bar()).then(res => console.log(res)); // 1

 * function foo() {
 *   return new Promise(resolve => setTimeout(() => resolve(2), 1000));
 * }
 * toPromise(foo()).then(res => console.log(res)); // 2
 *
 * ```
 */
function toPromise(promiseLike) {
  if (validate_type.isPromise(promiseLike)) {
    return promiseLike;
  }
  return Promise.resolve(promiseLike);
}

exports.toPromise = toPromise;
