https://github.com/baethon/extract-jsonld.js
Simple utility for extracting JSON-LD data from given URL
https://github.com/baethon/extract-jsonld.js
Last synced: about 18 hours ago
JSON representation
Simple utility for extracting JSON-LD data from given URL
- Host: GitHub
- URL: https://github.com/baethon/extract-jsonld.js
- Owner: baethon
- License: mit
- Created: 2018-03-05T18:14:21.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2018-03-12T20:54:48.000Z (about 7 years ago)
- Last Synced: 2025-02-16T21:18:10.351Z (3 months ago)
- Language: JavaScript
- Size: 52.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# extract-jsonld.js
Simple utility for extracting JSON-LD data from given URL# Installation
```bash
npm i @baethon/extract-jsonld
```# Usage
```js
// extract :: String -> Future e Object
const extract = require('@baethon/extract-jsonld')// start extraction
extract('http://some.site/with-embeded-jsonld').fork(
console.warn,
jsonld => {}
)// or convert Future to promise
const jsonld = await extract('http://some.site/with-embeded-jsonld').promise()```
# How it works
The idea is simple: load [JSDOM](https://github.com/jsdom/jsdom) document find the right script and `JSON.parse` its contents.
Whole thing is wrapped inside [Future](https://github.com/fluture-js/Fluture) monad. So the process will start after calling `fork()` or `promise()` methods.
Script will fail when:
* fails to load JSDOM
* fails to find script tag
* fails to parse contents of the script