import { ASTParserTree , KeyVal , Node } from '../parser/index' ; import { Token } from '../parser' ; import { TypedefRegistry } from '../types/typedef-registry' ; import { datetimeExp , datetimePlainExp } from './datetime' ; param val returns export const isUndefined = ( val ) : val is undefined => { const _undefined = undefined ; return val === _undefined ; } ; param val returns export const isNumber = ( val ) : val is number => { return typeof val === 'number' ; } ; param val returns export const isString = ( val ) : val is string => { return typeof val === 'string' ; } ; param val returns export const isBoolean = ( val ) : val is boolean => { return typeof val === 'boolean' ; } ; param val returns export const isDate = ( val ) : val is Date => { return val instanceof Date ; } ; param val returns export const isDTTypeString = ( val ) : val is string => { return isDateTimeString ( val ) || isDateString ( val ) || isTimeString ( val ) ; } ; param val returns export const isDateTimeString = ( val ) : val is string => { const exp = /[\-\:]/ . test ( val ) ? datetimeExp . datetime : datetimePlainExp . datetime ; return exp . test ( val ) ; } ; param val returns export const isDateString = ( val ) : val is string => { const exp = /\-/ . test ( val ) ? datetimeExp . date : datetimePlainExp . date ; return exp . test ( val ) ; } ; param val returns export const isTimeString = ( val ) : val is string => { const exp = /\:/ . test ( val ) ? datetimeExp . time : datetimePlainExp . time ; return exp . test ( val ) ; } ; param val returns export const isArray = ( val ) : val is Array < any > => { return val instanceof Array ; } ; export const isPlainObject = ( val ) => { if ( typeof val !== 'object' ) return false ; const ctor = val . constructor ; if ( typeof ctor !== 'function' ) return false ; const prot = ctor . prototype ; if ( typeof prot !== 'object' ) return false ; if ( prot . hasOwnProperty ( 'isPrototypeOf' ) === false ) { return false ; } return true ; } ; param val returns export const isDataType = ( val ) : boolean => { return TypedefRegistry . isRegisteredType ( val ) ; } ; export function isParserTree ( obj ) { try { return 'type' in obj && 'values' in obj ; } catch { return false ; } } param obj returns export function isToken ( obj ) { try { return obj && obj . token !== undefined && obj . value !== undefined ; } catch { return false ; } } param obj returns export function isNode ( obj ) { try { return obj && obj . index !== undefined && obj . row !== undefined && obj . col !== undefined ; } catch { return false ; } } export function isDefined < T > ( val ) { return val !== null && val !== undefined ; } param obj returns export function isKeyVal ( obj ) { try { return 'key' in obj && 'value' in obj ; } catch { return false ; } } param obj export const isSchemaDef = ( obj ) => { if ( isArray ( obj ) ) { return typeof obj [ 0 ] === 'string' && isDataType ( obj [ 0 ] ) ; } } ;