mux-lib
Version:
48 lines (32 loc) • 1.2 kB
text/typescript
import isPlainObject from "is-plain-object";
import invariant from "invariant";
import warning from "warning";
// 警告和报错
export { invariant, warning };
// 判断类型
export { isPlainObject };
export const isArray: ArrayConstructor["isArray"] = Array.isArray;
export const isFunction = (o: any): o is Function => typeof o === "function";
export const isBoolean = (o: any): o is boolean => typeof o === "boolean";
export const isEmptyObject = (o: any): o is Object =>
JSON.stringify(o) === "{}";
export const isString = (o: any): o is string => typeof o === "string";
export const checkFunctionType = o =>
Object.prototype.toString
.call(o)
.replace(/\[object\s(.*)\]/, (all, matched) => matched);
export const isGeneratorFunction = o =>
checkFunctionType(o) === "GeneratorFunction";
export const isAsyncFunction = o => checkFunctionType(o) === "AsyncFunction";
// 常用的方法
export const returnSelf = arg => arg;
export const noop = () => {};
export const hasOwnProperty = (obj, key) =>
Object.prototype.hasOwnProperty.call(obj, key);
export const mapToObj = (o: Map<any, any>) => {
let a = {};
o.forEach((v, k) => {
a[k] = v;
});
return a;
};