schemaorg-kit 1.1.0 → 1.1.1
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/README.md +82 -65
- package/dist/index.d.mts +2905 -2901
- package/dist/index.d.ts +2905 -2901
- package/dist/index.js +176 -154
- package/dist/index.mjs +176 -154
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -27,7 +27,11 @@ Requires **Node.js ≥ 18** and **Zod ≥ 4.3**.
|
|
|
27
27
|
## Quick Start
|
|
28
28
|
|
|
29
29
|
```typescript
|
|
30
|
-
import {
|
|
30
|
+
import {
|
|
31
|
+
createProduct,
|
|
32
|
+
createOffer,
|
|
33
|
+
createBreadcrumbList,
|
|
34
|
+
} from "schemaorg-kit";
|
|
31
35
|
|
|
32
36
|
const product = createProduct({
|
|
33
37
|
name: "Running Shoes",
|
|
@@ -50,14 +54,14 @@ const jsonLd = product.toJsonLd(); // includes @context
|
|
|
50
54
|
|
|
51
55
|
Every node returned by a factory exposes these methods:
|
|
52
56
|
|
|
53
|
-
| Method
|
|
54
|
-
|
|
55
|
-
| `.toObject()`
|
|
56
|
-
| `.toJsonLd()`
|
|
57
|
-
| `.toScript()`
|
|
58
|
-
| `.toString()`
|
|
59
|
-
| `.validate()`
|
|
60
|
-
| `.safeParse()` | Zod result
|
|
57
|
+
| Method | Returns | Description |
|
|
58
|
+
| -------------- | ------------------------- | ------------------------------------------------------------------ |
|
|
59
|
+
| `.toObject()` | `T` | Raw validated object — use this when nesting inside another schema |
|
|
60
|
+
| `.toJsonLd()` | `Record<string, unknown>` | Object with `@context: "https://schema.org"` added |
|
|
61
|
+
| `.toScript()` | `string` | Full `<script type="application/ld+json">` tag, ready for HTML |
|
|
62
|
+
| `.toString()` | `string` | Pretty-printed JSON string |
|
|
63
|
+
| `.validate()` | `this` | Throws a `ZodError` if data is invalid (chainable) |
|
|
64
|
+
| `.safeParse()` | Zod result | Returns `{ success, data, error }` without throwing |
|
|
61
65
|
|
|
62
66
|
## Composing Schemas
|
|
63
67
|
|
|
@@ -70,7 +74,7 @@ const author = createPerson({ name: "Jane Doe", url: "https://janedoe.com" });
|
|
|
70
74
|
|
|
71
75
|
const article = createArticle({
|
|
72
76
|
headline: "Hello World",
|
|
73
|
-
author: author.toObject(),
|
|
77
|
+
author: author.toObject(), // <-- nest with .toObject()
|
|
74
78
|
publisher: createOrganization({
|
|
75
79
|
name: "Acme Blog",
|
|
76
80
|
url: "https://acmeblog.com",
|
|
@@ -86,10 +90,18 @@ console.log(article.toScript());
|
|
|
86
90
|
Use `createGraph` to output multiple schema nodes in a single `<script>` tag with `@id` cross-references:
|
|
87
91
|
|
|
88
92
|
```typescript
|
|
89
|
-
import {
|
|
93
|
+
import {
|
|
94
|
+
createGraph,
|
|
95
|
+
createWebPage,
|
|
96
|
+
createArticle,
|
|
97
|
+
createPerson,
|
|
98
|
+
} from "schemaorg-kit";
|
|
90
99
|
|
|
91
100
|
const graph = createGraph([
|
|
92
|
-
createWebPage({
|
|
101
|
+
createWebPage({
|
|
102
|
+
"@id": "https://example.com/post#webpage",
|
|
103
|
+
url: "https://example.com/post",
|
|
104
|
+
}),
|
|
93
105
|
createArticle({
|
|
94
106
|
"@id": "https://example.com/post#article",
|
|
95
107
|
headline: "Hello World",
|
|
@@ -110,70 +122,70 @@ As an alternative to named imports, use the `schema()` factory with any register
|
|
|
110
122
|
import { schema } from "schemaorg-kit";
|
|
111
123
|
|
|
112
124
|
const product = schema("Product", { name: "Shoes", sku: "SH-001" });
|
|
113
|
-
const event
|
|
125
|
+
const event = schema("Event", { name: "Conference", startDate: "2025-09-01" });
|
|
114
126
|
```
|
|
115
127
|
|
|
116
128
|
## Supported Types
|
|
117
129
|
|
|
118
130
|
### Things
|
|
119
131
|
|
|
120
|
-
| Factory
|
|
121
|
-
|
|
122
|
-
| `createPerson`
|
|
123
|
-
| `createOrganization`
|
|
124
|
-
| `createCorporation`
|
|
125
|
-
| `createNGO`
|
|
126
|
-
| `createOnlineStore`
|
|
132
|
+
| Factory | Schema.org Type |
|
|
133
|
+
| ---------------------- | ---------------- |
|
|
134
|
+
| `createPerson` | `Person` |
|
|
135
|
+
| `createOrganization` | `Organization` |
|
|
136
|
+
| `createCorporation` | `Corporation` |
|
|
137
|
+
| `createNGO` | `NGO` |
|
|
138
|
+
| `createOnlineStore` | `OnlineStore` |
|
|
127
139
|
| `createOnlineBusiness` | `OnlineBusiness` |
|
|
128
|
-
| `createProduct`
|
|
129
|
-
| `createProductGroup`
|
|
130
|
-
| `createEvent`
|
|
131
|
-
| `createPlace`
|
|
132
|
-
| `createLocalBusiness`
|
|
133
|
-
| `createRestaurant`
|
|
134
|
-
| `createHotel`
|
|
135
|
-
| `createMovie`
|
|
140
|
+
| `createProduct` | `Product` |
|
|
141
|
+
| `createProductGroup` | `ProductGroup` |
|
|
142
|
+
| `createEvent` | `Event` |
|
|
143
|
+
| `createPlace` | `Place` |
|
|
144
|
+
| `createLocalBusiness` | `LocalBusiness` |
|
|
145
|
+
| `createRestaurant` | `Restaurant` |
|
|
146
|
+
| `createHotel` | `Hotel` |
|
|
147
|
+
| `createMovie` | `Movie` |
|
|
136
148
|
|
|
137
149
|
### Creative Works
|
|
138
150
|
|
|
139
|
-
| Factory
|
|
140
|
-
|
|
141
|
-
| `createBook`
|
|
142
|
-
| `createArticle`
|
|
143
|
-
| `createNewsArticle`
|
|
144
|
-
| `createBlogPosting`
|
|
145
|
-
| `createWebPage`
|
|
146
|
-
| `createWebSite`
|
|
147
|
-
| `createDataset`
|
|
148
|
-
| `createRecipe`
|
|
149
|
-
| `createCourse`
|
|
150
|
-
| `createSoftwareApplication` | `SoftwareApplication`
|
|
151
|
-
| `createMobileApplication`
|
|
152
|
-
| `createWebApplication`
|
|
153
|
-
| `createMathSolver`
|
|
154
|
-
| `createClaimReview`
|
|
151
|
+
| Factory | Schema.org Type |
|
|
152
|
+
| --------------------------- | --------------------------------------- |
|
|
153
|
+
| `createBook` | `Book` (with ReadAction / BorrowAction) |
|
|
154
|
+
| `createArticle` | `Article` |
|
|
155
|
+
| `createNewsArticle` | `NewsArticle` |
|
|
156
|
+
| `createBlogPosting` | `BlogPosting` |
|
|
157
|
+
| `createWebPage` | `WebPage` |
|
|
158
|
+
| `createWebSite` | `WebSite` |
|
|
159
|
+
| `createDataset` | `Dataset` |
|
|
160
|
+
| `createRecipe` | `Recipe` |
|
|
161
|
+
| `createCourse` | `Course` |
|
|
162
|
+
| `createSoftwareApplication` | `SoftwareApplication` |
|
|
163
|
+
| `createMobileApplication` | `MobileApplication` |
|
|
164
|
+
| `createWebApplication` | `WebApplication` |
|
|
165
|
+
| `createMathSolver` | `MathSolver` |
|
|
166
|
+
| `createClaimReview` | `ClaimReview` (Fact Check) |
|
|
155
167
|
|
|
156
168
|
### Intangibles & Other
|
|
157
169
|
|
|
158
|
-
| Factory
|
|
159
|
-
|
|
160
|
-
| `createOffer`
|
|
161
|
-
| `createImageObject`
|
|
162
|
-
| `createVideoObject`
|
|
163
|
-
| `createJobPosting`
|
|
170
|
+
| Factory | Schema.org Type |
|
|
171
|
+
| ------------------------------------------------ | ------------------------------ |
|
|
172
|
+
| `createOffer` | `Offer` |
|
|
173
|
+
| `createImageObject` | `ImageObject` |
|
|
174
|
+
| `createVideoObject` | `VideoObject` |
|
|
175
|
+
| `createJobPosting` | `JobPosting` |
|
|
164
176
|
| `createQAPage` / `createQuiz` / `createQuestion` | `QAPage` / `Quiz` / `Question` |
|
|
165
|
-
| `createDiscussionForumPosting`
|
|
166
|
-
| `createProfilePage`
|
|
167
|
-
| `createVacationRental`
|
|
168
|
-
| `createLanguage`
|
|
177
|
+
| `createDiscussionForumPosting` | `DiscussionForumPosting` |
|
|
178
|
+
| `createProfilePage` | `ProfilePage` |
|
|
179
|
+
| `createVacationRental` | `VacationRental` |
|
|
180
|
+
| `createLanguage` | `Language` |
|
|
169
181
|
|
|
170
182
|
### Helpers
|
|
171
183
|
|
|
172
|
-
| Helper
|
|
173
|
-
|
|
174
|
-
| `createBreadcrumbList([...])` | Builds a `BreadcrumbList` from a plain array
|
|
175
|
-
| `createFAQPage([...])`
|
|
176
|
-
| `createCarousel([...])`
|
|
184
|
+
| Helper | What it does |
|
|
185
|
+
| ----------------------------- | ------------------------------------------------------------ |
|
|
186
|
+
| `createBreadcrumbList([...])` | Builds a `BreadcrumbList` from a plain array |
|
|
187
|
+
| `createFAQPage([...])` | Builds a `FAQPage` from `{question, answer}` pairs |
|
|
188
|
+
| `createCarousel([...])` | Wraps schema nodes in an `ItemList` carousel |
|
|
177
189
|
| `createPaywalledArticle(...)` | Article with `isAccessibleForFree: false` paywalled sections |
|
|
178
190
|
|
|
179
191
|
## Common Patterns
|
|
@@ -201,7 +213,9 @@ const product = createProduct({
|
|
|
201
213
|
availability: "InStock",
|
|
202
214
|
shippingDetails: OfferShippingDetailsSchema.parse({
|
|
203
215
|
shippingRate: { value: 0, currency: "USD" },
|
|
204
|
-
shippingDestination: DefinedRegionSchema.parse({
|
|
216
|
+
shippingDestination: DefinedRegionSchema.parse({
|
|
217
|
+
addressCountry: "US",
|
|
218
|
+
}),
|
|
205
219
|
deliveryTime: {
|
|
206
220
|
handlingTime: { minValue: 0, maxValue: 1, unitCode: "DAY" },
|
|
207
221
|
transitTime: { minValue: 3, maxValue: 5, unitCode: "DAY" },
|
|
@@ -218,8 +232,11 @@ const product = createProduct({
|
|
|
218
232
|
import { createFAQPage } from "schemaorg-kit";
|
|
219
233
|
|
|
220
234
|
const faq = createFAQPage([
|
|
221
|
-
{
|
|
222
|
-
|
|
235
|
+
{
|
|
236
|
+
question: "What is schemaorg-kit?",
|
|
237
|
+
answer: "A type-safe schema.org builder.",
|
|
238
|
+
},
|
|
239
|
+
{ question: "Does it support @graph?", answer: "Yes, via createGraph()." },
|
|
223
240
|
]);
|
|
224
241
|
|
|
225
242
|
document.head.innerHTML += faq.toScript();
|
|
@@ -231,9 +248,9 @@ document.head.innerHTML += faq.toScript();
|
|
|
231
248
|
import { createBreadcrumbList } from "schemaorg-kit";
|
|
232
249
|
|
|
233
250
|
const breadcrumb = createBreadcrumbList([
|
|
234
|
-
{ name: "Home",
|
|
251
|
+
{ name: "Home", url: "https://example.com" },
|
|
235
252
|
{ name: "Products", url: "https://example.com/products" },
|
|
236
|
-
{ name: "Shoes" },
|
|
253
|
+
{ name: "Shoes" }, // last item — url is optional
|
|
237
254
|
]);
|
|
238
255
|
```
|
|
239
256
|
|
|
@@ -244,7 +261,7 @@ import { extendThing, makeFactory } from "schemaorg-kit";
|
|
|
244
261
|
import { z } from "zod";
|
|
245
262
|
|
|
246
263
|
const PodcastSchema = extendThing("PodcastSeries", {
|
|
247
|
-
webFeed: z.
|
|
264
|
+
webFeed: z.url(),
|
|
248
265
|
numberOfEpisodes: z.number().int().optional(),
|
|
249
266
|
});
|
|
250
267
|
|