@defra/lis-species-cattle 0.3.0-lreg-172.alpha.1 → 0.3.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.
- package/package.json +1 -1
- package/src/breeds.js +9 -5
package/package.json
CHANGED
package/src/breeds.js
CHANGED
|
@@ -30,8 +30,8 @@ export const breeds = {
|
|
|
30
30
|
BWB: 'Belted Welsh Black',
|
|
31
31
|
BWBX: 'Belted Welsh Black Cross',
|
|
32
32
|
BI: 'Bison',
|
|
33
|
-
BA:
|
|
34
|
-
BAX:
|
|
33
|
+
BA: 'Blonde D’Aquitaine',
|
|
34
|
+
BAX: 'Blonde D’Aquitaine Cross',
|
|
35
35
|
BAL: 'Blue Albion',
|
|
36
36
|
BALX: 'Blue Albion Cross',
|
|
37
37
|
BLG: 'Blue Grey',
|
|
@@ -211,8 +211,12 @@ export const breeds = {
|
|
|
211
211
|
ZE: 'Zebu'
|
|
212
212
|
}
|
|
213
213
|
|
|
214
|
+
// Names use typographic apostrophes for display, but people type straight ones
|
|
215
|
+
// or leave them out, so names are compared lower-cased with apostrophes removed.
|
|
216
|
+
const normaliseName = (name) => name.toLowerCase().replace(/['‘’]/g, '')
|
|
217
|
+
|
|
214
218
|
const breedsByName = Object.fromEntries(
|
|
215
|
-
Object.entries(breeds).map(([code, name]) => [name
|
|
219
|
+
Object.entries(breeds).map(([code, name]) => [normaliseName(name), code])
|
|
216
220
|
)
|
|
217
221
|
|
|
218
222
|
/**
|
|
@@ -225,10 +229,10 @@ export const getBreedName = (breedCode) => {
|
|
|
225
229
|
}
|
|
226
230
|
|
|
227
231
|
/**
|
|
228
|
-
* @param {string} breedName case-insensitive
|
|
232
|
+
* @param {string} breedName case-insensitive; apostrophes (straight, curly or none) are ignored
|
|
229
233
|
* @returns {string | undefined} the breed code, or undefined for an unknown name
|
|
230
234
|
*/
|
|
231
235
|
export const getBreedCode = (breedName) => {
|
|
232
|
-
const key = breedName
|
|
236
|
+
const key = breedName && normaliseName(breedName)
|
|
233
237
|
return Object.hasOwn(breedsByName, key) ? breedsByName[key] : undefined
|
|
234
238
|
}
|