@@ -57,14 +57,16 @@ export type Duration = { type: 'duration'; value: any; }
57
57
export type Binary = { type : 'binary' ; value : any ; }
58
58
export type Json = { type : 'json' ; value : any ; }
59
59
export type Alias = { type : 'alias' ; name : string ; value : any ; }
60
- export type Value = string | Date | number | boolean | Raw | Guid | Duration | Binary | Json | Alias ;
60
+ export type Decimal = { type : 'decimal' ; value : any ; }
61
+ export type Value = string | Date | number | boolean | Raw | Guid | Duration | Binary | Json | Alias | Decimal ;
61
62
62
63
export const raw = ( value : string ) : Raw => ( { type : 'raw' , value } ) ;
63
64
export const guid = ( value : string ) : Guid => ( { type : 'guid' , value } ) ;
64
65
export const duration = ( value : string ) : Duration => ( { type : 'duration' , value } ) ;
65
66
export const binary = ( value : string ) : Binary => ( { type : 'binary' , value } ) ;
66
67
export const json = ( value : PlainObject ) : Json => ( { type : 'json' , value } ) ;
67
68
export const alias = ( name : string , value : PlainObject ) : Alias => ( { type : 'alias' , name, value } ) ;
69
+ export const decimal = ( value : string ) : Decimal => ( { type : 'decimal' , value } ) ;
68
70
69
71
export type QueryOptions < T > = ExpandOptions < T > & {
70
72
search : string ;
@@ -363,36 +365,38 @@ function handleValue(value: Value, aliases?: Alias[]): any {
363
365
return value . toISOString ( ) ;
364
366
} else if ( typeof value === 'number' ) {
365
367
// Number.isInteger(value) is not supported by IE11
366
- const isDecimal = value % 1 !== 0 ;
367
- return isDecimal ? `${ value } M ` : value ;
368
+ const isDouble = value % 1 !== 0 ;
369
+ return isDouble ? `${ value } d ` : value ;
368
370
} else if ( Array . isArray ( value ) ) {
369
371
return `[${ value . map ( d => handleValue ( d ) ) . join ( ',' ) } ]` ;
370
372
} else if ( value === null ) {
371
373
return value ;
372
374
} else if ( typeof value === 'object' ) {
373
- if ( value . type === 'raw' ) {
374
- return value . value ;
375
- } else if ( value . type === 'guid' ) {
375
+ switch ( value . type ) {
376
+ case 'raw' :
377
+ case 'guid' :
376
378
return value . value ;
377
- } else if ( value . type === 'duration' ) {
379
+ case 'duration' :
378
380
return `duration'${ value . value } '` ;
379
- } else if ( value . type === 'binary' ) {
381
+ case 'binary' :
380
382
return `binary'${ value . value } '` ;
381
- } else if ( value . type === 'alias' ) {
382
- // Store
383
- if ( Array . isArray ( aliases ) )
384
- aliases . push ( value as Alias ) ;
385
- return `@${ ( value as Alias ) . name } ` ;
386
- } else if ( value . type === 'json' ) {
383
+ case 'alias' :
384
+ // Store
385
+ if ( Array . isArray ( aliases ) )
386
+ aliases . push ( value as Alias ) ;
387
+ return `@${ ( value as Alias ) . name } ` ;
388
+ case 'json' :
387
389
return escape ( JSON . stringify ( value . value ) ) ;
388
- } else {
389
- return Object . entries ( value )
390
- . filter ( ( [ , v ] ) => v !== undefined )
391
- . map ( ( [ k , v ] ) => `${ k } =${ handleValue ( v as Value , aliases ) } ` ) . join ( ',' ) ;
392
- }
390
+ case 'decimal' :
391
+ return `${ value . value } M` ;
392
+ default :
393
+ return Object . entries ( value )
394
+ . filter ( ( [ , v ] ) => v !== undefined )
395
+ . map ( ( [ k , v ] ) => `${ k } =${ handleValue ( v as Value , aliases ) } ` ) . join ( ',' ) ;
393
396
}
394
- return value ;
395
397
}
398
+ return value ;
399
+ }
396
400
397
401
function buildExpand < T > ( expands : Expand < T > ) : string {
398
402
if ( typeof expands === 'number' ) {
0 commit comments