import * as ts from '@terascope/utils' ; import ipaddr from 'ipaddr.js' ; import _isIP from 'is-ip' ; import ip6addr from 'ip6addr' ; import validateCidr from 'is-cidr' ; import PhoneValidator from 'awesome-phonenumber' ; import validator from 'validator' ; import * as url from 'valid-url' ; import { FieldType , GeoShapePoint , MACDelimiter } from '@terascope/types' ; import { FQDNOptions , HashConfig , LengthConfig , PostalCodeLocale , ArgsISSNOptions , } from './interfaces' ; import * as i from '../interfaces' ; export const repository = { isBoolean : { fn : isBoolean , config : { } , primary_input_type : i . InputType . Boolean } , isBooleanLike : { fn : isBooleanLike , config : { } , primary_input_type : i . InputType . Any } , isEmail : { fn : isEmail , config : { } , primary_input_type : i . InputType . String } , isGeoJSON : { fn : isGeoJSON , config : { } , primary_input_type : i . InputType . Object } , isGeoPoint : { fn : isGeoPoint , config : { } , primary_input_type : i . InputType . String } , isGeoShapePoint : { fn : isGeoShapePoint , config : { } , primary_input_type : i . InputType . Object } , isGeoShapePolygon : { fn : isGeoShapePolygon , config : { } , primary_input_type : i . InputType . Object } , isGeoShapeMultiPolygon : { fn : isGeoShapeMultiPolygon , config : { } , primary_input_type : i . InputType . Object } , isIP : { fn : isIP , config : { } , primary_input_type : i . InputType . String } , isISDN : { fn : isISDN , config : { } , primary_input_type : i . InputType . String } , isMACAddress : { fn : isMACAddress , config : { delimiter : { type : FieldType . String , array : true } } , primary_input_type : i . InputType . String } , isNumber : { fn : isNumber , config : { } , primary_input_type : i . InputType . Number } , isInteger : { fn : isInteger , config : { } , primary_input_type : i . InputType . Number } , inNumberRange : { fn : inNumberRange , config : { min : { type : FieldType . Number } , max : { type : FieldType . Number } , inclusive : { type : FieldType . Boolean } } , primary_input_type : i . InputType . Number } , isString : { fn : isString , config : { } , primary_input_type : i . InputType . String } , isURL : { fn : isURL , config : { } , primary_input_type : i . InputType . String } , isUUID : { fn : isUUID , config : { } , primary_input_type : i . InputType . String } , contains : { fn : contains , config : { value : { type : FieldType . String } } , primary_input_type : i . InputType . Array } , equals : { fn : equals , config : { value : { type : FieldType . String } } , primary_input_type : i . InputType . Any } , isAlpha : { fn : isAlpha , config : { locale : { type : FieldType . String } } , primary_input_type : i . InputType . String } , isAlphanumeric : { fn : isAlphanumeric , config : { locale : { type : FieldType . String } } , primary_input_type : i . InputType . String } , isASCII : { fn : isASCII , config : { } , primary_input_type : i . InputType . String } , isBase64 : { fn : isBase64 , config : { } , primary_input_type : i . InputType . String } , isEmpty : { fn : isEmpty , config : { ignoreWhitespace : { type : FieldType . Boolean } } , primary_input_type : i . InputType . Any } , isFQDN : { fn : isFQDN , config : { requireTld : { type : FieldType . Boolean } , allowUnderscores : { type : FieldType . Boolean } , allowTrailingDot : { type : FieldType . Boolean } , } , primary_input_type : i . InputType . String } , isHash : { fn : isHash , config : { algo : { type : FieldType . String } } , primary_input_type : i . InputType . String } , isCountryCode : { fn : isCountryCode , config : { } , primary_input_type : i . InputType . String } , isISO8601 : { fn : isISO8601 , config : { } , primary_input_type : i . InputType . String } , isISSN : { fn : isISSN , config : { caseSensitive : { type : FieldType . Boolean } , requireHyphen : { type : FieldType . Boolean } } , primary_input_type : i . InputType . String } , isRFC3339 : { fn : isRFC3339 , config : { } , primary_input_type : i . InputType . String } , isJSON : { fn : isJSON , config : { } , primary_input_type : i . InputType . String } , isLength : { fn : isLength , config : { size : { type : FieldType . Number } , min : { type : FieldType . Number } , max : { type : FieldType . Number } , } , primary_input_type : i . InputType . String } , isMIMEType : { fn : isMIMEType , config : { } , primary_input_type : i . InputType . String } , isPostalCode : { fn : isPostalCode , config : { locale : { type : FieldType . String } } , primary_input_type : i . InputType . String } , isRoutableIP : { fn : isRoutableIP , config : { } , primary_input_type : i . InputType . String } , isNonRoutableIP : { fn : isNonRoutableIP , config : { } , primary_input_type : i . InputType . String } , inIPRange : { fn : inIPRange , config : { min : { type : FieldType . String } , max : { type : FieldType . String } , cidr : { type : FieldType . String } } , primary_input_type : i . InputType . String } , isCIDR : { fn : isCIDR , config : { } , primary_input_type : i . InputType . String } , exists : { fn : exists , config : { } , primary_input_type : i . InputType . Any } , guard : { fn : guard , config : { } , primary_input_type : i . InputType . Any } , isArray : { fn : isArray , config : { } , primary_input_type : i . InputType . Array } , some : { fn : some , config : { fn : { type : FieldType . String } , options : { type : FieldType . Object } } , primary_input_type : i . InputType . Array } , every : { fn : every , config : { fn : { type : FieldType . String } , options : { type : FieldType . Object } } , primary_input_type : i . InputType . Array } , } ; function _lift ( fn , input , parentContext ? , args ? ) { const sanitized = input . filter ( ts . isNotNil ) ; if ( sanitized . length === 0 ) return false ; return sanitized . every ( ( data ) => fn ( data , parentContext , args ) ) ; } function handleArgs ( fn ) { return ( data , _parentContext , args ) => fn ( data , args ) ; } example param { * } input returns { boolean } export function isBoolean ( input , _parentContext ? ) { if ( ts . isNil ( input ) ) return false ; if ( isArray ( input ) ) return _lift ( handleArgs ( ts . isBoolean ) , input , _parentContext ) ; return ts . isBoolean ( input ) ; } example param { * } input returns { boolean } export function isBooleanLike ( input , _parentContext ? ) { if ( isArray ( input ) ) return input . every ( ts . isBooleanLike ) ; return ts . isBooleanLike ( input ) ; } example param { * } input returns { boolean } export function isEmail ( input , _parentContext ? ) { if ( ts . isNil ( input ) ) return false ; if ( isArray ( input ) ) return _lift ( handleArgs ( ts . isEmail ) , input , _parentContext ) ; return ts . isEmail ( input ) ; } example param { * } input returns { boolean } export function isGeoPoint ( input , _parentContext ? ) { if ( ts . isNil ( input ) ) return false ; if ( isArray ( input ) && ! isNumberTuple ( input ) ) { return _lift ( handleArgs ( ts . parseGeoPoint ) , input , _parentContext , false ) ; } const results = ts . parseGeoPoint ( input as any , false ) ; return results != null ; } example param { * } input returns { boolean } export function isGeoJSON ( input , _parentContext ? ) { if ( ts . isNil ( input ) ) return false ; if ( isArray ( input ) ) return _lift ( handleArgs ( ts . isGeoJSON ) , input , _parentContext ) ; return ts . isGeoJSON ( input ) ; } example param { JoinGeoShape } input returns { boolean } export function isGeoShapePoint ( input , _parentContext ? ) ; export function isGeoShapePoint ( input , _parentContext ? ) ; export function isGeoShapePoint ( input , _parentContext ? ) { if ( ts . isNil ( input ) ) return false ; if ( isArray ( input ) ) return _lift ( handleArgs ( ts . isGeoShapePoint ) , input , _parentContext ) ; return ts . isGeoShapePoint ( input as any ) ; } example param { JoinGeoShape } input returns { boolean } export function isGeoShapePolygon ( input , _parentContext ? ) { if ( ts . isNil ( input ) ) return false ; if ( isArray ( input ) ) return _lift ( handleArgs ( ts . isGeoShapePolygon ) , input , _parentContext ) ; return ts . isGeoShapePolygon ( input as any ) ; } example param { JoinGeoShape } input returns { boolean } export function isGeoShapeMultiPolygon ( input , _parentContext ? ) { if ( ts . isNil ( input ) ) return false ; if ( isArray ( input ) ) return _lift ( handleArgs ( ts . isGeoShapeMultiPolygon ) , input , _parentContext ) ; return ts . isGeoShapeMultiPolygon ( input as any ) ; } example param { * } input returns { boolean } export function isIP ( input , _parentContext ? ) { if ( ts . isNil ( input ) ) return false ; if ( isArray ( input ) ) return _lift ( isValidIP , input , _parentContext ) ; return isValidIP ( input ) ; } function isValidIP ( input , _parentContext ? ) { if ( ! ts . isString ( input ) ) return false ; if ( ! _isIP ( input ) ) return false ; return true ; } example param { * } input returns { boolean } export function isRoutableIP ( input , _parentContext ? ) { if ( ts . isNil ( input ) ) return false ; if ( isArray ( input ) ) return _lift ( _isRoutableIP , input , _parentContext ) ; return _isRoutableIP ( input ) ; } function _isRoutableIP ( input , _parentContext ? ) { if ( ! isIP ( input ) ) return false ; return ! _privateIP ( input ) ; } example param { * } input returns { boolean } export function isNonRoutableIP ( input , _parentContext ? ) { if ( ts . isNil ( input ) ) return false ; if ( isArray ( input ) ) return _lift ( _isNonRoutableIP , input , _parentContext ) ; return _isNonRoutableIP ( input ) ; } function _isNonRoutableIP ( input , _parentContext ? ) { if ( ! isIP ( input ) ) return false ; return _privateIP ( input ) ; } function _privateIP ( input ) { const parsedIp = _parseIpAddress ( input ) ; const ipRangeName = parsedIp . range ( ) ; return _inPrivateIPRange ( ipRangeName ) || _inRestrictedIPRange ( parsedIp ) ; } function _parseIpAddress ( input ) { const ipv4Regex = /\b((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.|$)){4}\b/ ; const parsed = ipaddr . parse ( input ) ; if ( parsed . kind ( ) === 'ipv6' ) { const ipv4 = input . match ( ipv4Regex ) ; if ( ipv4 != null && Array . isArray ( ipv4 ) ) { return ipaddr . parse ( ipv4 [ 0 ] ) ; } } return parsed ; } function _inPrivateIPRange ( ipRange ) { return [ 'private' , 'uniqueLocal' , 'loopback' , 'unspecified' , 'carrierGradeNat' , 'linkLocal' , 'reserved' , 'rfc6052' , 'teredo' , '6to4' , 'broadcast' ] . includes ( ipRange ) ; } const ipv4RestrictedRanges = [ ipaddr . parseCIDR ( '192.31.196.0/24' ) , ipaddr . parseCIDR ( '192.52.193.0/24' ) , ipaddr . parseCIDR ( '192.175.48.0/24' ) , ipaddr . parseCIDR ( '198.18.0.0/15' ) , ipaddr . parseCIDR ( '224.0.0.0/8' ) ] ; const ipv6RestrictedRanges = [ ipaddr . parseCIDR ( '64:ff9b:1::/48' ) , ipaddr . parseCIDR ( '100::/64' ) , ipaddr . parseCIDR ( '2001::/23' ) , ipaddr . parseCIDR ( '2620:4f:8000::/48' ) ] ; function _inRestrictedIPRange ( parsedIp ) { const rangesToCheck = parsedIp . kind ( ) === 'ipv4' ? ipv4RestrictedRanges : ipv6RestrictedRanges ; return rangesToCheck . some ( ( ipRange ) => parsedIp . match ( ipRange ) ) ; } example param { * } input returns { boolean } export function isCIDR ( input , _parentContext ? ) { if ( ts . isNil ( input ) ) return false ; if ( isArray ( input ) ) return _lift ( _isCidr , input , _parentContext ) ; return _isCidr ( input ) ; } function _isCidr ( input , _parentContext ? ) { if ( ! ts . isString ( input ) ) return false ; return validateCidr ( input ) > 0 ; } example param { * } input param { { min ? : string ; max ? : string ; cidr ? : string } } args returns { boolean } export function inIPRange ( input , _parentContext , args ) { if ( ts . isNil ( input ) ) return false ; if ( isArray ( input ) ) return _lift ( _inIPRange , input , _parentContext , args ) ; return _inIPRange ( input , args ) ; } function _inIPRange ( input , args ) { const MIN_IPV4_IP = '0.0.0.0' ; const MAX_IPV4_IP = '255.255.255.255' ; const MIN_IPV6_IP = '::' ; const MAX_IPV6_IP = 'ffff.ffff.ffff.ffff.ffff.ffff.ffff.ffff' ; if ( ! isIP ( input ) ) return false ; if ( args . cidr ) { if ( ! isCIDR ( args . cidr ) ) return false ; return ip6addr . createCIDR ( args . cidr ) . contains ( input ) ; } let { min , max } = args ; if ( ! min ) min = _isIP . v6 ( input ) ? MIN_IPV6_IP : MIN_IPV4_IP ; if ( ! max ) max = _isIP . v6 ( input ) ? MAX_IPV6_IP : MAX_IPV4_IP ; if ( ! isIP ( min ) || ! isIP ( max ) || _isIP . v6 ( min ) !== _isIP . v6 ( max ) || ip6addr . compare ( max , min ) === - 1 ) { return false ; } return ip6addr . createAddrRange ( min , max ) . contains ( input ) ; } example param { * } input returns { boolean } export function isISDN ( input , _parentContext ? ) { if ( ts . isNil ( input ) ) return false ; if ( isArray ( input ) ) { const fn = ( data ) => { const phoneNumber = new PhoneValidator ( `+${ data }` ) ; return phoneNumber . isValid ( ) ; } ; return _lift ( fn , input , _parentContext ) ; } const phoneNumber = new PhoneValidator ( `+${ input }` ) ; return phoneNumber . isValid ( ) ; } interface MACAddressArgs { delimiter ? : MACDelimiter ; } example param { * } input param { { delimiter } } returns { boolean } export function isMACAddress ( input , _parentContext ? , args ? ) { if ( ts . isNil ( input ) ) return false ; if ( isArray ( input ) ) { return _lift ( ts . isMACAddressFP ( args ?. delimiter ) , input , _parentContext ) ; } return ts . isMACAddress ( input , args ?. delimiter ) ; } example param { number } input param { { min ? : number ; max ? : number ; inclusive ? : boolean } } args returns { boolean } export function inNumberRange ( input , _parentContext , args ) { if ( ts . isNil ( input ) ) return false ; if ( isArray ( input ) ) { return _lift ( ts . inNumberRangeFP ( args ) , input , _parentContext ) ; } return ts . inNumberRange ( input , args ) ; } example param { * } input returns { boolean } export function isNumber ( input , _parentContext ? ) { if ( ts . isNil ( input ) ) return false ; if ( isArray ( input ) ) return _lift ( handleArgs ( ts . isNumber ) , input , _parentContext ) ; return ts . isNumber ( input ) ; } example param { * } input returns { boolean } export function isInteger ( input , _parentContext ? ) { if ( ts . isNil ( input ) ) return false ; if ( isArray ( input ) ) return _lift ( handleArgs ( ts . isInteger ) , input , _parentContext ) ; return ts . isInteger ( input ) ; } example param { * } input export function isString ( input , _parentContext ? ) { if ( ts . isNil ( input ) ) return false ; if ( isArray ( input ) ) return _lift ( handleArgs ( ts . isString ) , input , _parentContext ) ; return ts . isString ( input ) ; } example param { * } input returns { boolean } export function isURL ( input , _parentContext ? ) { if ( ts . isNil ( input ) ) return false ; if ( isArray ( input ) ) { const fn = ( data ) => ts . isString ( data ) && url . isUri ( data ) !== null ; return _lift ( fn , input , _parentContext ) ; } return ts . isString ( input ) && url . isUri ( input ) != null ; } example param { * } input returns { boolean } export function isUUID ( input , _parentContext ? ) { if ( ts . isNil ( input ) ) return false ; if ( isArray ( input ) ) { const fn = ( data ) => ts . isString ( data ) && validator . isUUID ( data ) ; return _lift ( fn , input , _parentContext ) ; } return ts . isString ( input ) && validator . isUUID ( input ) ; } example param { * } input param { { value : string } } returns { boolean } export function contains ( input , _parentContext , args ) { if ( ts . isNil ( input ) ) return false ; if ( ! args . value ) throw new Error ( 'Parameter value must provided' ) ; if ( isArray ( input ) ) { const fn = ( data ) => ts . includes ( data , args . value ) ; return _lift ( fn , input , _parentContext ) ; } return ts . includes ( input , args . value ) ; } example param { * } input param { { value : string } } returns { boolean } export function equals ( input , _parentContext , args ) { if ( ts . isNil ( input ) ) return false ; if ( ! args . value ) throw new Error ( 'A value must provided with the input' ) ; if ( isArray ( input ) ) { const fn = ( data ) => ts . isDeepEqual ( data , args . value ) ; return _lift ( fn , input , _parentContext ) ; } return ts . isDeepEqual ( input , args . value ) ; } example param { * } input param { { locale : validator . AlphaLocale } } args returns { boolean } export function isAlpha ( input , _parentContext ? , args ? ) { if ( ts . isNil ( input ) ) return false ; const locale = args && args . locale ? args . locale : 'en-US' ; if ( isArray ( input ) ) { const fn = ( data ) => ts . isString ( data ) && validator . isAlpha ( data , locale ) ; return _lift ( fn , input , _parentContext ) ; } return ts . isString ( input ) && validator . isAlpha ( input , locale ) ; } example param { * } input param { { locale : validator . AlphanumericLocale } } args returns { boolean } export function isAlphanumeric ( input , _parentContext ? , args ? ) { if ( ts . isNil ( input ) ) return false ; const locale = args && args . locale ? args . locale : 'en-US' ; if ( isArray ( input ) ) { const fn = ( data ) => ts . isString ( data ) && validator . isAlphanumeric ( data , locale ) ; return _lift ( fn , input , _parentContext ) ; } return ts . isString ( input ) && validator . isAlphanumeric ( input , locale ) ; } example param { * } input returns { boolean } export function isASCII ( input , _parentContext ? ) { if ( ts . isNil ( input ) ) return false ; if ( isArray ( input ) ) { const fn = ( data ) => ts . isString ( data ) && validator . isAscii ( data ) ; return _lift ( fn , input , _parentContext ) ; } return ts . isString ( input ) && validator . isAscii ( input ) ; } example param { * } input returns { boolean } export function isBase64 ( input , _parentContext ? ) { if ( ts . isNil ( input ) ) return false ; if ( isArray ( input ) ) { const fn = ( data ) => _validBase64 ( data ) ; return _lift ( fn , input , _parentContext ) ; } return _validBase64 ( input ) ; } function _validBase64 ( input ) { if ( ts . isString ( input ) ) { const validatorValid = validator . isBase64 ( input ) ; if ( validatorValid ) { const decode = Buffer . from ( input , 'base64' ) . toString ( 'utf8' ) ; const encode = Buffer . from ( decode , 'utf8' ) . toString ( 'base64' ) ; return input === encode ; } } return false ; } example param { * } input param { { ignoreWhitespace : boolean } } args returns { boolean } export function isEmpty ( input , _parentContext ? , args ? ) { let value = input ; if ( ! isArray ( value ) && ts . isString ( value ) && args && args . ignoreWhitespace ) { value = value . trim ( ) ; } return ts . isEmpty ( value ) ; } example param { * } input param { args } returns { boolean } export function isFQDN ( input , _parentContext ? , args ? ) { if ( ts . isNil ( input ) ) return false ; const config = { require_tld : args ?. requireTld || true , allow_underscores : args ?. allowUnderscores || false , allow_trailing_dot : args ?. allowTrailingDot || false } ; if ( isArray ( input ) ) { const fn = ( data ) => ts . isString ( data ) && validator . isFQDN ( data , config ) ; return _lift ( fn , input , _parentContext ) ; } return ts . isString ( input ) && validator . isFQDN ( input , config ) ; } example param { * } input param { HashConfig } returns { boolean } export function isHash ( input , _parentContext , args ) { if ( ts . isNil ( input ) ) return false ; if ( args ?. algo === undefined ) throw new Error ( 'Parameter property algo was not provided' ) ; if ( isArray ( input ) ) { const fn = ( data ) => ts . isString ( data ) && validator . isHash ( data , args . algo ) ; return _lift ( fn , input , _parentContext ) ; } return ts . isString ( input ) && validator . isHash ( input , args . algo ) ; } example param { * } input returns { boolean } export function isCountryCode ( input , _parentContext ? ) { if ( ts . isNil ( input ) ) return false ; if ( isArray ( input ) ) { const fn = ( data ) => ts . isString ( data ) && validator . isISO31661Alpha2 ( data ) ; return _lift ( fn , input , _parentContext ) ; } return ts . isString ( input ) && validator . isISO31661Alpha2 ( input ) ; } example param { * } input returns { boolean } export function isISO8601 ( input , _parentContext ? ) { if ( ts . isNil ( input ) ) return false ; if ( isArray ( input ) ) { const fn = ( data ) => ts . isString ( data ) && validator . isISO8601 ( data ) ; return _lift ( fn , input , _parentContext ) ; } return ts . isString ( input ) && validator . isISO8601 ( input ) ; } example param { * } input param { ArgsISSNOptions } returns { boolean } export function isISSN ( input , _parentContext ? , args ? ) { if ( ts . isNil ( input ) ) return false ; const config = { case_sensitive : args ?. caseSensitive || false , require_hyphen : args ?. requireHyphen || false } ; if ( isArray ( input ) ) { const fn = ( data ) => ts . isString ( data ) && validator . isISSN ( data , config ) ; return _lift ( fn , input , _parentContext ) ; } return ts . isString ( input ) && validator . isISSN ( input , config ) ; } example param { * } input returns { boolean } export function isRFC3339 ( input , _parentContext ? ) { if ( ts . isNil ( input ) ) return false ; if ( isArray ( input ) ) { const fn = ( data ) => ts . isString ( data ) && validator . isRFC3339 ( data ) ; return _lift ( fn , input , _parentContext ) ; } return ts . isString ( input ) && validator . isRFC3339 ( input ) ; } example param { * } input returns { boolean } export function isJSON ( input , _parentContext ? ) { if ( ts . isNil ( input ) ) return false ; if ( isArray ( input ) ) { const fn = ( data ) => ts . isString ( data ) && validator . isJSON ( data ) ; return _lift ( fn , input , _parentContext ) ; } return ts . isString ( input ) && validator . isJSON ( input ) ; } example param { * } input param { LengthConfig } returns { boolean } export function isLength ( input , _parentContext , { size , min , max } ) { if ( ts . isNil ( input ) ) return false ; if ( isArray ( input ) ) { const fn = ( data ) => { if ( size ) return ts . isString ( data ) && data . length === size ; if ( min || max ) return validator . isLength ( data , { min , max } ) ; return false ; } ; return _lift ( fn , input , _parentContext ) ; } if ( isString ( input ) ) { if ( size ) return input . length === size ; if ( min || max ) return validator . isLength ( input , { min , max } ) ; } return false ; } example param { * } input returns { boolean } export function isMIMEType ( input , _parentContext ? ) { if ( ts . isNil ( input ) ) return false ; if ( isArray ( input ) ) { const fn = ( data ) => ts . isString ( data ) && validator . isMimeType ( data ) ; return _lift ( fn , input , _parentContext ) ; } return ts . isString ( input ) && validator . isMimeType ( input ) ; } example param { * } input param { ( { locale : 'any' | PostalCodeLocale } ) } returns { boolean } export function isPostalCode ( input , _parentContext , args ) { if ( ts . isNil ( input ) ) return false ; if ( ! args ?. locale ) throw new Error ( 'Invalid parameter locale, must provide an object with locale' ) ; if ( isArray ( input ) ) { const fn = ( data ) => ts . isString ( data ) && validator . isPostalCode ( data , args . locale ) ; return _lift ( fn , input , _parentContext ) ; } return ts . isString ( input ) && validator . isPostalCode ( input , args . locale ) ; } example param { * } input returns { boolean } export function isValidDate ( input , _parentContext ? ) { if ( ts . isNil ( input ) ) return false ; if ( isArray ( input ) ) { return _lift ( handleArgs ( ts . isValidDate ) , input , _parentContext ) ; } return ! ts . isBoolean ( input as any ) && ts . isValidDate ( input ) ; } example param { * } input returns { boolean } export function guard ( input , _parentContext ? ) { if ( ts . isNil ( input ) ) throw new Error ( 'Expected value not to be empty' ) ; return true ; } example param { * } input returns { boolean } export function exists ( input , _parentContext ? ) { return ts . isNotNil ( input ) ; } example param { * } input returns { boolean } export function isArray ( input , _parentContext ? ) { return ts . isArrayLike ( input ) ; } example param { * } input param { { fn : string ; options ? : any } } returns { boolean } export function some ( input , _parentContext , { fn , options } ) { if ( ! isArray ( input ) ) return false ; const repoConfig = repository [ fn ] ; if ( ! repoConfig ) throw new Error ( `No function ${ fn } was found in the field validator repository` ) ; return input . some ( ( data ) => repoConfig . fn ( data , data , options ) ) ; } example param { * } input param { { fn : string ; options ? : any } } returns { boolean } export function every ( input , _parentContext , { fn , options } ) { if ( ! isArray ( input ) ) return false ; const repoConfig = repository [ fn ] ; if ( ! repoConfig ) throw new Error ( `No function ${ fn } was found in the field validator repository` ) ; return input . every ( ( data ) => repoConfig . fn ( data , data , options ) ) ; } export function isNumberTuple ( input , _parentContext ? ) { if ( Array . isArray ( input ) && input . length === 2 ) { return input . every ( isNumber ) ; } return false ; }