16 lines
645 B
JavaScript
16 lines
645 B
JavaScript
// The names the app searches on, in document order, without repeats. Case and
|
|
// accents are only used to spot a repeat: the first spelling of a name is the
|
|
// one kept, because it is the household's own.
|
|
export function listIngredientNames(document) {
|
|
const parsed = document['tofu:parsedIngredients'] ?? []
|
|
const seen = new Set()
|
|
const names = []
|
|
for (const { name } of parsed) {
|
|
if (typeof name !== 'string' || name.trim() === '') continue
|
|
const key = name.trim().toLowerCase().normalize('NFD').replace(/\p{Diacritic}/gu, '')
|
|
if (seen.has(key)) continue
|
|
seen.add(key)
|
|
names.push(name.trim())
|
|
}
|
|
return names
|
|
}
|