Skip to content

crushlovely/oembed-parser

 
 

Repository files navigation

oembed-parser

Extract eEmbed content from given URL.

NPM Build Status Coverage Status

Demo

Installation

npm install oembed-parser

Usage

import {
  extract,
} from 'oembed-parser';

const url = 'https://www.youtube.com/watch?v=8jPQjjsBbIc';

extract(url).then((oembed) => {
  console.log(oembed);
}).catch((err) => {
  console.trace(err);
});

APIs

.extract(String url [, Object params])

Extract oEmbed data from specified url. Return: a Promise

Optional argument params is an object with it we can set maxwidth and/or maxheight those are used to scale embed size to fit your container size. Please refer oEmbed/Full Spec/Consumer Request for more info.

Here is how we can use oembed-parser in async/await style:

import {
  extract
} from 'oembed-parser';

const getOembed = async (url) => {
  try {
    const oembed = await extract(url);
    return oembed;
  } catch (err) {
    console.trace(err);
  }
};

.hasProvider(String URL)

Return boolean. True if the URL matches with any provider in the list.

.setProviderList(Array of provider definitions)

Sets the list of providers to use, overriding the defaults.

This can be useful for whitelisting only certain providers, or for adding custom providers.

For the expected format, see the default list.

Provider list

List of resource providers is a clone of oembed.com and available here.

Test

git clone https://github.com/ndaidong/oembed-parser.git
cd oembed-parser
npm install
npm test

# quick evaluation
npm run eval {URL_TO_PARSE_OEMBED}

License

The MIT License (MIT)

Packages

No packages published

Languages

  • JavaScript 100.0%