@defra/forms-model 3.0.484 → 3.0.485

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.
@@ -13,4 +13,13 @@ export function slugify(input = '', options) {
13
13
  ...options
14
14
  });
15
15
  }
16
+
17
+ /**
18
+ * Safely extracts error message from unknown error types
19
+ * @param {unknown} error - The error to extract message from
20
+ * @returns {string} The error message
21
+ */
22
+ export function getErrorMessage(error) {
23
+ return error instanceof Error ? error.message : String(error);
24
+ }
16
25
  //# sourceMappingURL=helpers.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.js","names":["slug","slugify","input","options","string","trimStart","replace","fallback","lower","trim"],"sources":["../../../src/utils/helpers.ts"],"sourcesContent":["import slug from 'slug'\n\n/**\n * Replace whitespace, en-dashes and em-dashes with spaces\n * before running through the slug package\n */\nexport function slugify(input = '', options?: slug.Options) {\n const string = input.trimStart().replace(/[\\s–—]/g, ' ')\n\n return slug(string, {\n fallback: false,\n lower: true,\n trim: true,\n ...options\n })\n}\n"],"mappings":"AAAA,OAAOA,IAAI,MAAM,MAAM;;AAEvB;AACA;AACA;AACA;AACA,OAAO,SAASC,OAAOA,CAACC,KAAK,GAAG,EAAE,EAAEC,OAAsB,EAAE;EAC1D,MAAMC,MAAM,GAAGF,KAAK,CAACG,SAAS,CAAC,CAAC,CAACC,OAAO,CAAC,SAAS,EAAE,GAAG,CAAC;EAExD,OAAON,IAAI,CAACI,MAAM,EAAE;IAClBG,QAAQ,EAAE,KAAK;IACfC,KAAK,EAAE,IAAI;IACXC,IAAI,EAAE,IAAI;IACV,GAAGN;EACL,CAAC,CAAC;AACJ","ignoreList":[]}
1
+ {"version":3,"file":"helpers.js","names":["slug","slugify","input","options","string","trimStart","replace","fallback","lower","trim","getErrorMessage","error","Error","message","String"],"sources":["../../../src/utils/helpers.ts"],"sourcesContent":["import slug from 'slug'\n\n/**\n * Replace whitespace, en-dashes and em-dashes with spaces\n * before running through the slug package\n */\nexport function slugify(input = '', options?: slug.Options) {\n const string = input.trimStart().replace(/[\\s–—]/g, ' ')\n\n return slug(string, {\n fallback: false,\n lower: true,\n trim: true,\n ...options\n })\n}\n\n/**\n * Safely extracts error message from unknown error types\n * @param {unknown} error - The error to extract message from\n * @returns {string} The error message\n */\nexport function getErrorMessage(error: unknown): string {\n return error instanceof Error ? error.message : String(error)\n}\n"],"mappings":"AAAA,OAAOA,IAAI,MAAM,MAAM;;AAEvB;AACA;AACA;AACA;AACA,OAAO,SAASC,OAAOA,CAACC,KAAK,GAAG,EAAE,EAAEC,OAAsB,EAAE;EAC1D,MAAMC,MAAM,GAAGF,KAAK,CAACG,SAAS,CAAC,CAAC,CAACC,OAAO,CAAC,SAAS,EAAE,GAAG,CAAC;EAExD,OAAON,IAAI,CAACI,MAAM,EAAE;IAClBG,QAAQ,EAAE,KAAK;IACfC,KAAK,EAAE,IAAI;IACXC,IAAI,EAAE,IAAI;IACV,GAAGN;EACL,CAAC,CAAC;AACJ;;AAEA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASO,eAAeA,CAACC,KAAc,EAAU;EACtD,OAAOA,KAAK,YAAYC,KAAK,GAAGD,KAAK,CAACE,OAAO,GAAGC,MAAM,CAACH,KAAK,CAAC;AAC/D","ignoreList":[]}
@@ -4,4 +4,10 @@ import slug from 'slug';
4
4
  * before running through the slug package
5
5
  */
6
6
  export declare function slugify(input?: string, options?: slug.Options): string;
7
+ /**
8
+ * Safely extracts error message from unknown error types
9
+ * @param {unknown} error - The error to extract message from
10
+ * @returns {string} The error message
11
+ */
12
+ export declare function getErrorMessage(error: unknown): string;
7
13
  //# sourceMappingURL=helpers.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../src/utils/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAA;AAEvB;;;GAGG;AACH,wBAAgB,OAAO,CAAC,KAAK,SAAK,EAAE,OAAO,CAAC,EAAE,IAAI,CAAC,OAAO,UASzD"}
1
+ {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../src/utils/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAA;AAEvB;;;GAGG;AACH,wBAAgB,OAAO,CAAC,KAAK,SAAK,EAAE,OAAO,CAAC,EAAE,IAAI,CAAC,OAAO,UASzD;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAEtD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defra/forms-model",
3
- "version": "3.0.484",
3
+ "version": "3.0.485",
4
4
  "description": "A hapi plugin providing the model for Defra forms",
5
5
  "homepage": "https://github.com/DEFRA/forms-designer/tree/main/model#readme",
6
6
  "types": "dist/types/index.d.ts",
@@ -14,3 +14,12 @@ export function slugify(input = '', options?: slug.Options) {
14
14
  ...options
15
15
  })
16
16
  }
17
+
18
+ /**
19
+ * Safely extracts error message from unknown error types
20
+ * @param {unknown} error - The error to extract message from
21
+ * @returns {string} The error message
22
+ */
23
+ export function getErrorMessage(error: unknown): string {
24
+ return error instanceof Error ? error.message : String(error)
25
+ }