@openmrs/esm-utils 9.0.3-pre.4178 → 9.0.3-pre.4195
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/.turbo/turbo-build.log +1 -1
- package/dist/age-helpers.d.ts.map +1 -1
- package/dist/age-helpers.js +2 -3
- package/dist/dates/date-util.d.ts +1 -2
- package/dist/dates/date-util.d.ts.map +1 -1
- package/dist/dates/date-util.js +1 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/intl-durationformat.d.js +3 -0
- package/mock-jest.ts +2 -0
- package/mock.ts +2 -0
- package/package.json +6 -2
- package/setup-tests.ts +2 -0
- package/src/age-helpers.ts +3 -5
- package/src/dates/date-util.ts +2 -4
- package/src/index.ts +1 -0
- package/src/intl-durationformat.d.ts +64 -0
- package/vitest.config.ts +1 -0
package/.turbo/turbo-build.log
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"age-helpers.d.ts","sourceRoot":"","sources":["../src/age-helpers.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"age-helpers.d.ts","sourceRoot":"","sources":["../src/age-helpers.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,MAAM,OAAO,CAAC;AAO1B;;;;;;;;;GASG;AACH,wBAAgB,GAAG,CAAC,SAAS,EAAE,KAAK,CAAC,UAAU,EAAE,WAAW,GAAE,KAAK,CAAC,UAAoB,GAAG,MAAM,GAAG,IAAI,CAyEvG"}
|
package/dist/age-helpers.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
/** @module @category Utility */ import {
|
|
2
|
-
import { attempt } from "any-date-parser";
|
|
1
|
+
/** @module @category Utility */ import { attempt } from "any-date-parser";
|
|
3
2
|
import dayjs from "dayjs";
|
|
4
3
|
import objectSupport from "dayjs/plugin/objectSupport.js";
|
|
5
4
|
import { omit } from "lodash-es";
|
|
@@ -82,5 +81,5 @@ dayjs.extend(objectSupport);
|
|
|
82
81
|
} else {
|
|
83
82
|
duration['years'] = yearDiff;
|
|
84
83
|
}
|
|
85
|
-
return new DurationFormat(locale, options).format(duration);
|
|
84
|
+
return new Intl.DurationFormat(locale, options).format(duration);
|
|
86
85
|
}
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
* @category Date and Time
|
|
4
4
|
*/
|
|
5
5
|
import { type CalendarDate, type CalendarDateTime, type CalendarIdentifier, type ZonedDateTime } from '@internationalized/date';
|
|
6
|
-
import type { DurationFormatOptions, DurationInput } from '@formatjs/intl-durationformat/src/types';
|
|
7
6
|
export type DateInput = string | number | Date;
|
|
8
7
|
/**
|
|
9
8
|
* This function checks whether a date string is the OpenMRS ISO format.
|
|
@@ -167,5 +166,5 @@ export declare function convertToLocaleCalendar(date: CalendarDate | CalendarDat
|
|
|
167
166
|
* @param options Optional options for formatting.
|
|
168
167
|
* @returns The formatted duration string.
|
|
169
168
|
*/
|
|
170
|
-
export declare function formatDuration(duration: DurationInput, options?: DurationFormatOptions): string;
|
|
169
|
+
export declare function formatDuration(duration: Intl.DurationInput, options?: Intl.DurationFormatOptions): string;
|
|
171
170
|
//# sourceMappingURL=date-util.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"date-util.d.ts","sourceRoot":"","sources":["../../src/dates/date-util.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,gBAAgB,EACrB,KAAK,kBAAkB,EACvB,KAAK,aAAa,EAGnB,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"date-util.d.ts","sourceRoot":"","sources":["../../src/dates/date-util.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,gBAAgB,EACrB,KAAK,kBAAkB,EACvB,KAAK,aAAa,EAGnB,MAAM,yBAAyB,CAAC;AAajC,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,MAAM,GAAG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AAE,MAAM,EAAE,OAAO,GAAE,OAAO,CAAC,iBAAiB,CAAM,iBAuC7F;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,wBAAgB,UAAU,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,EAAE,OAAO,CAAC,iBAAiB,CAAC,UAkE1E;AAiBD;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,IAAI,UAKpC;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,EAAE,OAAO,CAAC,IAAI,CAAC,iBAAiB,EAAE,MAAM,CAAC,CAAC,UAE5F;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,CACrC,IAAI,EAAE,YAAY,GAAG,gBAAgB,GAAG,aAAa,EACrD,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC,MAAM,mDAM7B;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,IAAI,CAAC,aAAa,EAAE,OAAO,CAAC,EAAE,IAAI,CAAC,qBAAqB,UAGhG"}
|
package/dist/dates/date-util.js
CHANGED
|
@@ -27,7 +27,6 @@ function _class_private_field_init(obj, privateMap, value) {
|
|
|
27
27
|
* @module
|
|
28
28
|
* @category Date and Time
|
|
29
29
|
*/ import { createCalendar, toCalendar } from "@internationalized/date";
|
|
30
|
-
import { DurationFormat } from "@formatjs/intl-durationformat";
|
|
31
30
|
import { attempt } from "any-date-parser";
|
|
32
31
|
import dayjs from "dayjs";
|
|
33
32
|
import isToday from "dayjs/plugin/isToday.js";
|
|
@@ -358,6 +357,6 @@ const formatParts = (separator)=>{
|
|
|
358
357
|
* @param options Optional options for formatting.
|
|
359
358
|
* @returns The formatted duration string.
|
|
360
359
|
*/ export function formatDuration(duration, options) {
|
|
361
|
-
const formatter = new DurationFormat(getLocale(), options);
|
|
360
|
+
const formatter = new Intl.DurationFormat(getLocale(), options);
|
|
362
361
|
return formatter.format(duration);
|
|
363
362
|
}
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,eAAe,CAAC;AAC9B,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC"}
|
package/dist/index.js
CHANGED
package/mock-jest.ts
ADDED
package/mock.ts
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openmrs/esm-utils",
|
|
3
|
-
"version": "9.0.3-pre.
|
|
3
|
+
"version": "9.0.3-pre.4195",
|
|
4
4
|
"license": "MPL-2.0",
|
|
5
5
|
"description": "Helper utilities for OpenMRS",
|
|
6
6
|
"type": "module",
|
|
@@ -10,6 +10,10 @@
|
|
|
10
10
|
".": {
|
|
11
11
|
"types": "./src/index.ts",
|
|
12
12
|
"default": "./dist/index.js"
|
|
13
|
+
},
|
|
14
|
+
"./mock": {
|
|
15
|
+
"import": "./mock.ts",
|
|
16
|
+
"require": "./mock-jest.ts"
|
|
13
17
|
}
|
|
14
18
|
},
|
|
15
19
|
"source": true,
|
|
@@ -59,7 +63,7 @@
|
|
|
59
63
|
"rxjs": "6.x"
|
|
60
64
|
},
|
|
61
65
|
"devDependencies": {
|
|
62
|
-
"@openmrs/esm-globals": "9.0.3-pre.
|
|
66
|
+
"@openmrs/esm-globals": "9.0.3-pre.4195",
|
|
63
67
|
"@swc/cli": "0.8.0",
|
|
64
68
|
"@swc/core": "1.15.18",
|
|
65
69
|
"@types/lodash-es": "^4.17.12",
|
package/setup-tests.ts
ADDED
package/src/age-helpers.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
/** @module @category Utility */
|
|
2
|
-
import { DurationFormat } from '@formatjs/intl-durationformat';
|
|
3
|
-
import { type DurationFormatOptions, type DurationInput } from '@formatjs/intl-durationformat/src/types';
|
|
4
2
|
import { attempt } from 'any-date-parser';
|
|
5
3
|
import dayjs from 'dayjs';
|
|
6
4
|
import objectSupport from 'dayjs/plugin/objectSupport.js';
|
|
@@ -62,8 +60,8 @@ export function age(birthDate: dayjs.ConfigType, currentDate: dayjs.ConfigType =
|
|
|
62
60
|
const monthDiff = to.diff(from, 'months');
|
|
63
61
|
const yearDiff = to.diff(from, 'years');
|
|
64
62
|
|
|
65
|
-
const duration: DurationInput = {};
|
|
66
|
-
const options: DurationFormatOptions = { style: 'short', localeMatcher: 'lookup' };
|
|
63
|
+
const duration: Intl.DurationInput = {};
|
|
64
|
+
const options: Intl.DurationFormatOptions = { style: 'short', localeMatcher: 'lookup' };
|
|
67
65
|
|
|
68
66
|
if (hourDiff < 2) {
|
|
69
67
|
const minuteDiff = to.diff(from, 'minutes');
|
|
@@ -91,5 +89,5 @@ export function age(birthDate: dayjs.ConfigType, currentDate: dayjs.ConfigType =
|
|
|
91
89
|
duration['years'] = yearDiff;
|
|
92
90
|
}
|
|
93
91
|
|
|
94
|
-
return new DurationFormat(locale, options).format(duration);
|
|
92
|
+
return new Intl.DurationFormat(locale, options).format(duration);
|
|
95
93
|
}
|
package/src/dates/date-util.ts
CHANGED
|
@@ -10,7 +10,6 @@ import {
|
|
|
10
10
|
createCalendar,
|
|
11
11
|
toCalendar,
|
|
12
12
|
} from '@internationalized/date';
|
|
13
|
-
import { DurationFormat } from '@formatjs/intl-durationformat';
|
|
14
13
|
import { attempt } from 'any-date-parser';
|
|
15
14
|
import dayjs from 'dayjs';
|
|
16
15
|
import isToday from 'dayjs/plugin/isToday.js';
|
|
@@ -18,7 +17,6 @@ import objectSupport from 'dayjs/plugin/objectSupport.js';
|
|
|
18
17
|
import utc from 'dayjs/plugin/utc.js';
|
|
19
18
|
import { isNil, omit } from 'lodash-es';
|
|
20
19
|
import { getLocale } from '../';
|
|
21
|
-
import type { DurationFormatOptions, DurationInput } from '@formatjs/intl-durationformat/src/types';
|
|
22
20
|
|
|
23
21
|
dayjs.extend(isToday);
|
|
24
22
|
dayjs.extend(utc);
|
|
@@ -440,7 +438,7 @@ export function convertToLocaleCalendar(
|
|
|
440
438
|
* @param options Optional options for formatting.
|
|
441
439
|
* @returns The formatted duration string.
|
|
442
440
|
*/
|
|
443
|
-
export function formatDuration(duration: DurationInput, options?: DurationFormatOptions) {
|
|
444
|
-
const formatter = new DurationFormat(getLocale(), options);
|
|
441
|
+
export function formatDuration(duration: Intl.DurationInput, options?: Intl.DurationFormatOptions) {
|
|
442
|
+
const formatter = new Intl.DurationFormat(getLocale(), options);
|
|
445
443
|
return formatter.format(duration);
|
|
446
444
|
}
|
package/src/index.ts
CHANGED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// Ambient type declarations for Intl.DurationFormat (TC39 Stage 3 proposal).
|
|
2
|
+
// Can be removed once TypeScript ships built-in types for Intl.DurationFormat.
|
|
3
|
+
// Reference: https://tc39.es/proposal-intl-duration-format/
|
|
4
|
+
|
|
5
|
+
declare namespace Intl {
|
|
6
|
+
interface ResolvedDurationFormatOptions {
|
|
7
|
+
localeMatcher: 'best fit' | 'lookup';
|
|
8
|
+
style: 'long' | 'short' | 'narrow' | 'digital';
|
|
9
|
+
years: 'long' | 'short' | 'narrow';
|
|
10
|
+
yearsDisplay: 'always' | 'auto';
|
|
11
|
+
months: 'long' | 'short' | 'narrow';
|
|
12
|
+
monthsDisplay: 'always' | 'auto';
|
|
13
|
+
weeks: 'long' | 'short' | 'narrow';
|
|
14
|
+
weeksDisplay: 'always' | 'auto';
|
|
15
|
+
days: 'long' | 'short' | 'narrow';
|
|
16
|
+
daysDisplay: 'always' | 'auto';
|
|
17
|
+
hours: 'long' | 'short' | 'narrow' | 'numeric';
|
|
18
|
+
hoursDisplay: 'always' | 'auto';
|
|
19
|
+
minutes: 'long' | 'short' | 'narrow' | 'numeric' | '2-digit';
|
|
20
|
+
minutesDisplay: 'always' | 'auto';
|
|
21
|
+
seconds: 'long' | 'short' | 'narrow' | 'numeric' | '2-digit';
|
|
22
|
+
secondsDisplay: 'always' | 'auto';
|
|
23
|
+
milliseconds: 'long' | 'short' | 'narrow' | 'numeric';
|
|
24
|
+
millisecondsDisplay: 'always' | 'auto';
|
|
25
|
+
microseconds: 'long' | 'short' | 'narrow' | 'numeric';
|
|
26
|
+
microsecondsDisplay: 'always' | 'auto';
|
|
27
|
+
nanoseconds: 'long' | 'short' | 'narrow' | 'numeric';
|
|
28
|
+
nanosecondsDisplay: 'always' | 'auto';
|
|
29
|
+
fractionalDigits?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
|
|
30
|
+
numberingSystem: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
type DurationFormatOptions = Partial<ResolvedDurationFormatOptions>;
|
|
34
|
+
|
|
35
|
+
interface DurationInput {
|
|
36
|
+
years?: number;
|
|
37
|
+
months?: number;
|
|
38
|
+
weeks?: number;
|
|
39
|
+
days?: number;
|
|
40
|
+
hours?: number;
|
|
41
|
+
minutes?: number;
|
|
42
|
+
seconds?: number;
|
|
43
|
+
milliseconds?: number;
|
|
44
|
+
microseconds?: number;
|
|
45
|
+
nanoseconds?: number;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
interface DurationFormatPart {
|
|
49
|
+
unit?: string;
|
|
50
|
+
type: string;
|
|
51
|
+
value: string;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
class DurationFormat {
|
|
55
|
+
constructor(locales?: string | string[], options?: DurationFormatOptions);
|
|
56
|
+
format(duration: DurationInput): string;
|
|
57
|
+
formatToParts(duration: DurationInput): DurationFormatPart[];
|
|
58
|
+
resolvedOptions(): ResolvedDurationFormatOptions;
|
|
59
|
+
static supportedLocalesOf(
|
|
60
|
+
locales: string | string[],
|
|
61
|
+
options?: Pick<DurationFormatOptions, 'localeMatcher'>,
|
|
62
|
+
): string[];
|
|
63
|
+
}
|
|
64
|
+
}
|