| public | ||
| src | ||
| .editorconfig | ||
| .env.example | ||
| .gitignore | ||
| index.html | ||
| mise.toml | ||
| package-lock.json | ||
| package.json | ||
| pnpm-lock.yaml | ||
| README.md | ||
| tsconfig.json | ||
| vite.config.ts | ||
Purpose
This small single-page webapp generates nutrition information in the following style:
Makes 6 389g servings. Each serving: Calories: 558kcal (26%), Protein: 28.18g (52%), Total Fat: 11.64g (24%), Cholesterol: 64mg, Saturated Fat: 3g, Trans Fat: 0.11g, Carbohydrates: 82.35g (34%), Dietary Fiber: 3.9g (16%), Sugars: 3.11g, Calcium: 45mg (5%), Iron: 2.72mg (15%), Potassium: 474mg (10%), Sodium: 584mg (39%)
Information and quantities are based on user-provided ingredients and quantities.
Installation
$ npm install # or pnpm install or yarn install
Available Scripts
In the project directory, you can run:
npm run dev or npm start
Runs the app in the development mode.
Open http://localhost:3000 to view it in the browser.
The page will reload if you make edits.
npm run build
Builds the app for production to the dist folder.
It correctly bundles Solid in production mode and optimizes the build for the best performance.
The build is minified and the filenames include the hashes.
Your app is ready to be deployed!
npm run publish
Builds the project, then publishes dist to the gh-pages branch and pushes.
You can also manually deploy the dist folder to any static host provider (netlify, surge, now, etc.)
If you want to add a visit tracker see .env.example.
Colophon
I used SolidStart to scaffold an empty SolidJS TypeScript project with Vite. I downloaded the "SR Legacy" data set from the USDA FoodData Central site. This data set is fairly complete, but it's still small enough that I can serve and load a condensed version for fully client-side lookups. I used FuseJS to search this data set - its tuneable fuzzy search and small bundle size were perfect for the project's needs.
This was my first experience with SolidJS stores, and I found the developer experience wonderful. It turned out to be an efficient and simple way to reactively manage the dynamic form state I required.
I adapted a fraction-parsing script from StackExchange user machineghost to allow the quantity to be written as a mixed fraction. And that was it. You can see the results at the bottom of my bread pudding and breakfast strata posts.