@gsriram24/structured-data-validator 1.6.0 → 1.6.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.
Files changed (2) hide show
  1. package/README.md +95 -44
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,33 +1,83 @@
1
- # @adobe/structured-data-validator
1
+ # @gsriram24/structured-data-validator
2
2
 
3
- ![GitHub License](https://img.shields.io/github/license/adobe/structured-data-validator)
4
- [![CI](https://github.com/adobe/structured-data-validator/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/adobe/structured-data-validator/actions/workflows/ci.yml)
5
- [![NPM Version](https://img.shields.io/npm/v/%40adobe%2Fstructured-data-validator?link=https%3A%2F%2Fwww.npmjs.com%2Fpackage%2F%40adobe%2Fstructured-data-validator)](https://www.npmjs.com/package/@adobe/structured-data-validator)
6
- ![Node Current](https://img.shields.io/node/v/%40adobe%2Fstructured-data-validator)
3
+ > **Fork of [@adobe/structured-data-validator](https://github.com/adobe/structured-data-validator)** with additional features.
7
4
 
8
- A JavaScript library for validating and parsing structured data according to Schema.org specifications and Google Rich Results requirements. This library ensures your structured data meets both Schema.org standards and Google's specific requirements for rich results, helping to optimize your content for search engines and other platforms.
5
+ [![NPM Version](https://img.shields.io/npm/v/%40gsriram24%2Fstructured-data-validator)](https://www.npmjs.com/package/@gsriram24/structured-data-validator)
6
+ ![Node Current](https://img.shields.io/node/v/%40gsriram24%2Fstructured-data-validator)
9
7
 
10
- ## Features
8
+ A JavaScript library for validating and parsing structured data according to Schema.org specifications and Google Rich Results requirements.
11
9
 
12
- - Validates structured data against both Schema.org and Google Rich Results specifications
13
- - Ensures compliance with Google's structured data guidelines
14
- - Extensible validation system with custom type handlers
10
+ ## Additional Features in This Fork
11
+
12
+ This fork adds the following features on top of Adobe's original library:
13
+
14
+ ### 1. `fieldName` Property on Validation Errors
15
+ Every validation error now includes a `fieldName` property for precise programmatic access:
16
+
17
+ ```javascript
18
+ // Before (Adobe's version) - requires string parsing
19
+ {
20
+ issueMessage: 'Required attribute "price" is missing',
21
+ severity: 'ERROR',
22
+ path: [...]
23
+ }
24
+
25
+ // After (this fork) - direct field access
26
+ {
27
+ issueMessage: 'Required attribute "price" is missing',
28
+ severity: 'ERROR',
29
+ path: [...],
30
+ fieldName: 'price' // ✨ New!
31
+ }
32
+ ```
33
+
34
+ For `or()` conditions, both `fieldName` and `fieldNames` are provided:
35
+ ```javascript
36
+ {
37
+ issueMessage: 'One of the following attributes is required...',
38
+ fieldName: 'aggregateRating', // First field
39
+ fieldNames: ['aggregateRating', 'offers', 'review'] // All fields
40
+ }
41
+ ```
42
+
43
+ ### 2. New Validators for Common Schema Types
44
+ Added validators for commonly-used schema.org types:
45
+
46
+ | Type | Required Fields |
47
+ |------|-----------------|
48
+ | `LocalBusiness` | `name`, `address` |
49
+ | `Article` | `headline` |
50
+ | `Event` | `name`, `startDate`, `location` (or online mode) |
51
+ | `FAQPage` | `mainEntity` |
52
+ | `HowTo` | `name`, `step` |
53
+ | `WebSite` | `name`, `url` |
54
+
55
+ ### 3. Automatic Subtype Inheritance
56
+ Subtypes automatically inherit validation from parent types:
57
+
58
+ | Subtype | Inherits From |
59
+ |---------|---------------|
60
+ | `Restaurant`, `Store`, `Hotel`, `Dentist` | `LocalBusiness` |
61
+ | `NewsArticle`, `BlogPosting`, `TechArticle` | `Article` |
62
+ | `MusicEvent`, `SportsEvent`, `Festival` | `Event` |
63
+
64
+ This enables validation of **100+ schema types** without individual validator files.
65
+
66
+ ---
15
67
 
16
68
  ## Installation
17
69
 
18
70
  ```bash
19
- npm install @adobe/structured-data-validator
71
+ npm install @gsriram24/structured-data-validator
20
72
  ```
21
73
 
22
74
  ## Usage
23
75
 
24
- This library works in conjunction with [@marbec/web-auto-extractor](https://www.npmjs.com/package/@marbec/web-auto-extractor) to validate structured data extracted from web pages.
25
-
26
76
  ```javascript
27
- import { Validator } from '@adobe/structured-data-validator';
77
+ import { Validator } from '@gsriram24/structured-data-validator';
28
78
  import WebAutoExtractor from '@marbec/web-auto-extractor';
29
79
 
30
- // First, extract structured data from HTML
80
+ // Extract structured data from HTML
31
81
  const extractor = new WebAutoExtractor({ addLocation: true, embedSource: ['rdfa', 'microdata'] });
32
82
  const extractedData = extractor.parse(sampleHTML);
33
83
 
@@ -39,52 +89,60 @@ const validator = new Validator(schemaOrgJson);
39
89
 
40
90
  // Validate the extracted structured data
41
91
  const results = await validator.validate(extractedData);
42
- }
43
- ```
44
92
 
45
- The validator expects the output format from `@marbec/web-auto-extractor`, which includes:
46
-
47
- - JSON-LD structured data
48
- - Microdata
49
- - RDFa
93
+ // Use fieldName for precise error handling
94
+ results.forEach(issue => {
95
+ if (issue.severity === 'ERROR') {
96
+ console.log(`Field "${issue.fieldName}" has error: ${issue.issueMessage}`);
97
+ }
98
+ });
99
+ ```
50
100
 
51
101
  ### Browser
52
102
 
53
- You can run the parser and validator directly in the browser on any website using the following commands:
54
-
55
103
  ```js
56
104
  const { default: WebAutoExtractor } = await import(
57
105
  'https://unpkg.com/@marbec/web-auto-extractor@latest/dist/index.js'
58
106
  );
59
107
  const { default: Validator } = await import(
60
- 'https://unpkg.com/@adobe/structured-data-validator@latest/src/index.js'
108
+ 'https://unpkg.com/@gsriram24/structured-data-validator@latest/src/index.js'
61
109
  );
62
110
 
63
111
  const extractedData = new WebAutoExtractor({
64
112
  addLocation: true,
65
113
  embedSource: ['rdfa', 'microdata'],
66
114
  }).parse(document.documentElement.outerHTML);
67
- console.log(extractedData);
115
+
68
116
  const schemaOrgJson = await (
69
117
  await fetch('https://schema.org/version/latest/schemaorg-all-https.jsonld')
70
118
  ).json();
71
- await new Validator(schemaOrgJson).validate(extractedData);
119
+
120
+ const issues = await new Validator(schemaOrgJson).validate(extractedData);
121
+ console.log(issues);
72
122
  ```
73
123
 
124
+ ## Upstream Contributions
125
+
126
+ The features in this fork have been submitted as PRs to the upstream Adobe repository:
127
+ - [PR #57: Add fieldName property](https://github.com/adobe/structured-data-validator/pull/57)
128
+ - [PR #58: Add validators for common schema types](https://github.com/adobe/structured-data-validator/pull/58)
129
+
130
+ Once merged upstream, consider switching back to `@adobe/structured-data-validator`.
131
+
74
132
  ## Development
75
133
 
76
134
  ### Prerequisites
77
135
 
78
- - Node.js (latest LTS version recommended)
136
+ - Node.js (>=18.0.0)
79
137
  - npm
80
138
 
81
139
  ### Setup
82
140
 
83
- 1. Clone the repository
84
- 2. Install dependencies:
85
- ```bash
86
- npm install
87
- ```
141
+ ```bash
142
+ git clone https://github.com/gsriram24/structured-data-validator.git
143
+ cd structured-data-validator
144
+ npm install
145
+ ```
88
146
 
89
147
  ### Available Scripts
90
148
 
@@ -93,17 +151,10 @@ await new Validator(schemaOrgJson).validate(extractedData);
93
151
  - `npm run format` - Check code formatting
94
152
  - `npm run format:fix` - Fix code formatting issues
95
153
 
96
- ### Debug Logging
97
-
98
- To enable debug logging and see detailed validation output, set the `debug` property to `true` on your `Validator` instance:
99
-
100
- ```js
101
- const validator = new Validator();
102
- validator.debug = true; // Enable debug logging
103
- ```
154
+ ## License
104
155
 
105
- This will print additional information to the console during validation, which is useful for development and troubleshooting.
156
+ Apache-2.0 (same as upstream)
106
157
 
107
- ## Dependencies
158
+ ## Credits
108
159
 
109
- - [@marbec/web-auto-extractor](https://www.npmjs.com/package/@marbec/web-auto-extractor) - For extracting structured data from web pages
160
+ Original library by [Adobe](https://github.com/adobe/structured-data-validator).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gsriram24/structured-data-validator",
3
- "version": "1.6.0",
3
+ "version": "1.6.1",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },