import 'reflect-metadata' ; import { PropertyRef } from '.' ; import { getPropertyKey } from './widgets' ; import { Exclude } from "class-transformer" ; export function key ( propertyAccess ) { return ( "" + propertyAccess ) . match ( /\.([a-zA-Z_$][0-9a-zA-Z_$]*)[^\.]*$/ ) ! [ 1 ] ; } export function equalsIgnoreCase ( a , b ) { if ( a == b ) return true ; if ( a == null || b == null ) return false ; return a . toLowerCase ( ) == b . toLowerCase ( ) ; } export function fuzzyEquals ( x , y ) { return ( x == y || isNullOrEmpty ( x ) && isNullOrEmpty ( y ) || ( typeof ( x ) == "string" && typeof ( y ) == "string" && ( parseFloat ( x ) == parseFloat ( y ) ) ) ) ; } export const parseFloatDeNaN = ( s ) => Let ( parseFloat ( s ) , n => isNaN ( n ) ? undefined : n ) ; export function literal ( html ) { return ( element ) => { element . innerHTML = html ; } ; } export function Let < T , U > ( obj , op ) { return op ( obj ) ; } export function isNullOrEmpty ( s ? ) { return s == null || s === '' ; } /** Decorate for properties that are not part of your domain model and should not be serialized.  */ export function transient ( target , propertyKey ) { Reflect . metadata ( "transient" , true ) ( target , propertyKey ) ; Exclude ( ) ( target , propertyKey ) ; } export function isTransient ( target , propertyKey ) { return Reflect . getMetadata ( "transient" , target , propertyKey ) ; } export function Label ( s ) { return Reflect . metadata ( "label" , s ) ; } export function getLabel ( target , propertyKey ) { return Reflect . getMetadata ( "label" , target , propertyKey ) as string | undefined ; } export const humanizeIdentifier = ( str ) => str . replace ( /[a-z][A-Z]/g , x => "" + x [ 0 ] + " " + x [ 1 ] ) . replace ( /_[a-z]/g , x => " " + x . slice ( 1 ) . toUpperCase ( ) ) . replace ( /^./ , x => x . toUpperCase ( ) ) ;