meta_oxide 0.1.0

Universal metadata extraction library supporting 13 formats (HTML Meta, Open Graph, Twitter Cards, JSON-LD, Microdata, Microformats, RDFa, Dublin Core, Web App Manifest, oEmbed, rel-links, Images, SEO) with 7 language bindings
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
# Getting Started with MetaOxide (WebAssembly)

Welcome to MetaOxide! This guide will help you get started with the WebAssembly bindings for MetaOxide in just 5 minutes.

## Table of Contents

- [Installation]#installation
- [Quick Start (Browser)]#quick-start-browser
- [Basic Extraction]#basic-extraction
- [Platform Support]#platform-support
- [Next Steps]#next-steps

## Installation

Install MetaOxide via npm:

```bash
npm install meta-oxide-wasm
```

Or with yarn:

```bash
yarn add meta-oxide-wasm
```

Or with pnpm:

```bash
pnpm add meta-oxide-wasm
```

### Requirements

- Modern browser with WebAssembly support
- Node.js 14+ (for bundling)
- Works in browser, Node.js, and Deno

## Quick Start (Browser)

Here's a minimal example to extract metadata from HTML in the browser:

### HTML File

```html
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>MetaOxide WASM Demo</title>
</head>
<body>
    <h1>MetaOxide Demo</h1>
    <textarea id="html-input" rows="10" cols="50">
<!DOCTYPE html>
<html>
<head>
    <title>Sample Page</title>
    <meta name="description" content="A sample page">
    <meta property="og:title" content="Sample Page">
</head>
</html>
    </textarea>
    <button id="extract-btn">Extract Metadata</button>
    <pre id="output"></pre>

    <script type="module">
        import init, { MetaOxide } from './node_modules/meta-oxide-wasm/meta_oxide_wasm.js';

        async function run() {
            // Initialize WASM module
            await init();

            document.getElementById('extract-btn').addEventListener('click', () => {
                const html = document.getElementById('html-input').value;
                const extractor = new MetaOxide(html, 'https://example.com');
                const metadata = extractor.extractAll();

                document.getElementById('output').textContent =
                    JSON.stringify(metadata, null, 2);
            });
        }

        run();
    </script>
</body>
</html>
```

### With a Bundler (Webpack, Vite, etc.)

```javascript
import init, { MetaOxide } from 'meta-oxide-wasm';

async function extractMetadata() {
    // Initialize WASM module
    await init();

    const html = `
        <!DOCTYPE html>
        <html>
        <head>
            <title>My Page</title>
            <meta name="description" content="A great page">
            <meta property="og:title" content="My Page">
        </head>
        <body>Hello World</body>
        </html>
    `;

    const extractor = new MetaOxide(html, 'https://example.com');
    const metadata = extractor.extractAll();

    console.log('Title:', metadata.title);
    console.log('Description:', metadata.description);
}

extractMetadata();
```

## Basic Extraction

MetaOxide supports 13 metadata formats. Here's how to extract specific formats:

### Extract Open Graph Data

```javascript
import init, { MetaOxide } from 'meta-oxide-wasm';

async function extractOpenGraph(html) {
    await init();

    const extractor = new MetaOxide(html, 'https://example.com');
    const ogData = extractor.extractOpenGraph();

    if (ogData) {
        console.log('OG Title:', ogData.title);
        console.log('OG Type:', ogData.type);
        console.log('OG Image:', ogData.image);
    }

    return ogData;
}
```

### Extract Twitter Cards

```javascript
async function extractTwitter(html) {
    await init();

    const extractor = new MetaOxide(html, 'https://example.com');
    const twitterData = extractor.extractTwitterCard();

    if (twitterData) {
        console.log('Card Type:', twitterData.card);
        console.log('Title:', twitterData.title);
    }

    return twitterData;
}
```

### Extract JSON-LD Structured Data

```javascript
async function extractJSONLD(html) {
    await init();

    const extractor = new MetaOxide(html, 'https://example.com');
    const jsonldData = extractor.extractJSONLD();

    if (jsonldData) {
        console.log(JSON.stringify(jsonldData, null, 2));
    }

    return jsonldData;
}
```

### Extract from Current Page (Browser)

```javascript
import init, { MetaOxide } from 'meta-oxide-wasm';

async function extractCurrentPage() {
    await init();

    const html = document.documentElement.outerHTML;
    const url = window.location.href;

    const extractor = new MetaOxide(html, url);
    return extractor.extractAll();
}

// Usage
extractCurrentPage().then(metadata => {
    console.log('Current page metadata:', metadata);
});
```

### Fetch and Extract

```javascript
async function fetchAndExtract(url) {
    await init();

    const response = await fetch(url);
    const html = await response.text();

    const extractor = new MetaOxide(html, url);
    return extractor.extractAll();
}

// Usage
fetchAndExtract('https://example.com')
    .then(metadata => console.log(metadata))
    .catch(err => console.error(err));
```

