wcag-scanner 1.2.55 → 1.2.56

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 +90 -0
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -39,4 +39,94 @@ npm i wcag-scanner
39
39
  ### Using yarn
40
40
  ```bash
41
41
  yarn add wcag-scanner
42
+ ```
43
+
44
+ ## How to use
45
+
46
+ ### Scan a file
47
+ ```bash
48
+ npx wcag-scanner file index.html --level AA --format console
49
+ ```
50
+
51
+ ### Scan a URL
52
+ ```bash
53
+ npx wcag-scanner url https://example.com --format html --output report.html
54
+ ```
55
+
56
+ ### Implement with Express
57
+ ```JavaScript
58
+ import express from 'express';
59
+ import { middleware } from 'wcag-scanner';
60
+
61
+ const app = express();
62
+
63
+ // Add the WCAG scanner middleware
64
+ app.use(middleware.express.createMiddleware({
65
+ enabled: true,
66
+ level: 'AA',
67
+ headerName: 'X-WCAG-Violations',
68
+ inlineReport: true,
69
+ onViolation: (results, req, res) => {
70
+ console.log(`Found ${results.violations.length} accessibility issues in ${req.path}`);
71
+ }
72
+ }));
73
+
74
+ // Your routes
75
+ app.get('/', (req, res) => {
76
+ res.send(`
77
+ <!DOCTYPE html>
78
+ <html>
79
+ <head>
80
+ <title>Test Page</title>
81
+ </head>
82
+ <body>
83
+ <h1>Hello World</h1>
84
+ <img src="logo.png"> <!-- Missing alt text will trigger violation -->
85
+ </body>
86
+ </html>
87
+ `);
88
+ });
89
+
90
+ app.listen(3000, () => {
91
+ console.log('Server running on http://localhost:3000');
92
+ });
93
+ ```
94
+
95
+ ### Create an API
96
+ ```JavaScript
97
+ import { scanHtml, scanUrl, formatReport } from 'wcag-scanner';
98
+
99
+ async function checkMyWebsite() {
100
+ try {
101
+ // Scan a URL
102
+ const results = await scanUrl('https://example.com', { level: 'AA' });
103
+
104
+ console.log(`Found ${results.violations.length} accessibility issues`);
105
+
106
+ // Generate a report
107
+ const htmlReport = formatReport(results, 'html');
108
+
109
+ // Save the report
110
+ fs.writeFileSync('accessibility-report.html', htmlReport);
111
+ } catch (error) {
112
+ console.error('Error scanning website:', error);
113
+ }
114
+ }
115
+
116
+ async function checkHtmlString() {
117
+ const html = `
118
+ <!DOCTYPE html>
119
+ <html>
120
+ <head>
121
+ <title>Test</title>
122
+ </head>
123
+ <body>
124
+ <img src="logo.png"> <!-- Missing alt text -->
125
+ </body>
126
+ </html>
127
+ `;
128
+
129
+ const results = await scanHtml(html);
130
+ console.log(formatReport(results, 'console'));
131
+ }
42
132
  ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wcag-scanner",
3
- "version": "1.2.55",
3
+ "version": "1.2.56",
4
4
  "description": "Scan HTML for WCAG accessibility violations with AI-powered fix suggestions",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",