This repository has been archived by the owner on Mar 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
computed-macros.ts
81 lines (72 loc) · 2.64 KB
/
computed-macros.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import type { ParseOptions } from './parser';
import { computed, get } from '@ember/object';
import {
toBigEndianDateString,
toMiddleEndianDateString,
toMiddleEndianTimeString,
toMiddleEndianDateTimeString,
} from './formatters';
/**
* Exposes the `toMiddleEndianDateString` formatter as an Ember computed decorator to format
* a date-like value as "MONTH/DAY/YEAR".
*
* ```javascript
* public dateValue: new Date(1970, 9, 25, 13, 10, 50);
*
* @middleEndianDateString('dateValue');
* public formattedDate!: string; // => '10/25/1970'
* ```
*/
export function middleEndianDateString(dependantKey: string, defaultValue: any = 'None', options: ParseOptions = {}) {
return computed(dependantKey, function computedMiddleEndianDateString() {
return toMiddleEndianDateString(get(this, dependantKey), defaultValue, options);
});
}
/**
* Exposes the `middleEndianTimeString` formatter as an Ember computed decorator to format
* a date-like value as "HOUR:MINUTE MERIDIEM".
*
* ```javascript
* public dateValue: new Date(1970, 9, 25, 13, 10, 50);
*
* @middleEndianTimeString('dateValue');
* public formattedTime!: string; // => '1:10 PM'
* ```
*/
export function middleEndianTimeString(dependantKey: string, defaultValue: any = 'None', options: ParseOptions = {}) {
return computed(dependantKey, function computedMiddleEndianTimeString() {
return toMiddleEndianTimeString(get(this, dependantKey), defaultValue, options);
});
}
/**
* Exposes the `middleEndianDateTimeString` formatter as an Ember computed decorator to format
* a date-like value as "MONTH/DAY/YEAR HOUR:MINUTE MERIDIEM".
*
* ```javascript
* public dateValue: new Date(1970, 9, 25, 13, 10, 50);
*
* @middleEndianDateTimeString('dateValue');
* public formattedDateTime!: string; // => '10/25/1970 1:10 PM'
* ```
*/
export function middleEndianDateTimeString(dependantKey: string, defaultValue: any = 'None', options: ParseOptions = {}) {
return computed(dependantKey, function computedMiddleEndianDateTimeString() {
return toMiddleEndianDateTimeString(get(this, dependantKey), defaultValue, options);
});
}
/**
* Exposes the `bigEndianDateString` formatter as an Ember computed decorator to format
* a date-like value as "YEAR-MONTH-DAY".
*
* ```javascript
* public dateValue: new Date(1970, 9, 25, 13, 10, 50);
*
* @bigEndianDateString('dateValue');
* public formattedDate!: string; // => '1970-10-25'
* ```
*/
export function bigEndianDateString(dependantKey: string, defaultValue: any = 'None', options: ParseOptions = {}) {
return computed(dependantKey, function computedBigEndianDateString() {
return toBigEndianDateString(get(this, dependantKey), defaultValue, options);
});
}