@natch-the-storage/heathershaw-platform-types 1.18.13 → 1.18.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/validators.d.ts +15 -0
- package/build/validators.js +31 -0
- package/package.json +1 -1
package/build/validators.d.ts
CHANGED
|
@@ -83,12 +83,27 @@ export declare function getCurrentIsoTimestamp(): string;
|
|
|
83
83
|
* @returns
|
|
84
84
|
*/
|
|
85
85
|
export declare function formatDate(dateStr?: string | null, toDmy?: boolean): string;
|
|
86
|
+
/**
|
|
87
|
+
* Formats a date into a readable format
|
|
88
|
+
* @param date typically in ISO format - (yyyy-mm-ddThh:mm:sszz)
|
|
89
|
+
* @param time adds the time to the string
|
|
90
|
+
* @param toDmy format the date as dd/mm/yyyy instead
|
|
91
|
+
* @returns
|
|
92
|
+
*/
|
|
93
|
+
export declare function formatIsoTimestamp({ date, time, toDmy, }: {
|
|
94
|
+
date: string;
|
|
95
|
+
time?: boolean;
|
|
96
|
+
toDmy?: boolean;
|
|
97
|
+
}): string;
|
|
86
98
|
/**
|
|
87
99
|
* Gets the age in years based on todays date vs the date of birth
|
|
88
100
|
* @param dateOfBirth An isoDate (yyyy-mm-dd) string
|
|
89
101
|
* @returns The age in years
|
|
90
102
|
*/
|
|
91
103
|
export declare function getAge(dateOfBirth: string): number;
|
|
104
|
+
/**
|
|
105
|
+
* Formats an address object into a human readable format
|
|
106
|
+
*/
|
|
92
107
|
export declare function formatAddress(addr: Address): string;
|
|
93
108
|
export interface Address {
|
|
94
109
|
street: string;
|
package/build/validators.js
CHANGED
|
@@ -243,6 +243,34 @@ export function formatDate(dateStr, toDmy) {
|
|
|
243
243
|
year: 'numeric',
|
|
244
244
|
});
|
|
245
245
|
}
|
|
246
|
+
/**
|
|
247
|
+
* Formats a date into a readable format
|
|
248
|
+
* @param date typically in ISO format - (yyyy-mm-ddThh:mm:sszz)
|
|
249
|
+
* @param time adds the time to the string
|
|
250
|
+
* @param toDmy format the date as dd/mm/yyyy instead
|
|
251
|
+
* @returns
|
|
252
|
+
*/
|
|
253
|
+
export function formatIsoTimestamp({ date, time, toDmy, }) {
|
|
254
|
+
const d = new Date(date);
|
|
255
|
+
if (toDmy) {
|
|
256
|
+
return d.toLocaleDateString('en-AU', {
|
|
257
|
+
day: '2-digit',
|
|
258
|
+
month: '2-digit',
|
|
259
|
+
year: 'numeric',
|
|
260
|
+
hour: time ? '2-digit' : undefined,
|
|
261
|
+
minute: time ? '2-digit' : undefined,
|
|
262
|
+
timeZone: '+11',
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
return d.toLocaleDateString('en-AU', {
|
|
266
|
+
day: '2-digit',
|
|
267
|
+
month: 'short',
|
|
268
|
+
year: 'numeric',
|
|
269
|
+
hour: time ? '2-digit' : undefined,
|
|
270
|
+
minute: time ? '2-digit' : undefined,
|
|
271
|
+
timeZone: '+11',
|
|
272
|
+
});
|
|
273
|
+
}
|
|
246
274
|
/**
|
|
247
275
|
* Gets the age in years based on todays date vs the date of birth
|
|
248
276
|
* @param dateOfBirth An isoDate (yyyy-mm-dd) string
|
|
@@ -258,6 +286,9 @@ export function getAge(dateOfBirth) {
|
|
|
258
286
|
age -= 1;
|
|
259
287
|
return age;
|
|
260
288
|
}
|
|
289
|
+
/**
|
|
290
|
+
* Formats an address object into a human readable format
|
|
291
|
+
*/
|
|
261
292
|
export function formatAddress(addr) {
|
|
262
293
|
return `${addr.street}, ${addr.suburb} ${addr.state} ${addr.postcode}`;
|
|
263
294
|
}
|