Skip to content

Simple utility for extracting JSON-LD data from given URL

License

Notifications You must be signed in to change notification settings

baethon/extract-jsonld.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

extract-jsonld.js

Simple utility for extracting JSON-LD data from given URL

Installation

npm i @baethon/extract-jsonld

Usage

// 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 document find the right script and JSON.parse its contents.

Whole thing is wrapped inside Future 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

About

Simple utility for extracting JSON-LD data from given URL

Resources

License

Stars

Watchers

Forks

Packages

No packages published