@openmrs/esm-utils 8.0.1-pre.3783 → 8.0.1-pre.3786

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 (196.23ms)
1
+ [0] Successfully compiled: 12 files with swc (146.23ms)
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
@@ -11,8 +11,10 @@ export type DateInput = string | number | Date;
11
11
  */
12
12
  export declare function isOmrsDateStrict(omrsPayloadString: string): boolean;
13
13
  /**
14
+ * Checks if the provided date is today.
14
15
  *
15
- * @param date Checks if the provided date is today.
16
+ * @param date The date to check.
17
+ * @returns `true` if the date is today, `false` otherwise.
16
18
  */
17
19
  export declare function isOmrsDateToday(date: DateInput): boolean;
18
20
  /**
@@ -101,6 +103,10 @@ export type FormatDateOptions = {
101
103
  * When time is included, it is appended with a comma and a space. This
102
104
  * agrees with the output of `Date.prototype.toLocaleString` for *most*
103
105
  * locales.
106
+ *
107
+ * @param dateString The date string to parse and format.
108
+ * @param options Optional formatting options.
109
+ * @returns The formatted date string, or `null` if the input cannot be parsed.
104
110
  */
105
111
  export declare function formatPartialDate(dateString: string, options?: Partial<FormatDateOptions>): string | null;
106
112
  /**
@@ -121,11 +127,18 @@ export declare function formatPartialDate(dateString: string, options?: Partial<
121
127
  * When time is included, it is appended with a comma and a space. This
122
128
  * agrees with the output of `Date.prototype.toLocaleString` for *most*
123
129
  * locales.
130
+ *
131
+ * @param date The date to format.
132
+ * @param options Optional formatting options.
133
+ * @returns The formatted date string.
124
134
  */
125
135
  export declare function formatDate(date: Date, options?: Partial<FormatDateOptions>): string;
126
136
  /**
127
137
  * Formats the input as a time, according to the current locale.
128
138
  * 12-hour or 24-hour clock depends on locale.
139
+ *
140
+ * @param date The date whose time portion should be formatted.
141
+ * @returns The formatted time string (e.g., "2:30 PM" or "14:30").
129
142
  */
130
143
  export declare function formatTime(date: Date): string;
131
144
  /**
@@ -136,6 +149,10 @@ export declare function formatTime(date: Date): string;
136
149
  * This is created by concatenating the results of `formatDate`
137
150
  * and `formatTime` with a comma and space. This agrees with the
138
151
  * output of `Date.prototype.toLocaleString` for *most* locales.
152
+ *
153
+ * @param date The date to format.
154
+ * @param options Optional formatting options (same as formatDate, except time is always included).
155
+ * @returns The formatted date and time string.
139
156
  */
140
157
  export declare function formatDatetime(date: Date, options?: Partial<Omit<FormatDateOptions, 'time'>>): string;
141
158
  /**
@@ -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;;;GAGG;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,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,kBAAkB,QAEnF;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,MAAM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ided date is today.
66
67
  *
67
- * @param date Checks if the provided date is today.
68
+ * @param date The date to check.
69
+ * @returns `true` if the date is today, `false` otherwise.
68
70
  */ export function isOmrsDateToday(date) {
69
71
  return dayjs(date).isToday();
70
72
  }
