@openmrs/esm-utils 9.0.3-pre.4181 → 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.
@@ -1,3 +1,3 @@
1
- [0] Successfully compiled: 12 files with swc (143.67ms)
1
+ [0] Successfully compiled: 13 files with swc (177.11ms)
2
2
  [0] swc --strip-leading-paths src -d dist exited with code 0
3
3
  [1] tsc --project tsconfig.build.json exited with code 0
@@ -1 +1 @@
1
- {"version":3,"file":"age-helpers.d.ts","sourceRoot":"","sources":["../src/age-helpers.ts"],"names":[],"mappings":"AAIA,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"}
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"}
@@ -1,5 +1,4 @@
1
- /** @module @category Utility */ import { DurationFormat } from "@formatjs/intl-durationformat";
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;AASjC,OAAO,KAAK,EAAE,qBAAqB,EAAE,aAAa,EAAE,MAAM,yCAAyC,CAAC;AAMpG,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;AAI/C;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,iBAAiB,EAAE,MAAM,GAAG,OAAO,CAuBnE;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,SAAS,WAE9C;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,cAAc,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAMtE;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,SAAS,EAAE,KAAK,UAAQ,GAAG,MAAM,CAQtE;AAED;;;GAGG;AACH,wBAAgB,SAAS,CAAC,UAAU,EAAE,MAAM,QAE3C;AA6CD;;;;;;;;;;GAUG;AACH,wBAAgB,uBAAuB,CAA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
  * @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
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,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"}
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
@@ -1,3 +1,4 @@
1
+ /// <reference path="./intl-durationformat.d.ts" />
1
2
  export * from "./age-helpers.js";
2
3
  export * from "./dates/index.js";
3
4
  export * from "./get-locale.js";
@@ -0,0 +1,3 @@
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/
package/mock-jest.ts ADDED
@@ -0,0 +1,2 @@
1
+ import '@formatjs/intl-durationformat/polyfill';
2
+ export * from './src/index';
package/mock.ts ADDED
@@ -0,0 +1,2 @@
1
+ import '@formatjs/intl-durationformat/polyfill';
2
+ export * from './src/index';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openmrs/esm-utils",
3
- "version": "9.0.3-pre.4181",
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.4181",
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
@@ -0,0 +1,2 @@
1
+ // happy-dom doesn't have Intl.DurationFormat, so we unconditionally load the polyfill for tests
2
+ import '@formatjs/intl-durationformat/polyfill';
@@ -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
  }
@@ -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
@@ -1,3 +1,4 @@
1
+ /// <reference path="./intl-durationformat.d.ts" />
1
2
  export * from './age-helpers';
2
3
  export * from './dates';
3
4
  export * from './get-locale';
@@ -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
+ }
package/vitest.config.ts CHANGED
@@ -4,5 +4,6 @@ export default defineConfig({
4
4
  test: {
5
5
  environment: 'happy-dom',
6
6
  mockReset: true,
7
+ setupFiles: ['./setup-tests.ts'],
7
8
  },
8
9
  });