import { instanceToPlain , Exclude , Expose } from 'class-transformer' ; import type { ClassTransformOptions } from 'class-transformer' ; import type { LocationInterface } from '../interface' ; @ Exclude ( ) export class Location < ProviderRawEntryType = any > implements LocationInterface < ProviderRawEntryType > { @ Expose ( ) provider : string ; example example @ Expose ( { name : 'formattedAddress' , toClassOnly : true } ) formattedAddress ? : string ; @ Expose ( ) latitude : number ; @ Expose ( ) longitude : number ; @ Expose ( ) country ? : string ; @ Expose ( ) countryCode ? : string ; @ Expose ( ) state ? : string ; /**
     * can be as ISO 3166-1 alpha-2 or an arbitrary string for countries that have no states
     */ @ Expose ( ) stateCode ? : string ; @ Expose ( ) city ? : string ; @ Expose ( ) postalCode ? : string ; @ Expose ( ) streetName ? : string ; @ Expose ( ) houseNumber ? : string ; @ Expose ( ) placeId ? : string ; @ Expose ( { groups : [ 'raw' , 'all' ] } ) raw ? : ProviderRawEntryType ; get street ( ) : string { return `${ this . houseNumber || '' } ${ this . streetName || '' }` . trim ( ) ; } @ Expose ( { name : 'formattedAddress' , toPlainOnly : true } ) generateFormattedAddress ( ) { return this . formattedAddress ? this . formattedAddress : [ this . street || '' , this . city || '' , `${ this . stateCode || this . state || '' } ${ this . postalCode || '' }` . trim ( ) , this . country || this . countryCode || '' , ] . filter ( Boolean ) . join ( ', ' ) ; } toObject ( options ? ) { return instanceToPlain < Location < ProviderRawEntryType > > ( this , options ) as LocationInterface < ProviderRawEntryType > ; } }