@communitiesuk/svelte-component-library 0.1.17 → 0.2.0-alpha.2

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.
Files changed (97) hide show
  1. package/README.md +116 -98
  2. package/dist/assets/css/base.css +9 -0
  3. package/dist/assets/css/code-block.css +116 -0
  4. package/dist/assets/css/components.css +47 -0
  5. package/dist/assets/css/fonts.css +19 -0
  6. package/dist/assets/css/govuk-additional.css +142 -0
  7. package/dist/assets/css/govuk-frontend.min.css +2 -2
  8. package/dist/assets/css/moduk.css +1 -0
  9. package/dist/assets/css/moj-frontend.min copy.css +4108 -0
  10. package/dist/assets/css/moj-frontend.min.css +2 -0
  11. package/dist/assets/css/moj-frontend.min.css.map +1 -0
  12. package/dist/assets/css/utilities.css +0 -0
  13. package/dist/assets/images/govuk-crest.svg +1 -1
  14. package/dist/assets/js/govuk-frontend.min.js +1 -0
  15. package/dist/assets/js/moj-frontend.min.js +1 -0
  16. package/dist/assets/rebrand/images/favicon.ico +0 -0
  17. package/dist/assets/rebrand/images/favicon.svg +1 -0
  18. package/dist/assets/rebrand/images/govuk-crest.svg +1 -0
  19. package/dist/assets/rebrand/images/govuk-icon-180.png +0 -0
  20. package/dist/assets/rebrand/images/govuk-icon-192.png +0 -0
  21. package/dist/assets/rebrand/images/govuk-icon-512.png +0 -0
  22. package/dist/assets/rebrand/images/govuk-icon-mask.svg +1 -0
  23. package/dist/assets/rebrand/images/govuk-opengraph-image.png +0 -0
  24. package/dist/assets/rebrand/manifest.json +39 -0
  25. package/dist/components/data-vis/line-chart/Line.svelte +48 -41
  26. package/dist/components/data-vis/line-chart/Line.svelte.d.ts +6 -4
  27. package/dist/components/data-vis/line-chart/LineChart.svelte +145 -36
  28. package/dist/components/data-vis/line-chart/LineChart.svelte.d.ts +25 -9
  29. package/dist/components/data-vis/line-chart/Lines.svelte +10 -23
  30. package/dist/components/data-vis/line-chart/Lines.svelte.d.ts +8 -4
  31. package/dist/components/data-vis/line-chart/Marker.svelte +31 -5
  32. package/dist/components/data-vis/line-chart/Marker.svelte.d.ts +6 -2
  33. package/dist/components/data-vis/line-chart/SeriesLabel.svelte +7 -8
  34. package/dist/components/data-vis/line-chart/SeriesLabel.svelte.d.ts +2 -2
  35. package/dist/components/data-vis/line-chart/ValueLabel.svelte +26 -34
  36. package/dist/components/data-vis/line-chart/ValueLabel.svelte.d.ts +8 -4
  37. package/dist/components/data-vis/map/Map.svelte +299 -71
  38. package/dist/components/data-vis/map/Map.svelte.d.ts +39 -12
  39. package/dist/components/data-vis/map/NonStandardControls.svelte +10 -1
  40. package/dist/components/data-vis/map/NonStandardControls.svelte.d.ts +12 -11
  41. package/dist/components/data-vis/map/Tooltip.svelte +3 -4
  42. package/dist/components/data-vis/map/Tooltip.svelte.d.ts +0 -2
  43. package/dist/components/data-vis/map/mapUtils.d.ts +2 -0
  44. package/dist/components/data-vis/map/mapUtils.js +50 -0
  45. package/dist/components/data-vis/table/Table.svelte +28 -40
  46. package/dist/components/data-vis/table/Table.svelte.d.ts +0 -2
  47. package/dist/components/layout/Breadcrumbs.svelte +10 -12
  48. package/dist/components/layout/Breadcrumbs.svelte.d.ts +1 -0
  49. package/dist/components/layout/Footer.svelte +69 -4
  50. package/dist/components/layout/Footer.svelte.d.ts +3 -0
  51. package/dist/components/layout/Header.svelte +56 -16
  52. package/dist/components/layout/Header.svelte.d.ts +1 -0
  53. package/dist/components/layout/InternalHeader.svelte +155 -150
  54. package/dist/components/layout/InternalHeader.svelte.d.ts +1 -0
  55. package/dist/components/ui/Button.svelte +78 -4
  56. package/dist/components/ui/Button.svelte.d.ts +2 -0
  57. package/dist/components/ui/CookieBanner.svelte +356 -0
  58. package/dist/components/ui/CookieBanner.svelte.d.ts +18 -0
  59. package/dist/components/ui/FilterPanel.svelte +167 -158
  60. package/dist/components/ui/FilterPanel.svelte.d.ts +2 -0
  61. package/dist/components/ui/Masthead.svelte +35 -23
  62. package/dist/components/ui/Masthead.svelte.d.ts +2 -0
  63. package/dist/components/ui/PostcodeOrAreaSearch.svelte +200 -0
  64. package/dist/components/ui/PostcodeOrAreaSearch.svelte.d.ts +37 -0
  65. package/dist/components/ui/Search.svelte +2 -2
  66. package/dist/components/ui/SearchAutocomplete.svelte +104 -14
  67. package/dist/components/ui/SearchAutocomplete.svelte.d.ts +4 -0
  68. package/dist/data/IMD2019.json +32846 -0
  69. package/dist/data/places.csv +20039 -0
  70. package/dist/data/places.json +100192 -0
  71. package/dist/data/svgFontDimensions.json +90 -0
  72. package/dist/data/testData.json +52632 -0
  73. package/dist/index.d.ts +2 -0
  74. package/dist/index.js +2 -0
  75. package/dist/package-wrapping/BaseInformation.svelte +0 -33
  76. package/dist/package-wrapping/SidebarContainer.svelte +0 -7
  77. package/dist/utils/area-search/geoConfig.d.ts +435 -0
  78. package/dist/utils/area-search/geoConfig.js +291 -0
  79. package/dist/utils/cookiesNavigation.d.ts +44 -0
  80. package/dist/utils/cookiesNavigation.js +63 -0
  81. package/dist/utils/data-transformations/convert-csv-to-json-proper.cjs +88 -0
  82. package/dist/utils/data-transformations/convert-csv-to-json-proper.d.cts +1 -0
  83. package/dist/utils/data-transformations/convertCSV.d.ts +6 -0
  84. package/dist/utils/data-transformations/convertCSV.js +40 -21
  85. package/dist/utils/text-string-conversion/textStringConversion.d.ts +6 -0
  86. package/dist/utils/text-string-conversion/textStringConversion.js +10 -0
  87. package/package.json +18 -7
  88. package/dist/components/ui/Breadcrumbs.svelte +0 -198
  89. package/dist/components/ui/Breadcrumbs.svelte.d.ts +0 -24
  90. package/dist/components/ui/Footer.svelte +0 -171
  91. package/dist/components/ui/Footer.svelte.d.ts +0 -30
  92. package/dist/components/ui/Header.svelte +0 -43
  93. package/dist/components/ui/Header.svelte.d.ts +0 -7
  94. package/dist/components/ui/ServiceNavigation.svelte +0 -143
  95. package/dist/components/ui/ServiceNavigation.svelte.d.ts +0 -13
  96. package/dist/components/ui/SideNavigation.svelte +0 -346
  97. package/dist/components/ui/SideNavigation.svelte.d.ts +0 -25