## Platform Support

### Browser

Works in all modern browsers:

```javascript
import init, { MetaOxide } from 'meta-oxide-wasm';

// Initialize once
let wasmInitialized = false;

async function ensureInit() {
    if (!wasmInitialized) {
        await init();
        wasmInitialized = true;
    }
}

async function extract(html, url) {
    await ensureInit();
    const extractor = new MetaOxide(html, url);
    return extractor.extractAll();
}
```

### Node.js

```javascript
import init, { MetaOxide } from 'meta-oxide-wasm';
import { readFileSync } from 'fs';

async function extractFromFile(filepath, baseUrl) {
    await init();

    const html = readFileSync(filepath, 'utf-8');
    const extractor = new MetaOxide(html, baseUrl);
    return extractor.extractAll();
}

// Usage
extractFromFile('./index.html', 'https://example.com')
    .then(metadata => console.log(metadata));
```

### Deno

```typescript
import init, { MetaOxide } from 'npm:meta-oxide-wasm';

async function extractMetadata(html: string, url: string) {
    await init();

    const extractor = new MetaOxide(html, url);
    return extractor.extractAll();
}

const html = await Deno.readTextFile('./index.html');
const metadata = await extractMetadata(html, 'https://example.com');
console.log(metadata);
```

### React Example

```jsx
import { useState, useEffect } from 'react';
import init, { MetaOxide } from 'meta-oxide-wasm';

function MetadataExtractor() {
    const [metadata, setMetadata] = useState(null);
    const [initialized, setInitialized] = useState(false);

    useEffect(() => {
        init().then(() => setInitialized(true));
    }, []);

    const extractMetadata = (html) => {
        if (!initialized) return;

        const extractor = new MetaOxide(html, 'https://example.com');
        const result = extractor.extractAll();
        setMetadata(result);
    };

    return (
        <div>
            <button onClick={() => extractMetadata(sampleHTML)}>
                Extract
            </button>
            {metadata && (
                <pre>{JSON.stringify(metadata, null, 2)}</pre>
            )}
        </div>
    );
}
```

### Vue Example

```vue
<template>
  <div>
    <button @click="extractMetadata">Extract</button>
    <pre v-if="metadata">{{ JSON.stringify(metadata, null, 2) }}</pre>
  </div>
</template>

<script>
import { ref, onMounted } from 'vue';
import init, { MetaOxide } from 'meta-oxide-wasm';

export default {
  setup() {
    const metadata = ref(null);
    const initialized = ref(false);

    onMounted(async () => {
      await init();
      initialized.value = true;
    });

    const extractMetadata = () => {
      if (!initialized.value) return;

      const html = '<!DOCTYPE html>...';
      const extractor = new MetaOxide(html, 'https://example.com');
      metadata.value = extractor.extractAll();
    };

    return { metadata, extractMetadata };
  }
};
</script>
```

## Error Handling

Handle errors appropriately:

```javascript
import init, { MetaOxide } from 'meta-oxide-wasm';

async function safeExtraction(html, url) {
    try {
        await init();

        const extractor = new MetaOxide(html, url);
        const metadata = extractor.extractAll();

        console.log(`Extracted ${Object.keys(metadata).length} fields`);
        return metadata;
    } catch (error) {
        console.error('Extraction failed:', error.message);
        return {};
    }
}
```

## Next Steps

Now that you've got the basics, explore more:

1. **[Complete API Reference]/docs/api/api-reference-wasm.md** - Learn about all available methods
2. **[Real-World Examples]/examples/real-world/wasm-nextjs-app/** - See a complete Next.js application
3. **[Integration Guides]/docs/integrations/nextjs-integration.md** - Use with Next.js, React, Vue

### All Supported Formats

MetaOxide extracts these 13 metadata formats:

- Basic HTML metadata (title, description, keywords)
- Open Graph (og:*)
- Twitter Cards (twitter:*)
- JSON-LD structured data
- Microdata (schema.org)
- Microformats (h-card, h-entry, h-event)
- Dublin Core
- RDFA
- HTML5 semantic elements
- Link relations
- Image metadata
- Author information

### TypeScript Support

```typescript
import init, { MetaOxide } from 'meta-oxide-wasm';

interface Metadata {
    title?: string;
    description?: string;
    [key: string]: any;
}

async function extractMetadata(html: string, url: string): Promise<Metadata> {
    await init();

    const extractor = new MetaOxide(html, url);
    return extractor.extractAll();
}
```

### Learn More

- [Next.js Integration]/docs/integrations/nextjs-integration.md
- [Performance Tuning]/docs/performance/performance-tuning-guide.md
- [Architecture Overview]/docs/architecture/architecture-overview.md

Happy extracting! 🚀