Skip to content

Commit

Permalink
Add ignoreUOMs to dev and CI
Browse files Browse the repository at this point in the history
  • Loading branch information
jakeboone02 committed Jan 18, 2024
1 parent eead400 commit eea0738
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 5 deletions.
1 change: 1 addition & 0 deletions ci/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ <h1>parse-ingredient CI</h1>
<div>allowLeadingOf</div>
<div>normalizeUOM</div>
<div>additionalUOMs</div>
<div>ignoreUOMs</div>
</div>
<script src="src/index.ts"></script>
</body>
Expand Down
2 changes: 2 additions & 0 deletions ci/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const additionalUOMs = {
alternates: ['ounce'],
},
} as const;
const ignoreUOMs = ['cup', 'cups'] as const;

for (const ex of examples) {
const run = [
Expand All @@ -28,6 +29,7 @@ for (const ex of examples) {
parseIngredient(ex, { allowLeadingOf }),
parseIngredient(ex, { normalizeUOM }),
parseIngredient(ex, { additionalUOMs }),
parseIngredient(ex, { ignoreUOMs }),
];

gridInnerHTML.push(...run.map(e => `<div>${JSON.stringify(e, null, 2)}</div>`));
Expand Down
8 changes: 4 additions & 4 deletions ci/src/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@ body {

#grid {
display: grid;
grid-template-columns: 1fr 1fr 1fr 1fr 1fr;
grid-template-columns: 1fr 1fr 1fr 1fr 1fr 1fr;
column-gap: 1rem;
row-gap: 0.4rem;
}

#grid > *:nth-child(n + 5) {
#grid > *:nth-child(n + 6) {
border-bottom: 1px solid #dddddd;
}

#grid > *:nth-child(-n + 5) {
#grid > *:nth-child(-n + 6) {
border-bottom: 1px solid gray;
font-weight: bold;
text-align: center;
}

#grid > *:nth-child(5n + 1):nth-child(n + 5) {
#grid > *:nth-child(6n + 1):nth-child(n + 6) {
font-weight: bold;
text-align: right;
}
7 changes: 6 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
Expand Down Expand Up @@ -45,6 +45,11 @@ <h4>Ingredient List</h4>
Allow leading "of "
</label>
<br />
<label>
Ignore UOMs
<input type="text" id="ignore-uoms" />
</label>
<br />
<button type="button" id="parse">Parse</button>
<h4>Results</h4>
<pre id="results" class="language-json">(Click "Parse" to see results.)</pre>
Expand Down
4 changes: 4 additions & 0 deletions src/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,14 @@ document.getElementById('ingredient-list')!.innerHTML = seed;
document.getElementById('parse')!.addEventListener('click', () => {
const normalizeUOM = (document.getElementById('normalize-uom') as HTMLInputElement).checked;
const allowLeadingOf = (document.getElementById('allow-leading-of') as HTMLInputElement).checked;
const ignoreUOMs = ((document.getElementById('ignore-uoms') as HTMLInputElement).value ?? '')
.split(',')
.map(s => s.trim());
document.getElementById('results')!.innerHTML = JSON.stringify(
parseIngredient((document.getElementById('ingredient-list') as HTMLInputElement).value, {
normalizeUOM,
allowLeadingOf,
ignoreUOMs,
}),
null,
2
Expand Down

0 comments on commit eea0738

Please sign in to comment.