{"version":3,"sources":["../../src/utils/is.ts"],"sourcesContent":["import TypedefRegistry from '../schema/typedef-registry'\r\nimport { datetimeExp, datetimePlainExp } from './datetime'\r\n\r\n/**\r\n * Checks whether specified value is date or not.\r\n *\r\n * @param val The value to be tested for date check!\r\n * @returns `true` if the value is a date otherwise `false`\r\n */\r\nexport const isDTTypeString = (val: any): val is string => {\r\n  return isDateTimeString(val) || isDateString(val) || isTimeString(val)\r\n}\r\n\r\n/**\r\n * Checks whether specified value is datetime or not.\r\n *\r\n * @param val The value to be tested for number check!\r\n * @returns `true` if the value is a datetime otherwise `false`\r\n */\r\nexport const isDateTimeString = (val: any): val is string => {\r\n  const exp = /[\\-\\:]/.test(val) ? datetimeExp.datetime : datetimePlainExp.datetime\r\n  return exp.test(val)\r\n}\r\n\r\n/**\r\n * Checks whether specified value is date or not.\r\n *\r\n * @param val The value to be tested for date check!\r\n * @returns `true` if the value is a date otherwise `false`\r\n */\r\nexport const isDateString = (val: any): val is string => {\r\n  const exp = /\\-/.test(val) ? datetimeExp.date : datetimePlainExp.date\r\n  return exp.test(val)\r\n}\r\n\r\n/**\r\n * Checks whether specified value is time or not.\r\n *\r\n * @param val The value to be tested for time check!\r\n * @returns `true` if the value is a date otherwise `false`\r\n */\r\nexport const isTimeString = (val: any): val is string => {\r\n  const exp = /\\:/.test(val) ? datetimeExp.time : datetimePlainExp.time\r\n  return exp.test(val)\r\n}\r\n\r\n/**\r\n * Checks whether specified value is an array or not.\r\n *\r\n * @param val The value to be tested for an array check!\r\n * @returns `true` if the value is an array otherwise `false`\r\n */\r\nexport const isArray = (val: any): val is Array<any> => {\r\n  return val instanceof Array\r\n}\r\n\r\nexport const isPlainObject = (val: any) => {\r\n  if (typeof val !== 'object') return false\r\n\r\n  // If has modified constructor\r\n  const ctor = val.constructor\r\n  if (typeof ctor !== 'function') return false\r\n\r\n  // If has modified prototype\r\n  const prot = ctor.prototype\r\n  if (typeof prot !== 'object') return false\r\n\r\n  // If constructor does not have an Object-specific method\r\n  if (prot.hasOwnProperty('isPrototypeOf') === false) {\r\n    return false\r\n  }\r\n\r\n  // Most likely a plain Object\r\n  return true\r\n}\r\n\r\n/**\r\n * Checks whether specified value reprents datatype.\r\n *\r\n * @param val The value to be tested for an datatype check!\r\n * @returns `true` if the value is a datatype otherwise `false`\r\n */\r\nexport const isDataType = (val: string): boolean => {\r\n  return TypedefRegistry.isRegisteredType(val)\r\n}\r\n\r\n\r\nexport function isDefined<T>(val: T | null | undefined): val is T {\r\n  return val !== null && val !== undefined\r\n}\r\n\r\n\r\n/**\r\n *\r\n * @param obj\r\n */\r\nexport const isSchemaDef = (obj: any): boolean => {\r\n  if (isArray(obj)) {\r\n    return typeof obj[0] === 'string' && isDataType(obj[0])\r\n  }\r\n  return false\r\n}\r\n\r\n// export function isToken(val: any): val is Token {\r\n//   if (!val) return false\r\n\r\n//   if (typeof val !== 'obj') return false\r\n\r\n//   const keys = Object.keys(val)\r\n\r\n// }\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,8BAA4B;AAC5B,sBAA8C;AAQvC,MAAM,iBAAiB,CAAC,QAA4B;AACzD,SAAO,iBAAiB,GAAG,KAAK,aAAa,GAAG,KAAK,aAAa,GAAG;AACvE;AAQO,MAAM,mBAAmB,CAAC,QAA4B;AAC3D,QAAM,MAAM,SAAS,KAAK,GAAG,IAAI,4BAAY,WAAW,iCAAiB;AACzE,SAAO,IAAI,KAAK,GAAG;AACrB;AAQO,MAAM,eAAe,CAAC,QAA4B;AACvD,QAAM,MAAM,KAAK,KAAK,GAAG,IAAI,4BAAY,OAAO,iCAAiB;AACjE,SAAO,IAAI,KAAK,GAAG;AACrB;AAQO,MAAM,eAAe,CAAC,QAA4B;AACvD,QAAM,MAAM,KAAK,KAAK,GAAG,IAAI,4BAAY,OAAO,iCAAiB;AACjE,SAAO,IAAI,KAAK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