Skip to content

Commit 9832ff5

Browse files
authored
Add CommonJS support (#118)
1 parent 6b3b328 commit 9832ff5

File tree

5 files changed

+3076
-1535
lines changed

5 files changed

+3076
-1535
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,4 +400,5 @@ FodyWeavers.xsd
400400
# Other
401401
crx.zip
402402
.DS_STORE
403-
.parcel-cache
403+
.parcel-cache
404+
dist/

README.md

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ This script helps you identify which elements are out of order.
2222

2323
For applications that add lots of dynamic content to the `<head>` on the client, it'd be more accurate to look at the server-rendered `<head>` instead.
2424

25-
## Programmatic API (v2.0)
25+
## Programmatic API (v2)
2626

2727
You can also use capo.js programmatically to analyze HTML `<head>` elements in Node.js or other JavaScript environments.
2828

@@ -32,17 +32,26 @@ You can also use capo.js programmatically to analyze HTML `<head>` elements in N
3232
npm install @rviscomi/capo.js
3333
```
3434

35-
### Basic Usage
35+
### Usage
36+
37+
#### ES Modules
3638

3739
```javascript
38-
// Analyze a head element
40+
import { analyzeHead } from '@rviscomi/capo.js';
41+
import { BrowserAdapter } from '@rviscomi/capo.js/adapters';
42+
3943
const head = /* your head element */;
40-
const adapter = new BrowserAdapter(); // Or other adapter
41-
const result = analyzeHead(head, adapter);
44+
const result = analyzeHead(head, new BrowserAdapter());
45+
```
4246

43-
console.log(result.elements); // Array of head elements with weights
44-
console.log(result.violations); // Number of ordering violations
45-
console.log(result.warnings); // Validation warnings
47+
#### CommonJS
48+
49+
```javascript
50+
const { analyzeHead } = require('@rviscomi/capo.js');
51+
const { BrowserAdapter } = require('@rviscomi/capo.js/adapters');
52+
53+
const head = /* your head element */;
54+
const result = analyzeHead(head, new BrowserAdapter());
4655
```
4756

4857
Learn more about building your own adapters in the [custom adapters docs](https://rviscomi.github.io/capo.js/developer/custom-adapters/).

0 commit comments

Comments
 (0)