@@ -175,6 +177,10 @@ const defaultOptions = {
175
177
  * When time is included, it is appended with a comma and a space. This
176
178
  * agrees with the output of `Date.prototype.toLocaleString` for *most*
177
179
  * locales.
180
+ *
181
+ * @param dateString The date string to parse and format.
182
+ * @param options Optional formatting options.
183
+ * @returns The formatted date string, or `null` if the input cannot be parsed.
178
184
  */ // TODO: Shouldn't throw on null input
179
185
  export function formatPartialDate(dateString, options = {}) {
180
186
  const locale = getLocale();
@@ -229,6 +235,10 @@ export function formatPartialDate(dateString, options = {}) {
229
235
  * When time is included, it is appended with a comma and a space. This
230
236
  * agrees with the output of `Date.prototype.toLocaleString` for *most*
231
237
  * locales.
238
+ *
239
+ * @param date The date to format.
240
+ * @param options Optional formatting options.
241
+ * @returns The formatted date string.
232
242
  */ // TODO: Shouldn't throw on null input
233
243
  export function formatDate(date, options) {
234
244
  let locale = options?.locale ?? getLocale();
@@ -306,6 +316,9 @@ const formatParts = (separator)=>{
306
316
  /**
307
317
  * Formats the input as a time, according to the current locale.
308
318
  * 12-hour or 24-hour clock depends on locale.
319
+ *
320
+ * @param date The date whose time portion should be formatted.
321
+ * @returns The formatted time string (e.g., "2:30 PM" or "14:30").
309
322
  */ export function formatTime(date) {
310
323
  return date.toLocaleTimeString(getLocale(), {
311
324
  hour: '2-digit',
@@ -320,6 +333,10 @@ const formatParts = (separator)=>{
320
333
  * This is created by concatenating the results of `formatDate`
321
334
  * and `formatTime` with a comma and space. This agrees with the
322
335
  * output of `Date.prototype.toLocaleString` for *most* locales.
336
+ *
337
+ * @param date The date to format.
338
+ * @param options Optional formatting options (same as formatDate, except time is always included).
339
+ * @returns The formatted date and time string.
323
340
  */ export function formatDatetime(date, options) {
324
341
  return formatDate(date, {
325
342
  ...options,
@@ -1,2 +1,14 @@
1
+ /**
2
+ * Determines if the application should behave as if it is online.
3
+ * When offline mode is enabled (`window.offlineEnabled`), this returns the
4
+ * provided `online` parameter or falls back to `navigator.onLine`.
5
+ * When offline mode is disabled, this always returns `true`.
6
+ *
7
+ * @param online Optional override for the online status. If provided and offline
8
+ * mode is enabled, this value is returned directly.
9
+ * @returns `true` if the application should behave as online, `false` otherwise.
10
+ *
11
+ * @category Utility
12
+ */
1
13
  export declare function isOnline(online?: boolean): boolean;
2
14
  //# sourceMappingURL=is-online.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"is-online.d.ts","sourceRoot":"","sources":["../src/is-online.ts"],"names":[],"mappings":"AAEA,wBAAgB,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,WAExC"}
1
+ {"version":3,"file":"is-online.d.ts","sourceRoot":"","sources":["../src/is-online.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;GAWG;AACH,wBAAgB,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,WAExC"}
package/dist/is-online.js CHANGED
@@ -1,3 +1,14 @@
1
- export function isOnline(online) {
1
+ /**
2
+ * Determines if the application should behave as if it is online.
3
+ * When offline mode is enabled (`window.offlineEnabled`), this returns the
4
+ * provided `online` parameter or falls back to `navigator.onLine`.
5
+ * When offline mode is disabled, this always returns `true`.
6
+ *
7
+ * @param online Optional override for the online status. If provided and offline
8
+ * mode is enabled, this value is returned directly.
9
+ * @returns `true` if the application should behave as online, `false` otherwise.
10
+ *
11
+ * @category Utility
12
+ */ export function isOnline(online) {
2
13
  return window.offlineEnabled ? online ?? navigator.onLine : true;
3
14
  }
@@ -26,17 +26,20 @@ export declare function formattedName(name: fhir.HumanName | undefined): string;
26
26
  * Names may be specified with a usage such as 'usual', 'official', 'nickname', 'maiden', etc.
27
27
  * A name with no usage specified is treated as the 'usual' name.
28
28
  *
29
- * The chosen name will be selected according to the priority order of `preferredNames`,
30
- * @example
31
- * // normal use case; prefer usual name, fallback to official name
32
- * displayNameByUsage(patient, 'usual', 'official')
33
- * @example
34
- * // prefer usual name over nickname, fallback to official name
35
- * displayNameByUsage(patient, 'usual', 'nickname', 'official')
29
+ * The chosen name will be selected according to the priority order of `preferredNames`.
36
30
  *
37
31
  * @param patient The patient from whom a name will be selected.
38
32
  * @param preferredNames Optional ordered sequence of preferred name usages; defaults to 'usual' if not specified.
39
- * @return the preferred name for the patient, or undefined if no acceptable name could be found.
33
+ * @returns The preferred name for the patient, or undefined if no acceptable name could be found.
34
+ *
35
+ * @example
36
+ * ```ts
37
+ * // normal use case; prefer usual name, fallback to official name
38
+ * selectPreferredName(patient, 'usual', 'official')
39
+ *
40
+ * // prefer usual name over nickname, fallback to official name
41
+ * selectPreferredName(patient, 'usual', 'nickname', 'official')
42
+ * ```
40
43
  */
41
44
  export declare function selectPreferredName(patient: fhir.Patient, ...preferredNames: NameUse[]): fhir.HumanName | undefined;
42
45
  //# sourceMappingURL=patient-helpers.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"patient-helpers.d.ts","sourceRoot":"","sources":["../src/patient-helpers.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAEhC,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAEpD;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,IAAI,CAAC,OAAO,GAAG,MAAM,CAG5D;AAED,uCAAuC;AACvC,wBAAgB,WAAW,CAAC,OAAO,EAAE,IAAI,CAAC,OAAO,GAAG,MAAM,CAEzD;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,IAAI,CAAC,SAAS,GAAG,SAAS,GAAG,MAAM,CAG1E;AAED,0CAA0C;AAC1C,wBAAgB,aAAa,CAAC,IAAI,EAAE,IAAI,CAAC,SAAS,GAAG,SAAS,GAAG,MAAM,CAEtE;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,GAAG,cAAc,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC,SAAS,GAAG,SAAS,CAWnH"}
1
+ {"version":3,"file":"patient-helpers.d.ts","sourceRoot":"","sources":["../src/patient-helpers.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAEhC,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAEpD;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,IAAI,CAAC,OAAO,GAAG,MAAM,CAG5D;AAED,uCAAuC;AACvC,wBAAgB,WAAW,CAAC,OAAO,EAAE,IAAI,CAAC,OAAO,GAAG,MAAM,CAEzD;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,IAAI,CAAC,SAAS,GAAG,SAAS,GAAG,MAAM,CAG1E;AAED,0CAA0C;AAC1C,wBAAgB,aAAa,CAAC,IAAI,EAAE,IAAI,CAAC,SAAS,GAAG,SAAS,GAAG,MAAM,CAEtE;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,GAAG,cAAc,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC,SAAS,GAAG,SAAS,CAWnH"}
@@ -30,17 +30,20 @@
30
30
  * Names may be specified with a usage such as 'usual', 'official', 'nickname', 'maiden', etc.
31
31
  * A name with no usage specified is treated as the 'usual' name.
32
32
  *
33
- * The chosen name will be selected according to the priority order of `preferredNames`,
34
- * @example
35
- * // normal use case; prefer usual name, fallback to official name
36
- * displayNameByUsage(patient, 'usual', 'official')
37
- * @example
38
- * // prefer usual name over nickname, fallback to official name
39
- * displayNameByUsage(patient, 'usual', 'nickname', 'official')
33
+ * The chosen name will be selected according to the priority order of `preferredNames`.
40
34
  *
41
35
  * @param patient The patient from whom a name will be selected.
42
36
  * @param preferredNames Optional ordered sequence of preferred name usages; defaults to 'usual' if not specified.
43
- * @return the preferred name for the patient, or undefined if no acceptable name could be found.
37
+ * @returns The preferred name for the patient, or undefined if no acceptable name could be found.
38
+ *
39
+ * @example
40
+ * ```ts
41
+ * // normal use case; prefer usual name, fallback to official name
42
+ * selectPreferredName(patient, 'usual', 'official')
43
+ *
44
+ * // prefer usual name over nickname, fallback to official name
45
+ * selectPreferredName(patient, 'usual', 'nickname', 'official')
46
+ * ```
44
47
  */ export function selectPreferredName(patient, ...preferredNames) {
45
48
  if (preferredNames.length == 0) {
46
49
  preferredNames = [
package/dist/version.d.ts CHANGED
@@ -1,2 +1,11 @@
1
+ /**
2
+ * Checks if an installed version satisfies a required version range using
3
+ * semver comparison. Handles prerelease versions and normalizes version strings.
4
+ *
5
+ * @param requiredVersion A semver range string (e.g., "^1.0.0", ">=2.0.0").
6
+ * @param installedVersion The installed version string to check against the range.
7
+ * @returns `true` if the installed version satisfies the required version range.
8
+ *
9
+ */
1
10
  export declare function isVersionSatisfied(requiredVersion: string, installedVersion: string): boolean;
2
11
  //# sourceMappingURL=version.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAqBA,wBAAgB,kBAAkB,CAAC,eAAe,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,WAMnF"}
1
+ {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAqBA;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAAC,eAAe,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,WAMnF"}
package/dist/version.js CHANGED
@@ -13,7 +13,15 @@ function normalizeFullVersion(version) {
13
13
  }
14
14
  return normalizeOnlyVersion(version);
15
15
  }
16
- export function isVersionSatisfied(requiredVersion, installedVersion) {
16
+ /**
17
+ * Checks if an installed version satisfies a required version range using
18
+ * semver comparison. Handles prerelease versions and normalizes version strings.
19
+ *
20
+ * @param requiredVersion A semver range string (e.g., "^1.0.0", ">=2.0.0").
21
+ * @param installedVersion The installed version string to check against the range.
22
+ * @returns `true` if the installed version satisfies the required version range.
23
+ *
24
+ */ export function isVersionSatisfied(requiredVersion, installedVersion) {
17
25
  const version = normalizeFullVersion(installedVersion);
18
26
  return semver.satisfies(version, requiredVersion, {
19
27
  includePrerelease: true
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openmrs/esm-utils",
3
- "version": "8.0.1-pre.3783",
3
+ "version": "8.0.1-pre.3786",
4
4
  "license": "MPL-2.0",
5
5
  "description": "Helper utilities for OpenMRS",
6
6
  "type": "module",
@@ -59,7 +59,7 @@
59
59
  "rxjs": "6.x"
60
60
  },
61
61
  "devDependencies": {
62
- "@openmrs/esm-globals": "8.0.1-pre.3783",
62
+ "@openmrs/esm-globals": "8.0.1-pre.3786",
63
63
  "@swc/cli": "^0.7.7",
64
64
  "@swc/core": "^1.11.29",
65
65
  "@types/lodash-es": "^4.17.12",
@@ -58,8 +58,10 @@ export function isOmrsDateStrict(omrsPayloadString: string): boolean {
58
58
  }
59
59
 
60
60
  /**
61
+ * Checks if the provided date is today.
61
62
  *
62
- * @param date Checks if the provided date is today.
63
+ * @param date The date to check.
64
+ * @returns `true` if the date is today, `false` otherwise.
63
65
  */
64
66
  export function isOmrsDateToday(date: DateInput) {
65
67
  return dayjs(date).isToday();
@@ -232,6 +234,10 @@ const defaultOptions: FormatDateOptions = {
232
234
  * When time is included, it is appended with a comma and a space. This
233
235
  * agrees with the output of `Date.prototype.toLocaleString` for *most*
234
236
  * locales.
237
+ *
238
+ * @param dateString The date string to parse and format.
239
+ * @param options Optional formatting options.
240
+ * @returns The formatted date string, or `null` if the input cannot be parsed.
235
241
  */
236
242
  // TODO: Shouldn't throw on null input
237
243
  export function formatPartialDate(dateString: string, options: Partial<FormatDateOptions> = {}) {
@@ -293,6 +299,10 @@ export function formatPartialDate(dateString: string, options: Partial<FormatDat
293
299
  * When time is included, it is appended with a comma and a space. This
294
300
  * agrees with the output of `Date.prototype.toLocaleString` for *most*
295
301
  * locales.
302
+ *
303
+ * @param date The date to format.
304
+ * @param options Optional formatting options.
305
+ * @returns The formatted date string.
296
306
  */
297
307
  // TODO: Shouldn't throw on null input
298
308
  export function formatDate(date: Date, options?: Partial<FormatDateOptions>) {
@@ -381,6 +391,9 @@ const formatParts = (separator: string) => {
381
391
  /**
382
392
  * Formats the input as a time, according to the current locale.
383
393
  * 12-hour or 24-hour clock depends on locale.
394
+ *
395
+ * @param date The date whose time portion should be formatted.
396
+ * @returns The formatted time string (e.g., "2:30 PM" or "14:30").
384
397
  */
385
398
  export function formatTime(date: Date) {
386
399
  return date.toLocaleTimeString(getLocale(), {
@@ -397,6 +410,10 @@ export function formatTime(date: Date) {
397
410
  * This is created by concatenating the results of `formatDate`
398
411
  * and `formatTime` with a comma and space. This agrees with the
399
412
  * output of `Date.prototype.toLocaleString` for *most* locales.
413
+ *
414
+ * @param date The date to format.
415
+ * @param options Optional formatting options (same as formatDate, except time is always included).
416
+ * @returns The formatted date and time string.
400
417
  */
401
418
  export function formatDatetime(date: Date, options?: Partial<Omit<FormatDateOptions, 'time'>>) {
402
419
  return formatDate(date, { ...options, time: true });
package/src/is-online.ts CHANGED
@@ -1,5 +1,17 @@
1
1
  import type {} from '@openmrs/esm-globals';
2
2
 
3
+ /**
4
+ * Determines if the application should behave as if it is online.
5
+ * When offline mode is enabled (`window.offlineEnabled`), this returns the
6
+ * provided `online` parameter or falls back to `navigator.onLine`.
7
+ * When offline mode is disabled, this always returns `true`.
8
+ *
9
+ * @param online Optional override for the online status. If provided and offline
10
+ * mode is enabled, this value is returned directly.
11
+ * @returns `true` if the application should behave as online, `false` otherwise.
12
+ *
13
+ * @category Utility
14
+ */
3
15
  export function isOnline(online?: boolean) {
4
16
  return window.offlineEnabled ? online ?? navigator.onLine : true;
5
17
  }
@@ -42,17 +42,20 @@ export function formattedName(name: fhir.HumanName | undefined): string {
42
42
  * Names may be specified with a usage such as 'usual', 'official', 'nickname', 'maiden', etc.
43
43
  * A name with no usage specified is treated as the 'usual' name.
44
44
  *
45
- * The chosen name will be selected according to the priority order of `preferredNames`,
46
- * @example
47
- * // normal use case; prefer usual name, fallback to official name
48
- * displayNameByUsage(patient, 'usual', 'official')
49
- * @example
50
- * // prefer usual name over nickname, fallback to official name
51
- * displayNameByUsage(patient, 'usual', 'nickname', 'official')
45
+ * The chosen name will be selected according to the priority order of `preferredNames`.
52
46
  *
53
47
  * @param patient The patient from whom a name will be selected.
54
48
  * @param preferredNames Optional ordered sequence of preferred name usages; defaults to 'usual' if not specified.
55
- * @return the preferred name for the patient, or undefined if no acceptable name could be found.
49
+ * @returns The preferred name for the patient, or undefined if no acceptable name could be found.
50
+ *
51
+ * @example
52
+ * ```ts
53
+ * // normal use case; prefer usual name, fallback to official name
54
+ * selectPreferredName(patient, 'usual', 'official')
55
+ *
56
+ * // prefer usual name over nickname, fallback to official name
57
+ * selectPreferredName(patient, 'usual', 'nickname', 'official')
58
+ * ```
56
59
  */
57
60
  export function selectPreferredName(patient: fhir.Patient, ...preferredNames: NameUse[]): fhir.HumanName | undefined {
58
61
  if (preferredNames.length == 0) {
package/src/version.ts CHANGED
@@ -19,6 +19,15 @@ function normalizeFullVersion(version: string) {
19
19
  return normalizeOnlyVersion(version);
20
20
  }
21
21
 
22
+ /**
23
+ * Checks if an installed version satisfies a required version range using
24
+ * semver comparison. Handles prerelease versions and normalizes version strings.
25
+ *
26
+ * @param requiredVersion A semver range string (e.g., "^1.0.0", ">=2.0.0").
27
+ * @param installedVersion The installed version string to check against the range.
28
+ * @returns `true` if the installed version satisfies the required version range.
29
+ *
30
+ */
22
31
  export function isVersionSatisfied(requiredVersion: string, installedVersion: string) {
23
32
  const version = normalizeFullVersion(installedVersion);
24
33