export { merge, camelCase, upperFirst, cloneDeep } from '@vtj/utils';

/**
 * 生成 hash id
 * @returns id
 */
export function hashId() {
  return Number(Math.random().toString().substring(2, 5) + Date.now()).toString(
    36
  );
}

export function isCSSUrl(url: string): boolean {
  return /\.css$/.test(url);
}

export function isJSUrl(url: string): boolean {
  return /\.js$/.test(url);
}

export function isElement(node: any): node is Element {
  if (!node) return false;
  return node.nodeType === Node.ELEMENT_NODE;
}

export function isFunction(fn: any): boolean {
  return typeof fn === 'function';
}

export function isJSExpression(data: any) {
  return data && data.type === 'JSExpression';
}

export function isJSFunction(x: any) {
  return typeof x === 'object' && x && x.type === 'JSFunction';
}

export function isObject(value: any): value is Record<string, unknown> {
  return value !== null && typeof value === 'object';
}

export function isString(value: any): boolean {
  return typeof value === 'string';
}

export function isI18NObject(value: any): boolean {
  return isObject(value) && value.type === 'i18n';
}

export function isTextChildren(children: any) {
  return typeof children === 'string';
}

export function isUndefined(value: any): boolean {
  return typeof value === 'undefined' || value === null;
}

export function arrayToMap(array: any[], keyName: string) {
  const map: any = {};
  for (let item of array) {
    map[item[keyName]] = item;
  }
  return map;
}
