@types/govuk-frontend 5.7.0 → 5.8.0

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.
govuk-frontend/README.md CHANGED
@@ -8,7 +8,7 @@ This package contains type definitions for govuk-frontend (https://github.com/al
8
8
  Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/govuk-frontend.
9
9
 
10
10
  ### Additional Details
11
- * Last updated: Mon, 14 Oct 2024 16:41:00 GMT
11
+ * Last updated: Mon, 03 Feb 2025 16:02:40 GMT
12
12
  * Dependencies: none
13
13
 
14
14
  # Credits
@@ -1,3 +1,4 @@
1
+ export { ConfigurableComponent } from "./common/configuration.mjs";
1
2
  export { version } from "./common/govuk-frontend-version.mjs";
2
3
  export { isSupported } from "./common/index.mjs";
3
4
  export { Accordion } from "./components/accordion/accordion.mjs";
@@ -1,3 +1,4 @@
1
+ import { ConfigurableComponent } from "./common/configuration.js";
1
2
  import { version } from "./common/govuk-frontend-version.js";
2
3
  import { isSupported } from "./common/index.js";
3
4
  import { Accordion } from "./components/accordion/accordion.js";
@@ -38,6 +39,7 @@ declare const GOVUKFrontend: {
38
39
  SkipLink: typeof SkipLink;
39
40
  Tabs: typeof Tabs;
40
41
  Component: typeof Component;
42
+ ConfigurableComponent: typeof ConfigurableComponent;
41
43
  createAll: typeof createAll;
42
44
  initAll: typeof initAll;
43
45
  };
@@ -0,0 +1 @@
1
+ export * from "./configuration.js";
@@ -0,0 +1,208 @@
1
+ import { GOVUKFrontendComponent } from "../govuk-frontend-component.js";
2
+
3
+ /**
4
+ * Normalise string
5
+ *
6
+ * 'If it looks like a duck, and it quacks like a duck…' 🦆
7
+ *
8
+ * If the passed value looks like a boolean or a number, convert it to a boolean
9
+ * or number.
10
+ *
11
+ * Designed to be used to convert config passed via data attributes (which are
12
+ * always strings) into something sensible.
13
+ *
14
+ * @internal
15
+ * @param {DOMStringMap[string]} value - The value to normalise
16
+ * @param {SchemaProperty} [property] - Component schema property
17
+ * @returns {string | boolean | number | undefined} Normalised data
18
+ */
19
+ export function normaliseString(
20
+ value: DOMStringMap[string],
21
+ property?: SchemaProperty,
22
+ ): string | boolean | number | undefined;
23
+
24
+ /**
25
+ * Normalise dataset
26
+ *
27
+ * Loop over an object and normalise each value using {@link normaliseString},
28
+ * optionally expanding nested `i18n.field`
29
+ *
30
+ * @internal
31
+ * @param {{ schema?: Schema<ObjectNested>, moduleName: string }} Component - Component class
32
+ * @param {DOMStringMap} dataset - HTML element dataset
33
+ * @returns {ObjectNested} Normalised dataset
34
+ */
35
+ export function normaliseDataset(
36
+ Component: {
37
+ schema?: Schema<ObjectNested>;
38
+ moduleName: string;
39
+ },
40
+ dataset: DOMStringMap,
41
+ ): ObjectNested;
42
+
43
+ /**
44
+ * Config merging function
45
+ *
46
+ * Takes any number of objects and combines them together, with
47
+ * greatest priority on the LAST item passed in.
48
+ *
49
+ * @internal
50
+ * @param {...{ [key: string]: unknown }} configObjects - Config objects to merge
51
+ * @returns {{ [key: string]: unknown }} A merged config object
52
+ */
53
+ export function mergeConfigs(
54
+ ...configObjects: Array<{
55
+ [key: string]: unknown;
56
+ }>
57
+ ): {
58
+ [key: string]: unknown;
59
+ };
60
+
61
+ /**
62
+ * Validate component config by schema
63
+ *
64
+ * Follows limited examples in JSON schema for wider support in future
65
+ *
66
+ * {@link https://ajv.js.org/json-schema.html#compound-keywords}
67
+ * {@link https://ajv.js.org/packages/ajv-errors.html#single-message}
68
+ *
69
+ * @internal
70
+ * @template {Partial<Record<keyof ConfigurationType, unknown>>} ConfigurationType
71
+ * @param {Schema<ConfigurationType>} schema - The schema of a component
72
+ * @param {ConfigurationType} config - Component config
73
+ * @returns {string[]} List of validation errors
74
+ */
75
+ export function validateConfig<
76
+ ConfigurationType extends Partial<
77
+ Record<keyof ConfigurationType, unknown>
78
+ >,
79
+ >(
80
+ schema: Schema<ConfigurationType>,
81
+ config: ConfigurationType,
82
+ ): string[];
83
+
84
+ /**
85
+ * Extracts keys starting with a particular namespace from dataset ('data-*')
86
+ * object, removing the namespace in the process, normalising all values
87
+ *
88
+ * @internal
89
+ * @template {Partial<Record<keyof ConfigurationType, unknown>>} ConfigurationType
90
+ * @param {Schema<ConfigurationType>} schema - The schema of a component
91
+ * @param {DOMStringMap} dataset - The object to extract key-value pairs from
92
+ * @param {keyof ConfigurationType} namespace - The namespace to filter keys with
93
+ * @returns {ObjectNested | undefined} Nested object with dot-separated key namespace removed
94
+ */
95
+ export function extractConfigByNamespace<
96
+ ConfigurationType extends Partial<
97
+ Record<keyof ConfigurationType, unknown>
98
+ >,
99
+ >(
100
+ schema: Schema<ConfigurationType>,
101
+ dataset: DOMStringMap,
102
+ namespace: keyof ConfigurationType,
103
+ ): ObjectNested | undefined;
104
+
105
+ export const configOverride: unique symbol;
106
+
107
+ /**
108
+ * Base Component class
109
+ *
110
+ * Centralises the behaviours shared by our components
111
+ *
112
+ * @template {Partial<Record<keyof ConfigurationType, unknown>>} [ConfigurationType=ObjectNested]
113
+ * @template {Element & { dataset: DOMStringMap }} [RootElementType=HTMLElement]
114
+ */
115
+ export abstract class ConfigurableComponent<
116
+ ConfigurationType extends Partial<
117
+ Record<keyof ConfigurationType, unknown>
118
+ > = ObjectNested,
119
+ RootElementType extends Element & {
120
+ dataset: DOMStringMap;
121
+ } = HTMLElement,
122
+ > extends GOVUKFrontendComponent<RootElementType> {
123
+ /**
124
+ * Constructs a new component, validating that GOV.UK Frontend is supported
125
+ *
126
+ * @internal
127
+ * @param {Element | null} [$root] - HTML element to use for component
128
+ * @param {ConfigurationType} [config] - HTML element to use for component
129
+ */
130
+ constructor($root?: Element | null, config?: ConfigurationType);
131
+
132
+ /**
133
+ * Returns the root element of the component
134
+ *
135
+ * @returns {ConfigurationType} - the root element of component
136
+ */
137
+ protected get config(): ConfigurationType;
138
+
139
+ /** */
140
+ _config: ConfigurationType;
141
+
142
+ /**
143
+ * configOverride
144
+ *
145
+ * Function which defines configuration overrides to prioritize
146
+ * properties from the root element's dataset.
147
+ *
148
+ * It should take a subset of configuration as input and return
149
+ * a new configuration object with properties that should be
150
+ * overridden based on the root element's dataset. A Symbol
151
+ * is used for indexing to prevent conflicts.
152
+ *
153
+ * @internal
154
+ * @param {Partial<ConfigurationType>} [param] - Configuration object
155
+ * @returns {Partial<ConfigurationType>} return - Configuration object
156
+ */
157
+ [configOverride](param?: Partial<ConfigurationType>): Partial<ConfigurationType>;
158
+ }
159
+
160
+ export type NestedKey = keyof ObjectNested;
161
+
162
+ export interface ObjectNested {
163
+ [key: string]: string | boolean | number | ObjectNested | undefined;
164
+ }
165
+
166
+ /**
167
+ * Schema for component config
168
+ */
169
+ export interface Schema<
170
+ ConfigurationType extends Partial<
171
+ Record<keyof ConfigurationType, unknown>
172
+ >,
173
+ > {
174
+ /**
175
+ * - Schema properties
176
+ */
177
+ properties: Record<keyof ConfigurationType, SchemaProperty | undefined>;
178
+
179
+ /**
180
+ * - List of schema conditions
181
+ */
182
+ anyOf?: SchemaCondition[] | undefined;
183
+ }
184
+
185
+ /**
186
+ * Schema property for component config
187
+ */
188
+ export interface SchemaProperty {
189
+ /**
190
+ * - Property type
191
+ */
192
+ type: "string" | "boolean" | "number" | "object";
193
+ }
194
+
195
+ /**
196
+ * Schema condition for component config
197
+ */
198
+ export interface SchemaCondition {
199
+ /**
200
+ * - List of required config fields
201
+ */
202
+ required: string[];
203
+
204
+ /**
205
+ * - Error message when required config fields not provided
206
+ */
207
+ errorMessage: string;
208
+ }
@@ -1,3 +1,5 @@
1
+ import { type ObjectNested } from "./configuration.js";
2
+
1
3
  /**
2
4
  * Common helpers which do not require polyfill.
3
5
  *
@@ -5,41 +7,6 @@
5
7
  * so that the polyfill can be properly tree-shaken and does not burden
6
8
  * the components that do not need that helper
7
9
  */
8
- /**
9
- * Config merging function
10
- *
11
- * Takes any number of objects and combines them together, with
12
- * greatest priority on the LAST item passed in.
13
- *
14
- * @internal
15
- * @param {...{ [key: string]: unknown }} configObjects - Config objects to merge
16
- * @returns {{ [key: string]: unknown }} A merged config object
17
- */
18
- export function mergeConfigs(
19
- ...configObjects: Array<{
20
- [key: string]: unknown;
21
- }>
22
- ): {
23
- [key: string]: unknown;
24
- };
25
-
26
- /**
27
- * Extracts keys starting with a particular namespace from dataset ('data-*')
28
- * object, removing the namespace in the process, normalising all values
29
- *
30
- * @internal
31
- * @param {{ schema: Schema }} Component - Component class
32
- * @param {DOMStringMap} dataset - The object to extract key-value pairs from
33
- * @param {string} namespace - The namespace to filter keys with
34
- * @returns {ObjectNested | undefined} Nested object with dot-separated key namespace removed
35
- */
36
- export function extractConfigByNamespace(
37
- Component: {
38
- schema: Schema;
39
- },
40
- dataset: DOMStringMap,
41
- namespace: string,
42
- ): ObjectNested | undefined;
43
10
 
44
11
  /**
45
12
  * Get hash fragment from URL
@@ -105,21 +72,18 @@ export function isInitialised($root: Element, moduleName: string): boolean;
105
72
  export function isSupported($scope?: HTMLElement | null): boolean;
106
73
 
107
74
  /**
108
- * Validate component config by schema
109
- *
110
- * Follows limited examples in JSON schema for wider support in future
111
- *
112
- * {@link https://ajv.js.org/json-schema.html#compound-keywords}
113
- * {@link https://ajv.js.org/packages/ajv-errors.html#single-message}
75
+ * Check for an object
114
76
  *
115
77
  * @internal
116
- * @param {Schema} schema - Config schema
117
- * @param {{ [key: string]: unknown }} config - Component config
118
- * @returns {string[]} List of validation errors
78
+ * @template {Partial<Record<keyof ObjectType, unknown>>} [ObjectType=ObjectNested]
79
+ * @param {unknown | ObjectType} option - Option to check
80
+ * @returns {option is ObjectType} Whether the option is an object
119
81
  */
120
- export function validateConfig(schema: Schema, config: {
121
- [key: string]: unknown;
122
- }): string[];
82
+ export function isObject<
83
+ ObjectType extends Partial<Record<keyof ObjectType, unknown>> = ObjectNested,
84
+ >(
85
+ option: unknown,
86
+ ): option is ObjectType;
123
87
 
124
88
  /**
125
89
  * Format error message
@@ -131,54 +95,6 @@ export function validateConfig(schema: Schema, config: {
131
95
  */
132
96
  export function formatErrorMessage(Component: ComponentWithModuleName, message: string): string;
133
97
 
134
- /**
135
- * Schema for component config
136
- */
137
- export interface Schema {
138
- /**
139
- * - Schema properties
140
- */
141
- properties: {
142
- [field: string]: SchemaProperty | undefined;
143
- };
144
-
145
- /**
146
- * - List of schema conditions
147
- */
148
- anyOf?: SchemaCondition[] | undefined;
149
- }
150
-
151
- /**
152
- * Schema property for component config
153
- */
154
- export interface SchemaProperty {
155
- /**
156
- * - Property type
157
- */
158
- type: "string" | "boolean" | "number" | "object";
159
- }
160
-
161
- /**
162
- * Schema condition for component config
163
- */
164
- export interface SchemaCondition {
165
- /**
166
- * - List of required config fields
167
- */
168
- required: string[];
169
-
170
- /**
171
- * - Error message when required config fields not provided
172
- */
173
- errorMessage: string;
174
- }
175
-
176
- export type NestedKey = keyof ObjectNested;
177
-
178
- export interface ObjectNested {
179
- [key: string]: string | boolean | number | ObjectNested | undefined;
180
- }
181
-
182
98
  export interface ComponentWithModuleName {
183
99
  /**
184
100
  * - Name of the component
@@ -1,4 +1,4 @@
1
- import { GOVUKFrontendComponent } from "../../govuk-frontend-component.js";
1
+ import { ConfigurableComponent } from "../../common/configuration.js";
2
2
 
3
3
  /**
4
4
  * Accordion component
@@ -12,7 +12,7 @@ import { GOVUKFrontendComponent } from "../../govuk-frontend-component.js";
12
12
  * The state of each section is saved to the DOM via the `aria-expanded`
13
13
  * attribute, which also provides accessibility.
14
14
  */
15
- export class Accordion extends GOVUKFrontendComponent<HTMLElement> {
15
+ export class Accordion extends ConfigurableComponent<AccordionConfig, HTMLElement> {
16
16
  /**
17
17
  * Name for the component used when initialising using data-module attributes.
18
18
  */
@@ -1,9 +1,9 @@
1
- import { GOVUKFrontendComponent } from "../../govuk-frontend-component.js";
1
+ import { ConfigurableComponent } from "../../common/configuration.js";
2
2
 
3
3
  /**
4
4
  * JavaScript enhancements for the Button component
5
5
  */
6
- export class Button extends GOVUKFrontendComponent<HTMLElement> {
6
+ export class Button extends ConfigurableComponent<ButtonConfig, HTMLElement> {
7
7
  /**
8
8
  * Name for the component used when initialising using data-module attributes.
9
9
  */
@@ -1,4 +1,4 @@
1
- import { GOVUKFrontendComponent } from "../../govuk-frontend-component.js";
1
+ import { configOverride, ConfigurableComponent } from "../../common/configuration.js";
2
2
  import { type TranslationPluralForms } from "../../i18n.js";
3
3
 
4
4
  /**
@@ -11,7 +11,7 @@ import { type TranslationPluralForms } from "../../i18n.js";
11
11
  * You can configure the message to only appear after a certain percentage
12
12
  * of the available characters/words has been entered.
13
13
  */
14
- export class CharacterCount extends GOVUKFrontendComponent<HTMLElement> {
14
+ export class CharacterCount extends ConfigurableComponent<CharacterCountConfig, HTMLElement> {
15
15
  /**
16
16
  * Name for the component used when initialising using data-module attributes.
17
17
  */
@@ -55,6 +55,19 @@ export class CharacterCount extends GOVUKFrontendComponent<HTMLElement> {
55
55
  * @param {CharacterCountConfig} [config] - Character count config
56
56
  */
57
57
  constructor($root: Element | null, config?: CharacterCountConfig);
58
+
59
+ /**
60
+ * Character count config override
61
+ *
62
+ * To ensure data-attributes take complete precedence, even if they change
63
+ * the type of count, we need to reset the `maxlength` and `maxwords` from
64
+ * the JavaScript config.
65
+ *
66
+ * @internal
67
+ * @param {CharacterCountConfig} datasetConfig - configuration specified by dataset
68
+ * @returns {CharacterCountConfig} - configuration to override by dataset
69
+ */
70
+ [configOverride](datasetConfig: CharacterCountConfig): CharacterCountConfig;
58
71
  }
59
72
 
60
73
  /**
@@ -1,4 +1,4 @@
1
- import { GOVUKFrontendComponent } from "../../govuk-frontend-component.js";
1
+ import { ConfigurableComponent } from "../../common/configuration.js";
2
2
 
3
3
  /**
4
4
  * Error summary component
@@ -6,7 +6,7 @@ import { GOVUKFrontendComponent } from "../../govuk-frontend-component.js";
6
6
  * Takes focus on initialisation for accessible announcement, unless disabled in
7
7
  * configuration.
8
8
  */
9
- export class ErrorSummary extends GOVUKFrontendComponent<HTMLElement> {
9
+ export class ErrorSummary extends ConfigurableComponent<ErrorSummaryConfig, HTMLElement> {
10
10
  /**
11
11
  * Name for the component used when initialising using data-module attributes.
12
12
  */
@@ -1,9 +1,9 @@
1
- import { GOVUKFrontendComponent } from "../../govuk-frontend-component.js";
1
+ import { ConfigurableComponent } from "../../common/configuration.js";
2
2
 
3
3
  /**
4
4
  * Exit this page component
5
5
  */
6
- export class ExitThisPage extends GOVUKFrontendComponent<HTMLElement> {
6
+ export class ExitThisPage extends ConfigurableComponent<ExitThisPageConfig, HTMLElement> {
7
7
  /**
8
8
  * Name for the component used when initialising using data-module attributes.
9
9
  */
@@ -1,9 +1,9 @@
1
- import { GOVUKFrontendComponent } from "../../govuk-frontend-component.js";
1
+ import { ConfigurableComponent } from "../../common/configuration.js";
2
2
 
3
3
  /**
4
4
  * Notification Banner component
5
5
  */
6
- export class NotificationBanner extends GOVUKFrontendComponent<HTMLElement> {
6
+ export class NotificationBanner extends ConfigurableComponent<NotificationBannerConfig, HTMLElement> {
7
7
  /**
8
8
  * Name for the component used when initialising using data-module attributes.
9
9
  */
@@ -1,9 +1,9 @@
1
- import { GOVUKFrontendComponent } from "../../govuk-frontend-component.js";
1
+ import { ConfigurableComponent } from "../../common/configuration.js";
2
2
 
3
3
  /**
4
4
  * Password input component
5
5
  */
6
- export class PasswordInput extends GOVUKFrontendComponent<HTMLElement> {
6
+ export class PasswordInput extends ConfigurableComponent<PasswordInputConfig, HTMLElement> {
7
7
  /**
8
8
  * Name for the component used when initialising using data-module attributes.
9
9
  */
@@ -8,7 +8,6 @@ import { type PasswordInputConfig } from "./components/password-input/password-i
8
8
 
9
9
  export interface CompatibleClass {
10
10
  new(...args: any[]): any;
11
- defaults?: object;
12
11
  moduleName: string;
13
12
  }
14
13
 
@@ -57,7 +56,9 @@ export interface Config {
57
56
  */
58
57
  export type ConfigKey = keyof Config;
59
58
 
60
- export interface ErrorContext<T extends CompatibleClass> {
59
+ export type ComponentConfig<ComponentClass extends CompatibleClass> = ConstructorParameters<ComponentClass>[1];
60
+
61
+ export interface ErrorContext<ComponentClass extends CompatibleClass> {
61
62
  /**
62
63
  * - Element used for component module initialisation
63
64
  */
@@ -66,17 +67,20 @@ export interface ErrorContext<T extends CompatibleClass> {
66
67
  /**
67
68
  * - Class of component
68
69
  */
69
- component?: T | undefined;
70
+ component?: ComponentClass | undefined;
70
71
 
71
72
  /**
72
73
  * - Config supplied to component
73
74
  */
74
- config: T["defaults"];
75
+ config: ComponentConfig<ComponentClass>;
75
76
  }
76
77
 
77
- export type OnErrorCallback<T extends CompatibleClass> = (error: unknown, context: ErrorContext<T>) => any;
78
+ export type OnErrorCallback<ComponentClass extends CompatibleClass> = (
79
+ error: unknown,
80
+ context: ErrorContext<ComponentClass>,
81
+ ) => any;
78
82
 
79
- export interface CreateAllOptions<T extends CompatibleClass> {
83
+ export interface CreateAllOptions<ComponentClass extends CompatibleClass> {
80
84
  /**
81
85
  * - scope of the document to search within
82
86
  */
@@ -85,7 +89,7 @@ export interface CreateAllOptions<T extends CompatibleClass> {
85
89
  /**
86
90
  * - callback function if error throw by component on init
87
91
  */
88
- onError?: OnErrorCallback<T> | undefined;
92
+ onError?: OnErrorCallback<ComponentClass> | undefined;
89
93
  }
90
94
 
91
95
  /**
@@ -112,14 +116,14 @@ export function initAll(
112
116
  *
113
117
  * Any component errors will be caught and logged to the console.
114
118
  *
115
- * @template {CompatibleClass} T
116
- * @param {T} Component - class of the component to create
117
- * @param {T["defaults"]} [config] - Config supplied to component
118
- * @param {OnErrorCallback<T> | Element | Document | CreateAllOptions<T> } [createAllOptions] - options for createAll including scope of the document to search within and callback function if error throw by component on init
119
- * @returns {Array<InstanceType<T>>} - array of instantiated components
119
+ * @template {CompatibleClass} ComponentClass
120
+ * @param {ComponentClass} Component - class of the component to create
121
+ * @param {ComponentConfig<ComponentClass>} [config] - Config supplied to component
122
+ * @param {OnErrorCallback<ComponentClass> | Element | Document | CreateAllOptions<ComponentClass> } [createAllOptions] - options for createAll including scope of the document to search within and callback function if error throw by component on init
123
+ * @returns {Array<InstanceType<ComponentClass>>} - array of instantiated components
120
124
  */
121
- export function createAll<T extends CompatibleClass>(
122
- Component: T,
123
- config?: T["defaults"],
124
- createAllOptions?: Document | Element | OnErrorCallback<T> | CreateAllOptions<T>,
125
- ): Array<InstanceType<T>>;
125
+ export function createAll<ComponentClass extends CompatibleClass>(
126
+ Component: ComponentClass,
127
+ config?: ComponentConfig<ComponentClass>,
128
+ createAllOptions?: OnErrorCallback<ComponentClass> | Element | Document | CreateAllOptions<ComponentClass>,
129
+ ): Array<InstanceType<ComponentClass>>;
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@types/govuk-frontend",
3
- "version": "5.7.0",
3
+ "version": "5.8.0",
4
4
  "description": "TypeScript definitions for govuk-frontend",
5
5
  "homepage": "https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/govuk-frontend",
6
6
  "license": "MIT",
@@ -32,6 +32,7 @@
32
32
  },
33
33
  "scripts": {},
34
34
  "dependencies": {},
35
- "typesPublisherContentHash": "08d1cc6a671dadd0e0e9c1113ea085b28a6b2510f52991c817bfb8d71bc308ae",
36
- "typeScriptVersion": "4.8"
35
+ "peerDependencies": {},
36
+ "typesPublisherContentHash": "3df1d321f714ae24feef605eab0f6302b12f0717613036605b5de394fb136253",
37
+ "typeScriptVersion": "5.0"
37
38
  }
@@ -1 +0,0 @@
1
- export * from "./normalise-dataset.js";
@@ -1,16 +0,0 @@
1
- import { type ObjectNested, type Schema } from "./index.js";
2
-
3
- /**
4
- * Normalise dataset
5
- *
6
- * Loop over an object and normalise each value using {@link normaliseString},
7
- * optionally expanding nested `i18n.field`
8
- *
9
- * @internal
10
- * @param {{ schema: Schema }} Component - Component class
11
- * @param {DOMStringMap} dataset - HTML element dataset
12
- * @returns {ObjectNested} Normalised dataset
13
- */
14
- export function normaliseDataset(Component: {
15
- schema: Schema;
16
- }, dataset: DOMStringMap): ObjectNested;
@@ -1 +0,0 @@
1
- export * from "./normalise-string.js";
@@ -1,22 +0,0 @@
1
- import { type SchemaProperty } from "./index.js";
2
-
3
- /**
4
- * Normalise string
5
- *
6
- * 'If it looks like a duck, and it quacks like a duck…' 🦆
7
- *
8
- * If the passed value looks like a boolean or a number, convert it to a boolean
9
- * or number.
10
- *
11
- * Designed to be used to convert config passed via data attributes (which are
12
- * always strings) into something sensible.
13
- *
14
- * @internal
15
- * @param {DOMStringMap[string]} value - The value to normalise
16
- * @param {SchemaProperty} [property] - Component schema property
17
- * @returns {string | boolean | number | undefined} Normalised data
18
- */
19
- export function normaliseString(
20
- value: DOMStringMap[string],
21
- property?: SchemaProperty,
22
- ): string | boolean | number | undefined;