@@ -0,0 +1,291 @@
1
+ /* eslint-disable @typescript-eslint/ban-ts-comment */
2
+ // @ts-nocheck
3
+ export const geoNames = {
4
+ W04: { label: 'community', plural: 'communities', childGroup: true },
5
+ E06: { label: 'unitary authority', plural: 'unitary authorities' },
6
+ W06: { label: 'unitary authority', plural: 'unitary authorities', childGroup: true },
7
+ E07: {
8
+ label: 'non-metropolitan district',
9
+ plural: 'non-metropolitan districts',
10
+ childGroup: true
11
+ },
12
+ E08: { label: 'metropolitan district', plural: 'metropolitan districts' },
13
+ E09: { label: 'borough', plural: 'boroughs', childGroup: true },
14
+ E10: { label: 'county', plural: 'counties' },
15
+ E11: { label: 'metropolitan county', plural: 'metropolital counties' },
16
+ S12: { label: 'council area', plural: 'council areas', childGroup: true },
17
+ N09: {
18
+ label: 'local government district',
19
+ plural: 'local government districts',
20
+ childGroup: true
21
+ }
22
+ };
23
+ export const sources = [
24
+ { id: 'uk', type: 'geojson' },
25
+ { id: 'ctry', type: 'geojson' },
26
+ { id: 'rgn', type: 'geojson' },
27
+ {
28
+ id: 'la',
29
+ type: 'vector',
30
+ url: 'https://cdn.ons.gov.uk/maptiles/administrative/2024/authorities-all/v1/boundaries/{z}/{x}/{y}.pbf',
31
+ layer: 'boundaries',
32
+ minzoom: 4
33
+ },
34
+ {
35
+ id: 'wpc',
36
+ type: 'vector',
37
+ url: 'https://cdn.ons.gov.uk/maptiles/administrative/2024/wpc/v1/boundaries/{z}/{x}/{y}.pbf',
38
+ layer: 'boundaries',
39
+ minzoom: 4
40
+ },
41
+ {
42
+ id: 'sener',
43
+ type: 'vector',
44
+ url: 'https://cdn.ons.gov.uk/maptiles/administrative/2022/sen/v1/boundaries/{z}/{x}/{y}.pbf',
45
+ layer: 'region'
46
+ },
47
+ {
48
+ id: 'senc',
49
+ type: 'vector',
50
+ url: 'https://cdn.ons.gov.uk/maptiles/administrative/2022/sen/v1/boundaries/{z}/{x}/{y}.pbf',
51
+ layer: 'constituency'
52
+ },
53
+ {
54
+ id: 'wd',
55
+ type: 'vector',
56
+ url: 'https://cdn.ons.gov.uk/maptiles/administrative/2024/wd/v1/boundaries/{z}/{x}/{y}.pbf',
57
+ layer: 'boundaries',
58
+ minzoom: 6
59
+ },
60
+ {
61
+ id: 'par',
62
+ type: 'vector',
63
+ url: 'https://cdn.ons.gov.uk/maptiles/administrative/2022/par/v1/boundaries/{z}/{x}/{y}.pbf',
64
+ layer: 'par',
65
+ minzoom: 6
66
+ },
67
+ {
68
+ id: 'msoa',
69
+ type: 'vector',
70
+ url: 'https://cdn.ons.gov.uk/maptiles/administrative/2021/msoa/v2/boundaries/{z}/{x}/{y}.pbf',
71
+ layer: 'msoa',
72
+ minzoom: 6
73
+ },
74
+ {
75
+ id: 'lsoa',
76
+ type: 'vector',
77
+ url: 'https://cdn.ons.gov.uk/maptiles/administrative/2021/lsoa/v2/boundaries/{z}/{x}/{y}.pbf',
78
+ layer: 'lsoa',
79
+ minzoom: 7
80
+ },
81
+ {
82
+ id: 'oa',
83
+ type: 'vector',
84
+ url: 'https://cdn.ons.gov.uk/maptiles/administrative/2021/oa/v2/boundaries/{z}/{x}/{y}.pbf',
85
+ layer: 'oa',
86
+ minzoom: 8
87
+ }
88
+ ];
89
+ const notInTypes = (cds) => cds.map((cd) => ['!', ['in', cd, ['get', 'areacd']]]);
90
+ export const geoTypes = [
91
+ {
92
+ key: 'uk',
93
+ codes: ['K02'],
94
+ source: 'uk',
95
+ label: 'United Kingdom',
96
+ plural: 'United Kingdom',
97
+ index: true
98
+ },
99
+ {
100
+ key: 'ctry',
101
+ alt: 'country',
102
+ codes: ['E92', 'S92', 'N92', 'W92'],
103
+ pcio: 'country',
104
+ label: 'country',
105
+ plural: 'countries',
106
+ source: 'ctry',
107
+ index: true,
108
+ ess: true
109
+ },
110
+ {
111
+ key: 'rgn',
112
+ alt: 'region',
113
+ codes: ['E12'],
114
+ pcio: 'region',
115
+ label: 'region',
116
+ plural: 'regions',
117
+ source: 'rgn',
118
+ index: true,
119
+ ess: true
120
+ },
121
+ {
122
+ key: 'cauth',
123
+ alt: 'combined',
124
+ codes: ['E06', 'E09', 'E10', 'E47', 'N09', 'S12', 'W06'],
125
+ label: 'upper-tier/combined authority',
126
+ plural: 'upper-tier/combined authorities',
127
+ source: 'la',
128
+ filter: ['all', ...notInTypes(['E07', 'E08']), ['!', ['==', ['get', 'cauth'], 'true']]],
129
+ index: true,
130
+ ess: true
131
+ },
132
+ {
133
+ key: 'utla',
134
+ alt: 'upper',
135
+ codes: ['E06', 'E08', 'E09', 'E10', 'N09', 'S12', 'W06'],
136
+ pcio: 'admin_county',
137
+ label: 'upper-tier/unitary authority',
138
+ plural: 'upper-tier/unitary authorities',
139
+ source: 'la',
140
+ filter: ['all', ...notInTypes(['E07', 'E47'])],
141
+ index: true,
142
+ ess: true
143
+ },
144
+ {
145
+ key: 'ltla',
146
+ alt: 'lower',
147
+ codes: ['E06', 'E07', 'E08', 'E09', 'N09', 'S12', 'W06'],
148
+ pcio: 'admin_district',
149
+ label: 'lower-tier/unitary authority',
150
+ plural: 'lower-tier/unitary authorities',
151
+ source: 'la',
152
+ filter: ['all', ...notInTypes(['E10', 'E47'])],
153
+ index: true,
154
+ ess: true
155
+ },
156
+ {
157
+ key: 'wpc',
158
+ codes: ['E14', 'N05', 'N06', 'S14', 'W07'],
159
+ pcio: 'parliamentary_constituency',
160
+ label: 'parliamentary constituency',
161
+ plural: 'parliamentary constituencies',
162
+ source: 'wpc',
163
+ index: true
164
+ },
165
+ {
166
+ key: 'sener',
167
+ codes: ['W10'],
168
+ label: 'Senedd electoral region',
169
+ plural: 'Senedd electoral regions',
170
+ source: 'sener',
171
+ index: true
172
+ },
173
+ {
174
+ key: 'senc',
175
+ codes: ['W09'],
176
+ label: 'Senedd constituency',
177
+ plural: 'Senedd constituencies',
178
+ source: 'senc',
179
+ index: true
180
+ },
181
+ {
182
+ key: 'wd',
183
+ codes: ['E05', 'W05'],
184
+ pcio: 'admin_ward',
185
+ label: 'ward',
186
+ plural: 'wards',
187
+ source: 'wd'
188
+ },
189
+ {
190
+ key: 'par',
191
+ codes: ['E04', 'W04'],
192
+ pcio: 'parish',
193
+ label: 'parish',
194
+ plural: 'parishes',
195
+ source: 'par'
196
+ },
197
+ {
198
+ key: 'msoa',
199
+ codes: ['E02', 'W02'],
200
+ pcio: 'msoa',
201
+ label: 'MSOA',
202
+ plural: 'MSOAs',
203
+ source: 'msoa'
204
+ },
205
+ {
206
+ key: 'lsoa',
207
+ codes: ['E01', 'W01'],
208
+ pcio: 'lsoa',
209
+ label: 'LSOA',
210
+ plural: 'LSOAs',
211
+ source: 'lsoa'
212
+ },
213
+ {
214
+ key: 'oa',
215
+ codes: ['E00', 'W00'],
216
+ label: 'output area',
217
+ plural: 'output areas',
218
+ source: 'oa'
219
+ }
220
+ ];
221
+ export const geoTypeMap = (() => {
222
+ const map = {};
223
+ geoTypes.filter((s) => s.alt).forEach((s) => (map[s.alt] = s.key));
224
+ return map;
225
+ })();
226
+ export const oldGeoCodesLookup = {
227
+ E06000048: 'E06000057',
228
+ E08000020: 'E08000037',
229
+ E07000097: 'E07000242',
230
+ E07000100: 'E07000240',
231
+ E07000101: 'E07000243',
232
+ E07000104: 'E07000241'
233
+ };
234
+ export const noIndex = Array.from(new Set(geoTypes
235
+ .filter((t) => !t.index)
236
+ .map((t) => t.codes)
237
+ .flat()));
238
+ export const essGeocodes = Array.from(new Set(geoTypes
239
+ .filter((t) => t.ess)
240
+ .map((t) => t.codes)
241
+ .flat()));
242
+ export const mapSources = sources.map((s) => {
243
+ return {
244
+ ...s,
245
+ layers: geoTypes.filter((l) => l.source === s.id)
246
+ };
247
+ });
248
+ export const geoCodesLookup = (() => {
249
+ const lkp = {};
250
+ for (const g of geoTypes) {
251
+ for (const c of g.codes) {
252
+ lkp[c] = { ...g };
253
+ const geoName = geoNames[c];
254
+ if (geoName?.childGroup) {
255
+ lkp[c].label = geoName.label;
256
+ lkp[c].plural = geoName.plural;
257
+ }
258
+ }
259
+ }
260
+ return lkp;
261
+ })();
262
+ export const geoTypesLookup = (() => {
263
+ const lkp = {};
264
+ for (const g of geoTypes)
265
+ lkp[g.key] = g;
266
+ return lkp;
267
+ })();
268
+ export const countryLookup = {
269
+ E92000001: 'England',
270
+ N92000002: 'Northern Ireland',
271
+ S92000003: 'Scotland',
272
+ W92000004: 'Wales'
273
+ };
274
+ export const regionLookup = {
275
+ E12000001: 'North East',
276
+ E12000002: 'North West',
277
+ E12000003: 'Yorkshire and The Humber',
278
+ E12000004: 'East Midlands',
279
+ E12000005: 'West Midlands',
280
+ E12000006: 'East of England',
281
+ E12000007: 'London',
282
+ E12000008: 'South East',
283
+ E12000009: 'South West',
284
+ ...countryLookup
285
+ };
286
+ export const regionReverseLookup = (() => {
287
+ const lkp = {};
288
+ for (const key of Object.keys(regionLookup))
289
+ lkp[regionLookup[key]] = key;
290
+ return lkp;
291
+ })();
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Navigate to cookies page while preserving current URL
3
+ *
4
+ * This function handles navigation to the cookies page while preserving the current URL
5
+ * in sessionStorage for potential return navigation. In demo mode, it prevents navigation
6
+ * to avoid disrupting the demo experience.
7
+ *
8
+ * @param event - The navigation event (typically a click event from a link)
9
+ * @param demoMode - Whether the component is in demo mode (defaults to false)
10
+ * When true, prevents navigation and calls preventDefault()
11
+ * @returns void
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * // Basic usage
16
+ * handleCookiesNavigation(clickEvent);
17
+ *
18
+ * // With demo mode enabled
19
+ * handleCookiesNavigation(clickEvent, true);
20
+ * ```
21
+ */
22
+ export declare function handleCookiesNavigation(event: Event, demoMode?: boolean): void;
23
+ /**
24
+ * Create the cookies page URL with current query parameters
25
+ *
26
+ * This function generates a URL for the cookies page that preserves any query parameters
27
+ * from the current page. This ensures that user context (like filters, search terms, etc.)
28
+ * is maintained when navigating to the cookies page.
29
+ *
30
+ * @param cookiesPageUrl - The base URL for the cookies page (defaults to "/cookies-page")
31
+ * @returns The cookies page URL with current query parameters appended
32
+ *
33
+ * @example
34
+ * ```typescript
35
+ * // Using default cookies page URL
36
+ * const url = createCookiesUrl();
37
+ * // Returns: "/cookies-page?param1=value1&param2=value2" (if current page has those params)
38
+ *
39
+ * // Using custom cookies page URL
40
+ * const customUrl = createCookiesUrl("/custom-cookies");
41
+ * // Returns: "/custom-cookies?param1=value1&param2=value2"
42
+ * ```
43
+ */
44
+ export declare function createCookiesUrl(cookiesPageUrl?: string): string;
@@ -0,0 +1,63 @@
1
+ import { browser } from "$app/environment";
2
+ /**
3
+ * Navigate to cookies page while preserving current URL
4
+ *
5
+ * This function handles navigation to the cookies page while preserving the current URL
6
+ * in sessionStorage for potential return navigation. In demo mode, it prevents navigation
7
+ * to avoid disrupting the demo experience.
8
+ *
9
+ * @param event - The navigation event (typically a click event from a link)
10
+ * @param demoMode - Whether the component is in demo mode (defaults to false)
11
+ * When true, prevents navigation and calls preventDefault()
12
+ * @returns void
13
+ *
14
+ * @example
15
+ * ```typescript
16
+ * // Basic usage
17
+ * handleCookiesNavigation(clickEvent);
18
+ *
19
+ * // With demo mode enabled
20
+ * handleCookiesNavigation(clickEvent, true);
21
+ * ```
22
+ */
23
+ export function handleCookiesNavigation(event, demoMode = false) {
24
+ if (!browser)
25
+ return;
26
+ if (demoMode) {
27
+ // In demo mode, prevent navigation
28
+ event.preventDefault();
29
+ return;
30
+ }
31
+ // Store the current URL in sessionStorage
32
+ sessionStorage.setItem("previousUrl", window.location.href);
33
+ // Let the normal link navigation proceed
34
+ // SvelteKit will handle the navigation
35
+ }
36
+ /**
37
+ * Create the cookies page URL with current query parameters
38
+ *
39
+ * This function generates a URL for the cookies page that preserves any query parameters
40
+ * from the current page. This ensures that user context (like filters, search terms, etc.)
41
+ * is maintained when navigating to the cookies page.
42
+ *
43
+ * @param cookiesPageUrl - The base URL for the cookies page (defaults to "/cookies-page")
44
+ * @returns The cookies page URL with current query parameters appended
45
+ *
46
+ * @example
47
+ * ```typescript
48
+ * // Using default cookies page URL
49
+ * const url = createCookiesUrl();
50
+ * // Returns: "/cookies-page?param1=value1&param2=value2" (if current page has those params)
51
+ *
52
+ * // Using custom cookies page URL
53
+ * const customUrl = createCookiesUrl("/custom-cookies");
54
+ * // Returns: "/custom-cookies?param1=value1&param2=value2"
55
+ * ```
56
+ */
57
+ export function createCookiesUrl(cookiesPageUrl = "/cookies-page") {
58
+ if (!browser)
59
+ return cookiesPageUrl;
60
+ const currentUrl = new URL(window.location.href);
61
+ const searchParams = currentUrl.search;
62
+ return cookiesPageUrl + searchParams;
63
+ }
@@ -0,0 +1,88 @@
1
+ const fs = require("fs");
2
+ const path = require("path");
3
+
4
+ // Read the CSV file
5
+ const csvPath = "static/data/places.csv";
6
+ const csvContent = fs.readFileSync(csvPath, "utf8");
7
+
8
+ // Proper CSV parser that handles quoted fields
9
+ function parseCSV(text) {
10
+ const lines = text.trim().split("\n");
11
+ const headers = parseCSVLine(lines[0]);
12
+ const data = [];
13
+
14
+ for (let i = 1; i < lines.length; i++) {
15
+ const values = parseCSVLine(lines[i]);
16
+ if (values.length === headers.length) {
17
+ const obj = {};
18
+ headers.forEach((header, index) => {
19
+ obj[header.trim()] = values[index].trim();
20
+ });
21
+ data.push(obj);
22
+ }
23
+ }
24
+
25
+ return data;
26
+ }
27
+
28
+ // Parse a single CSV line handling quoted fields
29
+ function parseCSVLine(line) {
30
+ const result = [];
31
+ let current = "";
32
+ let inQuotes = false;
33
+
34
+ for (let i = 0; i < line.length; i++) {
35
+ const char = line[i];
36
+
37
+ if (char === '"') {
38
+ if (inQuotes && line[i + 1] === '"') {
39
+ // Escaped quote
40
+ current += '"';
41
+ i++; // Skip next quote
42
+ } else {
43
+ // Toggle quote mode
44
+ inQuotes = !inQuotes;
45
+ }
46
+ } else if (char === "," && !inQuotes) {
47
+ // End of field
48
+ result.push(current);
49
+ current = "";
50
+ } else {
51
+ current += char;
52
+ }
53
+ }
54
+
55
+ // Don't forget the last field
56
+ result.push(current);
57
+
58
+ return result;
59
+ }
60
+
61
+ // Parse the CSV
62
+ const data = parseCSV(csvContent);
63
+
64
+ // Ensure the lib data directory exists
65
+ const outputDir = "src/lib/data";
66
+ if (!fs.existsSync(outputDir)) {
67
+ fs.mkdirSync(outputDir, { recursive: true });
68
+ }
69
+
70
+ // Write JSON file
71
+ const outputPath = path.join(outputDir, "places.json");
72
+ fs.writeFileSync(outputPath, JSON.stringify(data, null, 2));
73
+
74
+ console.log(`Converted ${data.length} records from CSV to JSON`);
75
+ console.log(`Output: ${outputPath}`);
76
+
77
+ // Show a few examples to verify
78
+ console.log("\nFirst few records:");
79
+ console.log(data.slice(0, 5));
80
+
81
+ // Check for any records that might have quotes in the name
82
+ const recordsWithQuotes = data.filter(
83
+ (r) => r.areanm && r.areanm.includes('"'),
84
+ );
85
+ console.log(`\nRecords with quotes in name: ${recordsWithQuotes.length}`);
86
+ if (recordsWithQuotes.length > 0) {
87
+ console.log("Examples:", recordsWithQuotes.slice(0, 3));
88
+ }
@@ -1,2 +1,8 @@
1
1
  export function convertToCSV(array: any): string;
2
2
  export function csvToArrayOfObjects(csv: any): any;
3
+ /**
4
+ * Fetches and parses a CSV file from a URL
5
+ * @param {string} url - The URL of the CSV file to fetch
6
+ * @returns {Promise<Array<Object>>} Promise that resolves to array of objects
7
+ */
8
+ export function getCSV(url: string): Promise<Array<any>>;
@@ -1,22 +1,41 @@
1
1
  export function convertToCSV(array) {
2
- if (!array.length) return '';
3
-
4
- const header = Object.keys(array[0]).join(', '); // Add space after commas in header
5
- const rows = array.map((obj) => Object.values(obj).join(', ')); // Add space after commas in rows
6
-
7
- return [header, ...rows].join('\n');
8
- }
9
-
10
- export function csvToArrayOfObjects(csv) {
11
- const lines = csv.split('\n').filter((line) => line.trim() !== ''); // Split into lines and remove empty ones
12
- const [headerLine, ...dataLines] = lines; // Separate header from data
13
- const headers = headerLine.split(',').map((header) => header.trim()); // Split header into keys and trim spaces
14
-
15
- return dataLines.map((line) => {
16
- const values = line.split(',').map((value) => value.trim()); // Split each line by commas and trim spaces
17
- return headers.reduce((acc, key, index) => {
18
- acc[key] = values[index]; // Map values to their corresponding header
19
- return acc;
20
- }, {});
21
- });
22
- }
2
+ if (!array.length) return "";
3
+
4
+ const header = Object.keys(array[0]).join(", "); // Add space after commas in header
5
+ const rows = array.map((obj) => Object.values(obj).join(", ")); // Add space after commas in rows
6
+
7
+ return [header, ...rows].join("\n");
8
+ }
9
+
10
+ export function csvToArrayOfObjects(csv) {
11
+ const lines = csv.split("\n").filter((line) => line.trim() !== ""); // Split into lines and remove empty ones
12
+ const [headerLine, ...dataLines] = lines; // Separate header from data
13
+ const headers = headerLine.split(",").map((header) => header.trim()); // Split header into keys and trim spaces
14
+
15
+ return dataLines.map((line) => {
16
+ const values = line.split(",").map((value) => value.trim()); // Split each line by commas and trim spaces
17
+ return headers.reduce((acc, key, index) => {
18
+ acc[key] = values[index]; // Map values to their corresponding header
19
+ return acc;
20
+ }, {});
21
+ });
22
+ }
23
+
24
+ /**
25
+ * Fetches and parses a CSV file from a URL
26
+ * @param {string} url - The URL of the CSV file to fetch
27
+ * @returns {Promise<Array<Object>>} Promise that resolves to array of objects
28
+ */
29
+ export async function getCSV(url) {
30
+ try {
31
+ const response = await fetch(url);
32
+ if (!response.ok) {
33
+ throw new Error(`HTTP error! status: ${response.status}`);
34
+ }
35
+ const csvText = await response.text();
36
+ return csvToArrayOfObjects(csvText);
37
+ } catch (error) {
38
+ console.error("Error fetching CSV:", error);
39
+ throw error;
40
+ }
41
+ }
@@ -7,3 +7,9 @@ export function kebabToPascalCase(str: any): any;
7
7
  * @returns {string} - The text with <br> inserted before the third capital letter
8
8
  */
9
9
  export function forceWrapAtThirdCapital(text: string): string;
10
+ /**
11
+ * Capitalizes the first letter of a string
12
+ * @param {string} str - The string to capitalize
13
+ * @returns {string} The string with first letter capitalized
14
+ */
15
+ export function capitalise(str: string): string;
@@ -84,3 +84,13 @@ export function forceWrapAtThirdCapital(text) {
84
84
 
85
85
  return result;
86
86
  }
87
+
88
+ /**
89
+ * Capitalizes the first letter of a string
90
+ * @param {string} str - The string to capitalize
91
+ * @returns {string} The string with first letter capitalized
92
+ */
93
+ export function capitalise(str) {
94
+ if (!str || typeof str !== "string") return str;
95
+ return str.charAt(0).toUpperCase() + str.slice(1);
96
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@communitiesuk/svelte-component-library",
3
- "version": "0.1.17",
3
+ "version": "0.2.0-alpha.2",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/communitiesuk/mhclg_svelte_component_library.git"
@@ -15,6 +15,7 @@
15
15
  "test": "echo \"Error: no test specified\" && exit 1",
16
16
  "dev": "vite dev",
17
17
  "build": "vite build && npm run package",
18
+ "deploy": "gh-pages -d docs",
18
19
  "preview": "vite preview",
19
20
  "prepackage": "tsx scripts/generate-index.ts && node scripts/copy-static-assets-to-lib.js",
20
21
  "package": "npm run prepackage && svelte-kit sync && svelte-package && publint",
@@ -28,7 +29,8 @@
28
29
  "copy-govuk-assets": "node scripts/copy-govuk-assets-to-static.js",
29
30
  "copy-moj-assets": "node scripts/copy-moj-assets-to-static.js",
30
31
  "prepare": "",
31
- "create-component-and-wrapper-pages": "node scripts/create-component-and-wrapper-pages.js"
32
+ "create-component-and-wrapper-pages": "node scripts/create-component-and-wrapper-pages.js",
33
+ "sync-node-version": "node -pe \"require('./package.json').engines.node.match(/\\d+/)[0]\" > .nvmrc && echo '.nvmrc updated to use latest Node.js v'$(cat .nvmrc)'.x' && source ~/.zprofile && INSTALL_OUTPUT=$(nvm install $(cat .nvmrc) 2>&1 | grep -E '(already installed|Downloading and installing)') && echo $INSTALL_OUTPUT && INSTALLED_VERSION=$(echo $INSTALL_OUTPUT | grep -o 'v[0-9.]*') && echo 'Node.js '$INSTALLED_VERSION' ready. To switch in this terminal: nvm use'"
32
34
  },
33
35
  "files": [
34
36
  "dist",
@@ -44,8 +46,15 @@
44
46
  "exports": {
45
47
  ".": {
46
48
  "types": "./dist/index.d.ts",
47
- "svelte": "./dist/index.js"
48
- }
49
+ "svelte": "./dist/index.js",
50
+ "import": "./dist/index.js",
51
+ "require": "./dist/index.js"
52
+ },
53
+ "./src/*": "./src/lib/*",
54
+ "./src/lib/*": "./src/lib/*"
55
+ },
56
+ "engines": {
57
+ "node": ">=20.0.0"
49
58
  },
50
59
  "peerDependencies": {
51
60
  "@sveltejs/kit": "^2.0.0",
@@ -53,6 +62,7 @@
53
62
  },
54
63
  "devDependencies": {
55
64
  "@sveltejs/adapter-auto": "^3.3.0",
65
+ "@sveltejs/adapter-static": "^3.0.8",
56
66
  "@sveltejs/kit": "^2.16.1",
57
67
  "@sveltejs/package": "^2.0.0",
58
68
  "@sveltejs/vite-plugin-svelte": "^4.0.0",
@@ -87,6 +97,7 @@
87
97
  "@maptiler/sdk": "^3.0.1",
88
98
  "@ministryofjustice/frontend": "^4.0.1",
89
99
  "@monaco-editor/loader": "^1.4.0",
100
+ "@sveltejs/adapter-netlify": "^5.0.2",
90
101
  "@types/dompurify": "^3.0.5",
91
102
  "accessible-autocomplete": "^3.0.1",
92
103
  "csv-parser": "^3.0.0",
@@ -94,20 +105,20 @@
94
105
  "decimal.js": "^10.5.0",
95
106
  "dompurify": "^3.2.5",
96
107
  "flowbite-svelte-icons": "^2.0.3",
97
- "govuk-frontend": "^5.9.0",
108
+ "govuk-frontend": "^5.11.1",
109
+ "gh-pages": "^6.3.0",
98
110
  "labelplacer": "^0.0.0",
99
111
  "leaflet": "^1.9.4",
100
112
  "mapbox-gl": "^1.13.3",
101
113
  "maplibre-gl": "^5.2.0",
102
114
  "monaco-editor": "^0.52.2",
103
- "node": "^18.20.6",
104
- "npm": "^11.0.0",
105
115
  "prism-svelte": "^0.5.0",
106
116
  "prismjs": "^1.29.0",
107
117
  "shiki": "^1.27.2",
108
118
  "sveaflet": "^0.1.4",
109
119
  "svelte-maplibre": "^1.0.0-next.12",
110
120
  "svelte-preprocess": "^6.0.3",
121
+ "tileserver-gl": "^5.3.1",
111
122
  "topojson-client": "^3.1.0"
112
123
  }
113
124
  }