@types/govuk-frontend 5.4.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/LICENSE +21 -0
- govuk-frontend/README.md +15 -0
- govuk-frontend/dist/govuk/all.bundle.d.mts +14 -0
- govuk-frontend/dist/govuk/all.bundle.d.ts +39 -0
- govuk-frontend/dist/govuk/all.d.mts +1 -0
- govuk-frontend/dist/govuk/common/closest-attribute-value.d.mts +1 -0
- govuk-frontend/dist/govuk/common/closest-attribute-value.d.ts +9 -0
- govuk-frontend/dist/govuk/common/govuk-frontend-version.d.mts +1 -0
- govuk-frontend/dist/govuk/common/govuk-frontend-version.d.ts +6 -0
- govuk-frontend/dist/govuk/common/index.d.mts +1 -0
- govuk-frontend/dist/govuk/common/index.d.ts +159 -0
- govuk-frontend/dist/govuk/common/normalise-dataset.d.mts +1 -0
- govuk-frontend/dist/govuk/common/normalise-dataset.d.ts +16 -0
- govuk-frontend/dist/govuk/common/normalise-string.d.mts +1 -0
- govuk-frontend/dist/govuk/common/normalise-string.d.ts +22 -0
- govuk-frontend/dist/govuk/components/accordion/accordion.d.mts +1 -0
- govuk-frontend/dist/govuk/components/accordion/accordion.d.ts +120 -0
- govuk-frontend/dist/govuk/components/button/button.d.mts +1 -0
- govuk-frontend/dist/govuk/components/button/button.d.ts +48 -0
- govuk-frontend/dist/govuk/components/character-count/character-count.d.mts +1 -0
- govuk-frontend/dist/govuk/components/character-count/character-count.d.ts +158 -0
- govuk-frontend/dist/govuk/components/checkboxes/checkboxes.d.mts +1 -0
- govuk-frontend/dist/govuk/components/checkboxes/checkboxes.d.ts +27 -0
- govuk-frontend/dist/govuk/components/error-summary/error-summary.d.mts +1 -0
- govuk-frontend/dist/govuk/components/error-summary/error-summary.d.ts +51 -0
- govuk-frontend/dist/govuk/components/exit-this-page/exit-this-page.d.mts +1 -0
- govuk-frontend/dist/govuk/components/exit-this-page/exit-this-page.d.ts +77 -0
- govuk-frontend/dist/govuk/components/header/header.d.mts +1 -0
- govuk-frontend/dist/govuk/components/header/header.d.ts +19 -0
- govuk-frontend/dist/govuk/components/notification-banner/notification-banner.d.mts +1 -0
- govuk-frontend/dist/govuk/components/notification-banner/notification-banner.d.ts +50 -0
- govuk-frontend/dist/govuk/components/password-input/password-input.d.mts +1 -0
- govuk-frontend/dist/govuk/components/password-input/password-input.d.ts +90 -0
- govuk-frontend/dist/govuk/components/radios/radios.d.mts +1 -0
- govuk-frontend/dist/govuk/components/radios/radios.d.ts +27 -0
- govuk-frontend/dist/govuk/components/skip-link/skip-link.d.mts +1 -0
- govuk-frontend/dist/govuk/components/skip-link/skip-link.d.ts +19 -0
- govuk-frontend/dist/govuk/components/tabs/tabs.d.mts +1 -0
- govuk-frontend/dist/govuk/components/tabs/tabs.d.ts +16 -0
- govuk-frontend/dist/govuk/errors/index.d.mts +1 -0
- govuk-frontend/dist/govuk/errors/index.d.ts +83 -0
- govuk-frontend/dist/govuk/govuk-frontend-component.d.mts +1 -0
- govuk-frontend/dist/govuk/govuk-frontend-component.d.ts +9 -0
- govuk-frontend/dist/govuk/i18n.d.mts +1 -0
- govuk-frontend/dist/govuk/i18n.d.ts +211 -0
- govuk-frontend/dist/govuk/init.d.mts +1 -0
- govuk-frontend/dist/govuk/init.d.ts +93 -0
- govuk-frontend/index.d.mts +1 -0
- govuk-frontend/index.d.ts +3 -0
- govuk-frontend/package.json +32 -0
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal support for selecting messages to render, with placeholder
|
|
3
|
+
* interpolation and locale-aware number formatting and pluralisation
|
|
4
|
+
*
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
7
|
+
export class I18n {
|
|
8
|
+
/**
|
|
9
|
+
* Map of plural rules to languages where those rules apply.
|
|
10
|
+
*
|
|
11
|
+
* Note: These groups are named for the most dominant or recognisable language
|
|
12
|
+
* that uses each system. The groupings do not imply that the languages are
|
|
13
|
+
* related to one another. Many languages have evolved the same systems
|
|
14
|
+
* independently of one another.
|
|
15
|
+
*
|
|
16
|
+
* Code to support more languages can be found in the i18n spike:
|
|
17
|
+
* {@link https://github.com/alphagov/govuk-frontend/blob/spike-i18n-support/src/govuk/i18n.mjs}
|
|
18
|
+
*
|
|
19
|
+
* Languages currently supported:
|
|
20
|
+
*
|
|
21
|
+
* Arabic: Arabic (ar)
|
|
22
|
+
* Chinese: Burmese (my), Chinese (zh), Indonesian (id), Japanese (ja),
|
|
23
|
+
* Javanese (jv), Korean (ko), Malay (ms), Thai (th), Vietnamese (vi)
|
|
24
|
+
* French: Armenian (hy), Bangla (bn), French (fr), Gujarati (gu), Hindi (hi),
|
|
25
|
+
* Persian Farsi (fa), Punjabi (pa), Zulu (zu)
|
|
26
|
+
* German: Afrikaans (af), Albanian (sq), Azerbaijani (az), Basque (eu),
|
|
27
|
+
* Bulgarian (bg), Catalan (ca), Danish (da), Dutch (nl), English (en),
|
|
28
|
+
* Estonian (et), Finnish (fi), Georgian (ka), German (de), Greek (el),
|
|
29
|
+
* Hungarian (hu), Luxembourgish (lb), Norwegian (no), Somali (so),
|
|
30
|
+
* Swahili (sw), Swedish (sv), Tamil (ta), Telugu (te), Turkish (tr),
|
|
31
|
+
* Urdu (ur)
|
|
32
|
+
* Irish: Irish Gaelic (ga)
|
|
33
|
+
* Russian: Russian (ru), Ukrainian (uk)
|
|
34
|
+
* Scottish: Scottish Gaelic (gd)
|
|
35
|
+
* Spanish: European Portuguese (pt-PT), Italian (it), Spanish (es)
|
|
36
|
+
* Welsh: Welsh (cy)
|
|
37
|
+
*
|
|
38
|
+
* @internal
|
|
39
|
+
*/
|
|
40
|
+
static pluralRulesMap: {
|
|
41
|
+
[key: string]: string[];
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Different pluralisation rule sets
|
|
46
|
+
*
|
|
47
|
+
* Returns the appropriate suffix for the plural form associated with `n`.
|
|
48
|
+
* Possible suffixes: 'zero', 'one', 'two', 'few', 'many', 'other' (the actual
|
|
49
|
+
* meaning of each differs per locale). 'other' should always exist, even in
|
|
50
|
+
* languages without plurals, such as Chinese.
|
|
51
|
+
* {@link https://cldr.unicode.org/index/cldr-spec/plural-rules}
|
|
52
|
+
*
|
|
53
|
+
* The count must be a positive integer. Negative numbers and decimals aren't accounted for
|
|
54
|
+
*
|
|
55
|
+
* @internal
|
|
56
|
+
*/
|
|
57
|
+
static pluralRules: {
|
|
58
|
+
[key: string]: (count: number) => PluralRule;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* @internal
|
|
63
|
+
* @param {{ [key: string]: string | TranslationPluralForms }} translations - Key-value pairs of the translation strings to use.
|
|
64
|
+
* @param {object} [config] - Configuration options for the function.
|
|
65
|
+
* @param {string | null} [config.locale] - An overriding locale for the PluralRules functionality.
|
|
66
|
+
*/
|
|
67
|
+
constructor(
|
|
68
|
+
translations?: {
|
|
69
|
+
[key: string]: string | TranslationPluralForms;
|
|
70
|
+
},
|
|
71
|
+
config?: {
|
|
72
|
+
locale?: string | null | undefined;
|
|
73
|
+
},
|
|
74
|
+
);
|
|
75
|
+
translations: {
|
|
76
|
+
[key: string]: string | TranslationPluralForms;
|
|
77
|
+
};
|
|
78
|
+
locale: string;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* The most used function - takes the key for a given piece of UI text and
|
|
82
|
+
* returns the appropriate string.
|
|
83
|
+
*
|
|
84
|
+
* @internal
|
|
85
|
+
* @param {string} lookupKey - The lookup key of the string to use.
|
|
86
|
+
* @param {{ [key: string]: unknown }} [options] - Any options passed with the translation string, e.g: for string interpolation.
|
|
87
|
+
* @returns {string} The appropriate translation string.
|
|
88
|
+
* @throws {Error} Lookup key required
|
|
89
|
+
* @throws {Error} Options required for `${}` placeholders
|
|
90
|
+
*/
|
|
91
|
+
t(
|
|
92
|
+
lookupKey: string,
|
|
93
|
+
options?: {
|
|
94
|
+
[key: string]: unknown;
|
|
95
|
+
},
|
|
96
|
+
): string;
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Takes a translation string with placeholders, and replaces the placeholders
|
|
100
|
+
* with the provided data
|
|
101
|
+
*
|
|
102
|
+
* @internal
|
|
103
|
+
* @param {string} translationString - The translation string
|
|
104
|
+
* @param {{ [key: string]: unknown }} options - Any options passed with the translation string, e.g: for string interpolation.
|
|
105
|
+
* @returns {string} The translation string to output, with $\{\} placeholders replaced
|
|
106
|
+
*/
|
|
107
|
+
replacePlaceholders(translationString: string, options: {
|
|
108
|
+
[key: string]: unknown;
|
|
109
|
+
}): string;
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Check to see if the browser supports Intl.PluralRules
|
|
113
|
+
*
|
|
114
|
+
* It requires all conditions to be met in order to be supported:
|
|
115
|
+
* - The implementation of Intl supports PluralRules (NOT true in Safari 10–12)
|
|
116
|
+
* - The browser/OS has plural rules for the current locale (browser dependent)
|
|
117
|
+
*
|
|
118
|
+
* {@link https://browsersl.ist/#q=supports+es6-module+and+not+supports+intl-pluralrules}
|
|
119
|
+
*
|
|
120
|
+
* @internal
|
|
121
|
+
* @returns {boolean} Returns true if all conditions are met. Returns false otherwise.
|
|
122
|
+
*/
|
|
123
|
+
hasIntlPluralRulesSupport(): boolean;
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Get the appropriate suffix for the plural form.
|
|
127
|
+
*
|
|
128
|
+
* Uses Intl.PluralRules (or our own fallback implementation) to get the
|
|
129
|
+
* 'preferred' form to use for the given count.
|
|
130
|
+
*
|
|
131
|
+
* Checks that a translation has been provided for that plural form – if it
|
|
132
|
+
* hasn't, it'll fall back to the 'other' plural form (unless that doesn't exist
|
|
133
|
+
* either, in which case an error will be thrown)
|
|
134
|
+
*
|
|
135
|
+
* @internal
|
|
136
|
+
* @param {string} lookupKey - The lookup key of the string to use.
|
|
137
|
+
* @param {number} count - Number used to determine which pluralisation to use.
|
|
138
|
+
* @returns {PluralRule} The suffix associated with the correct pluralisation for this locale.
|
|
139
|
+
* @throws {Error} Plural form `.other` required when preferred plural form is missing
|
|
140
|
+
*/
|
|
141
|
+
getPluralSuffix(lookupKey: string, count: number): PluralRule;
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Get the plural form using our fallback implementation
|
|
145
|
+
*
|
|
146
|
+
* This is split out into a separate function to make it easier to test the
|
|
147
|
+
* fallback behaviour in an environment where Intl.PluralRules exists.
|
|
148
|
+
*
|
|
149
|
+
* @internal
|
|
150
|
+
* @param {number} count - Number used to determine which pluralisation to use.
|
|
151
|
+
* @returns {PluralRule} The pluralisation form for count in this locale.
|
|
152
|
+
*/
|
|
153
|
+
selectPluralFormUsingFallbackRules(count: number): PluralRule;
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Work out which pluralisation rules to use for the current locale
|
|
157
|
+
*
|
|
158
|
+
* The locale may include a regional indicator (such as en-GB), but we don't
|
|
159
|
+
* usually care about this part, as pluralisation rules are usually the same
|
|
160
|
+
* regardless of region. There are exceptions, however, (e.g. Portuguese) so
|
|
161
|
+
* this searches by both the full and shortened locale codes, just to be sure.
|
|
162
|
+
*
|
|
163
|
+
* @internal
|
|
164
|
+
* @returns {string | undefined} The name of the pluralisation rule to use (a key for one
|
|
165
|
+
* of the functions in this.pluralRules)
|
|
166
|
+
*/
|
|
167
|
+
getPluralRulesForLocale(): string | undefined;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Plural rule category mnemonic tags
|
|
172
|
+
*/
|
|
173
|
+
export type PluralRule = "zero" | "one" | "two" | "few" | "many" | "other";
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Translated message by plural rule they correspond to.
|
|
177
|
+
*
|
|
178
|
+
* Allows to group pluralised messages under a single key when passing
|
|
179
|
+
* translations to a component's constructor
|
|
180
|
+
*/
|
|
181
|
+
export interface TranslationPluralForms {
|
|
182
|
+
/**
|
|
183
|
+
* - General plural form
|
|
184
|
+
*/
|
|
185
|
+
other?: string | undefined;
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* - Plural form used with 0
|
|
189
|
+
*/
|
|
190
|
+
zero?: string | undefined;
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* - Plural form used with 1
|
|
194
|
+
*/
|
|
195
|
+
one?: string | undefined;
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* - Plural form used with 2
|
|
199
|
+
*/
|
|
200
|
+
two?: string | undefined;
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* - Plural form used for a few
|
|
204
|
+
*/
|
|
205
|
+
few?: string | undefined;
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* - Plural form used for many
|
|
209
|
+
*/
|
|
210
|
+
many?: string | undefined;
|
|
211
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./init.js";
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { type AccordionConfig } from "./components/accordion/accordion.js";
|
|
2
|
+
import { type ButtonConfig } from "./components/button/button.js";
|
|
3
|
+
import { type CharacterCountConfig } from "./components/character-count/character-count.js";
|
|
4
|
+
import { type ErrorSummaryConfig } from "./components/error-summary/error-summary.js";
|
|
5
|
+
import { type ExitThisPageConfig } from "./components/exit-this-page/exit-this-page.js";
|
|
6
|
+
import { type NotificationBannerConfig } from "./components/notification-banner/notification-banner.js";
|
|
7
|
+
import { type PasswordInputConfig } from "./components/password-input/password-input.js";
|
|
8
|
+
|
|
9
|
+
export interface CompatibleClass {
|
|
10
|
+
new(...args: any[]): any;
|
|
11
|
+
defaults?: object;
|
|
12
|
+
moduleName: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Config for all components via `initAll()`
|
|
17
|
+
*/
|
|
18
|
+
export interface Config {
|
|
19
|
+
/**
|
|
20
|
+
* - Accordion config
|
|
21
|
+
*/
|
|
22
|
+
accordion?: AccordionConfig | undefined;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* - Button config
|
|
26
|
+
*/
|
|
27
|
+
button?: ButtonConfig | undefined;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* - Character Count config
|
|
31
|
+
*/
|
|
32
|
+
characterCount?: CharacterCountConfig | undefined;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* - Error Summary config
|
|
36
|
+
*/
|
|
37
|
+
errorSummary?: ErrorSummaryConfig | undefined;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* - Exit This Page config
|
|
41
|
+
*/
|
|
42
|
+
exitThisPage?: ExitThisPageConfig | undefined;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* - Notification Banner config
|
|
46
|
+
*/
|
|
47
|
+
notificationBanner?: NotificationBannerConfig | undefined;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* - Password input config
|
|
51
|
+
*/
|
|
52
|
+
passwordInput?: PasswordInputConfig | undefined;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Component config keys, e.g. `accordion` and `characterCount`
|
|
57
|
+
*/
|
|
58
|
+
export type ConfigKey = keyof Config;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Initialise all components
|
|
62
|
+
*
|
|
63
|
+
* Use the `data-module` attributes to find, instantiate and init all of the
|
|
64
|
+
* components provided as part of GOV.UK Frontend.
|
|
65
|
+
*
|
|
66
|
+
* @param {Config & { scope?: Element }} [config] - Config for all components (with optional scope)
|
|
67
|
+
*/
|
|
68
|
+
export function initAll(
|
|
69
|
+
config?: Config & {
|
|
70
|
+
scope?: Element;
|
|
71
|
+
},
|
|
72
|
+
): void;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Create all instances of a specific component on the page
|
|
76
|
+
*
|
|
77
|
+
* Uses the `data-module` attribute to find all elements matching the specified
|
|
78
|
+
* component on the page, creating instances of the component object for each
|
|
79
|
+
* of them.
|
|
80
|
+
*
|
|
81
|
+
* Any component errors will be caught and logged to the console.
|
|
82
|
+
*
|
|
83
|
+
* @template {CompatibleClass} T
|
|
84
|
+
* @param {T} Component - class of the component to create
|
|
85
|
+
* @param {T["defaults"]} [config] - config for the component
|
|
86
|
+
* @param {Element|Document} [$scope] - scope of the document to search within
|
|
87
|
+
* @returns {Array<InstanceType<T>>} - array of instantiated components
|
|
88
|
+
*/
|
|
89
|
+
export function createAll<T extends CompatibleClass>(
|
|
90
|
+
Component: T,
|
|
91
|
+
config?: T["defaults"],
|
|
92
|
+
$scope?: Document | Element,
|
|
93
|
+
): Array<InstanceType<T>>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./dist/govuk/all.mjs";
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@types/govuk-frontend",
|
|
3
|
+
"version": "5.4.0",
|
|
4
|
+
"description": "TypeScript definitions for govuk-frontend",
|
|
5
|
+
"homepage": "https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/govuk-frontend",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"contributors": [
|
|
8
|
+
{
|
|
9
|
+
"name": "Colin Rotherham",
|
|
10
|
+
"githubUsername": "colinrotherham",
|
|
11
|
+
"url": "https://github.com/colinrotherham"
|
|
12
|
+
}
|
|
13
|
+
],
|
|
14
|
+
"main": "",
|
|
15
|
+
"types": "index.d.ts",
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"import": "./dist/govuk/all.d.mts",
|
|
19
|
+
"require": "./dist/govuk/all.bundle.d.ts"
|
|
20
|
+
},
|
|
21
|
+
"./package.json": "./package.json"
|
|
22
|
+
},
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "https://github.com/DefinitelyTyped/DefinitelyTyped.git",
|
|
26
|
+
"directory": "types/govuk-frontend"
|
|
27
|
+
},
|
|
28
|
+
"scripts": {},
|
|
29
|
+
"dependencies": {},
|
|
30
|
+
"typesPublisherContentHash": "1f43b1eee3d40d868c5033c6e7cf085eebe98e8a973c98c717ad4d6b325c6f7a",
|
|
31
|
+
"typeScriptVersion": "4.8"
|
|
32
|
+
}
|