dce-reactkit 3.6.13 → 3.6.15

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.
@@ -52,7 +52,7 @@ export declare const confirm: (title: string, text: string, opts?: {
52
52
  */
53
53
  export declare const showFatalError: (error: any, errorTitle?: string) => Promise<void>;
54
54
  /**
55
- * Add a handler for when a fatal error occurs
55
+ * Add a handler for when a fatal error occurs (or when a session expiry occurs)
56
56
  * @author Gabe Abrams
57
57
  */
58
58
  export declare const addFatalErrorHandler: (handler: () => void) => void;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Prefix a word or name with "a" or "an" depending on whether it starts with a
3
+ * vowel or not
4
+ * @author Gabe Abrams
5
+ * @param text the text to prefix
6
+ * @param capitalize whether to capitalize the "A" or "An"
7
+ * @returns the text prefixed with "a" or "an"
8
+ */
9
+ declare const prefixWithAOrAn: (text: string, capitalize?: boolean) => string;
10
+ export default prefixWithAOrAn;
package/dist/index.d.ts CHANGED
@@ -71,7 +71,7 @@ declare const confirm: (title: string, text: string, opts?: {
71
71
  */
72
72
  declare const showFatalError: (error: any, errorTitle?: string) => Promise<void>;
73
73
  /**
74
- * Add a handler for when a fatal error occurs
74
+ * Add a handler for when a fatal error occurs (or when a session expiry occurs)
75
75
  * @author Gabe Abrams
76
76
  */
77
77
  declare const addFatalErrorHandler: (handler: () => void) => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dce-reactkit",
3
- "version": "3.6.13",
3
+ "version": "3.6.15",
4
4
  "description": "Shared components for Harvard DCE apps",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -314,7 +314,7 @@ export const showFatalError = async (
314
314
  };
315
315
 
316
316
  /**
317
- * Add a handler for when a fatal error occurs
317
+ * Add a handler for when a fatal error occurs (or when a session expiry occurs)
318
318
  * @author Gabe Abrams
319
319
  */
320
320
  export const addFatalErrorHandler = (handler: () => void) => {
@@ -333,6 +333,15 @@ let setSessionHasExpired: (isExpired: boolean) => void;
333
333
  * @author Gabe Abrams
334
334
  */
335
335
  export const showSessionExpiredMessage = async () => {
336
+ // Call all fatal error listeners
337
+ try {
338
+ fatalErrorHandlers.forEach((handler) => {
339
+ handler();
340
+ });
341
+ } catch (err) {
342
+ // Ignore listener errors
343
+ }
344
+
336
345
  // Wait for helper to exist
337
346
  await waitForHelper(() => {
338
347
  return !!setSessionHasExpired;
@@ -0,0 +1,29 @@
1
+ // Constants
2
+ const VOWELS = ['a', 'e', 'i', 'o', 'u'];
3
+
4
+ /**
5
+ * Prefix a word or name with "a" or "an" depending on whether it starts with a
6
+ * vowel or not
7
+ * @author Gabe Abrams
8
+ * @param text the text to prefix
9
+ * @param capitalize whether to capitalize the "A" or "An"
10
+ * @returns the text prefixed with "a" or "an"
11
+ */
12
+ const prefixWithAOrAn = (text: string, capitalize = false): string => {
13
+ // Get the first letter
14
+ const firstLetter = text.charAt(0).toLowerCase();
15
+
16
+ // Check if starts with vowel
17
+ const startsWithVowel = VOWELS.includes(firstLetter);
18
+
19
+ // Determine prefix
20
+ let prefix = startsWithVowel ? 'an' : 'a';
21
+ if (capitalize) {
22
+ prefix = prefix.charAt(0).toUpperCase() + prefix.substring(1);
23
+ }
24
+
25
+ // Return the text prefixed with "a" or "an"
26
+ return `${prefix} ${text}`;
27
+ };
28
+
29
+ export default prefixWithAOrAn;