soustack 0.1.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/LICENSE +21 -0
- package/README.md +138 -0
- package/dist/cli/index.js +2009 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/index.d.mts +336 -0
- package/dist/index.d.ts +336 -0
- package/dist/index.js +2126 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +2104 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +74 -0
- package/src/schema.json +305 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Richard Herold
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
# Soustack Core
|
|
2
|
+
|
|
3
|
+
> **The Logic Engine for Computational Recipes.**
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/soustack)
|
|
6
|
+
[](https://opensource.org/licenses/MIT)
|
|
7
|
+
[](https://www.typescriptlang.org/)
|
|
8
|
+
|
|
9
|
+
**Soustack Core** is the reference implementation for the [Soustack Standard](https://github.com/soustack/spec). It provides the validation, parsing, and scaling logic required to turn static recipe data into dynamic, computable objects.
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## 💡 The Value Proposition
|
|
14
|
+
|
|
15
|
+
Most recipe formats (like Schema.org) are **descriptive**—they tell you _what_ a recipe is.
|
|
16
|
+
Soustack is **computational**—it understands _how_ a recipe behaves.
|
|
17
|
+
|
|
18
|
+
### The Problems We Solve:
|
|
19
|
+
|
|
20
|
+
1. **The "Salty Soup" Problem (Intelligent Scaling):**
|
|
21
|
+
- _Old Way:_ Doubling a recipe doubles every ingredient blindly.
|
|
22
|
+
- _Soustack:_ Understands that salt scales differently than flour, and frying oil shouldn't scale at all. It supports **Linear**, **Fixed**, **Discrete**, and **Baker's Percentage** scaling modes.
|
|
23
|
+
2. **The "Lying Prep Time" Problem:**
|
|
24
|
+
- _Old Way:_ Authors guess "Prep: 15 mins."
|
|
25
|
+
- _Soustack:_ Calculates total time dynamically based on the active/passive duration of every step.
|
|
26
|
+
3. **The "Timing Clash" Problem:**
|
|
27
|
+
- _Old Way:_ A flat list of instructions.
|
|
28
|
+
- _Soustack:_ A **Dependency Graph** that knows you can chop vegetables while the water boils.
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
## 📦 Installation
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
npm install soustack
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## What’s Included
|
|
39
|
+
|
|
40
|
+
- **Validation**: `validateRecipe()` validates Soustack JSON against the bundled schema.
|
|
41
|
+
- **Scaling & Computation**: `scaleRecipe()` produces a flat, UI-ready “computed recipe” (scaled ingredients + aggregated timing).
|
|
42
|
+
- **Parsers**:
|
|
43
|
+
- Ingredient parsing (`parseIngredient`, `parseIngredientLine`)
|
|
44
|
+
- Duration parsing (`smartParseDuration`)
|
|
45
|
+
- Yield parsing (`parseYield`)
|
|
46
|
+
- **Schema.org Conversion**:
|
|
47
|
+
- `fromSchemaOrg()` (Schema.org JSON-LD → Soustack)
|
|
48
|
+
- `toSchemaOrg()` (Soustack → Schema.org JSON-LD)
|
|
49
|
+
- **Web Scraping**: `scrapeRecipe()` fetches a recipe page and extracts Schema.org recipe data from:
|
|
50
|
+
- JSON-LD (`<script type="application/ld+json">`)
|
|
51
|
+
- Microdata (`itemscope/itemtype`)
|
|
52
|
+
|
|
53
|
+
## Programmatic Usage
|
|
54
|
+
|
|
55
|
+
```ts
|
|
56
|
+
import {
|
|
57
|
+
scrapeRecipe,
|
|
58
|
+
fromSchemaOrg,
|
|
59
|
+
toSchemaOrg,
|
|
60
|
+
validateRecipe,
|
|
61
|
+
scaleRecipe
|
|
62
|
+
} from 'soustack';
|
|
63
|
+
|
|
64
|
+
// Validate a Soustack recipe JSON object
|
|
65
|
+
validateRecipe(recipe);
|
|
66
|
+
|
|
67
|
+
// Scale a recipe to a target yield amount (returns a "computed recipe")
|
|
68
|
+
const computed = scaleRecipe(recipe, 2);
|
|
69
|
+
|
|
70
|
+
// Scrape a URL into a Soustack recipe (throws if no recipe is found)
|
|
71
|
+
const scraped = await scrapeRecipe('https://example.com/recipe');
|
|
72
|
+
|
|
73
|
+
// Convert Schema.org → Soustack
|
|
74
|
+
const soustack = fromSchemaOrg(schemaOrgJsonLd);
|
|
75
|
+
|
|
76
|
+
// Convert Soustack → Schema.org
|
|
77
|
+
const jsonLd = toSchemaOrg(recipe);
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## 🔁 Schema.org Conversion
|
|
81
|
+
|
|
82
|
+
Use the new helpers to move between Schema.org JSON-LD and Soustack's structured recipe format.
|
|
83
|
+
|
|
84
|
+
```ts
|
|
85
|
+
import { fromSchemaOrg, toSchemaOrg } from 'soustack';
|
|
86
|
+
|
|
87
|
+
const soustackRecipe = fromSchemaOrg(schemaOrgJsonLd);
|
|
88
|
+
const schemaOrgRecipe = toSchemaOrg(soustackRecipe);
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## 🧰 Scraping Options
|
|
92
|
+
|
|
93
|
+
`scrapeRecipe(url, options)` supports basic fetch tuning:
|
|
94
|
+
|
|
95
|
+
- `timeout` (ms, default `10000`)
|
|
96
|
+
- `userAgent` (string, optional)
|
|
97
|
+
- `maxRetries` (default `2`, retries on non-4xx failures)
|
|
98
|
+
|
|
99
|
+
```ts
|
|
100
|
+
import { scrapeRecipe } from 'soustack';
|
|
101
|
+
|
|
102
|
+
const recipe = await scrapeRecipe('https://example.com/recipe', {
|
|
103
|
+
timeout: 15000,
|
|
104
|
+
maxRetries: 3
|
|
105
|
+
});
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### CLI
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
# Validate & Scale (existing commands)
|
|
112
|
+
npx soustack validate recipe.soustack.json
|
|
113
|
+
npx soustack scale recipe.soustack.json 2
|
|
114
|
+
|
|
115
|
+
# Schema.org ↔ Soustack
|
|
116
|
+
npx soustack import recipe.jsonld -o recipe.soustack.json
|
|
117
|
+
npx soustack export recipe.soustack.json -o recipe.jsonld
|
|
118
|
+
npx soustack scrape "https://example.com/recipe" -o recipe.soustack.json
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## 🔄 Keeping the Schema in Sync
|
|
122
|
+
|
|
123
|
+
The `src/schema.json` file in this repository is a **copy** of the official standard.
|
|
124
|
+
The source of truth lives in [RichardHerold/soustack-spec](https://github.com/RichardHerold/soustack-spec).
|
|
125
|
+
|
|
126
|
+
**Do not edit `src/schema.json` manually.**
|
|
127
|
+
|
|
128
|
+
To update to the latest version of the standard, run:
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
npm run sync:spec
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
## Development
|
|
135
|
+
|
|
136
|
+
```bash
|
|
137
|
+
npm test
|
|
138
|
+
```
|