New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

oembed-parser

Package Overview
Dependencies
Maintainers
3
Versions
70
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

oembed-parser - npm Package Compare versions

Comparing version 2.0.0-rc1 to 2.0.0-rc2

2

package.json
{
"version": "2.0.0rc1",
"version": "2.0.0rc2",
"name": "oembed-parser",

@@ -4,0 +4,0 @@ "description": "Get oEmbed data from given URL.",

@@ -7,3 +7,3 @@ # oembed-parser

[![CI test](https://github.com/ndaidong/oembed-parser/workflows/ci-test/badge.svg)](https://github.com/ndaidong/oembed-parser/actions)
[![Coverage Status](https://coveralls.io/repos/github/ndaidong/oembed-parser/badge.svg)](https://coveralls.io/github/ndaidong/oembed-parser)
[![Coverage Status](https://coveralls.io/repos/github/ndaidong/oembed-parser/badge.svg?branch=main)](https://coveralls.io/github/ndaidong/oembed-parser?branch=main)
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=ndaidong_oembed-parser&metric=alert_status)](https://sonarcloud.io/dashboard?id=ndaidong_oembed-parser)

@@ -13,7 +13,2 @@ [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)

### Important note:
- [Changes with Instagram](#changes-with-instagram)
## Demo

@@ -20,0 +15,0 @@

@@ -101,109 +101,129 @@ // main

test('test extract YouTube link', async () => {
const url = 'https://www.youtube.com/watch?v=ciS8aCrX-9s'
const provider = findProvider(url)
const { baseUrl, path } = parseUrl(provider.fetchEndpoint)
const scope = nock(baseUrl, { encodedQueryParams: true })
const params = new URLSearchParams({
url,
format: 'json'
})
scope.get(path)
.query(params)
.replyWithFile(200, './test-data/youtube_ciS8aCrX-9s.json', {
'Content-Type': 'application/json'
})
const result = await extract(url)
expect(hasRichKeys(result)).toBe(true)
expect(result.provider_name).toEqual('YouTube')
expect(result.type).toEqual('video')
})
describe('test if extract() with some popular providers', () => {
const cases = [
{
input: {
url: 'https://youtu.be/qQpb1oCernE',
file: './test-data/youtube.json'
},
expected: {
provider_name: 'YouTube',
type: 'video'
},
checkFn: hasRichKeys
},
{
input: {
url: 'https://www.youtube.com/watch?v=ciS8aCrX-9s',
file: './test-data/youtube_ciS8aCrX-9s.json'
},
expected: {
provider_name: 'YouTube',
type: 'video'
},
checkFn: hasRichKeys
},
{
input: {
url: 'https://twitter.com/ndaidong/status/1173592062878314497',
file: './test-data/twitter.json'
},
expected: {
provider_name: 'Twitter',
type: 'rich'
},
checkFn: hasRichKeys
},
{
input: {
url: 'https://www.instagram.com/p/ic7kRDqOlt/',
params: {
access_token: '845078789498971|8ff3ab4ddd45b8f018b35c4fb7edac62'
},
file: './test-data/instagram_ic7kRDqOlt.json'
},
expected: {
provider_name: 'Instagram',
type: 'rich'
},
checkFn: hasInstagramKeys
},
{
input: {
url: 'https://www.facebook.com/facebook/videos/10153231379946729/',
params: {
access_token: '845078789498971|8ff3ab4ddd45b8f018b35c4fb7edac62'
},
file: './test-data/facebook.json'
},
expected: {
provider_name: 'Facebook',
type: 'video'
},
checkFn: hasRichKeys
},
{
input: {
url: 'https://flic.kr/p/2iYctUr',
file: './test-data/flickr_2iYctUr.json'
},
expected: {
provider_name: 'Flickr',
type: 'photo',
maxwidth: 1024,
maxheight: 768
},
checkFn: hasPhotoKeys
},
{
input: {
url: 'https://flic.kr/p/2iYctUr',
file: './test-data/flickr_2iYctUr_640x480.json'
},
expected: {
provider_name: 'Flickr',
type: 'photo',
maxwidth: 640,
maxheight: 480
},
checkFn: hasPhotoKeys
}
]
test('test extract Flickr link', async () => {
const url = 'https://flic.kr/p/2iYctUr'
const provider = findProvider(url)
const { baseUrl, path } = parseUrl(provider.fetchEndpoint)
const scope = nock(baseUrl, { encodedQueryParams: true })
const params = new URLSearchParams({
url,
format: 'json'
})
scope.get(path)
.query(params)
.replyWithFile(200, './test-data/flickr_2iYctUr.json', {
'Content-Type': 'application/json'
})
const result = await extract(url)
expect(hasPhotoKeys(result)).toBe(true)
expect(result.provider_name).toEqual('Flickr')
expect(result.type).toEqual('photo')
expect(result.width).toEqual(1024)
expect(result.height).toEqual(768)
})
cases.forEach(({ input, expected, checkFn }) => {
const { url, file, params = {} } = input
test(` check fetchEmbed("${url}")`, async () => {
const provider = findProvider(url)
const { baseUrl, path } = parseUrl(provider.fetchEndpoint)
test('test extract Flickr link with params', async () => {
const url = 'https://flic.kr/p/2iYctUr'
const provider = findProvider(url)
const { baseUrl, path } = parseUrl(provider.fetchEndpoint)
const scope = nock(baseUrl, { encodedQueryParams: true })
const params = new URLSearchParams({
url,
maxwidth: 640,
maxheight: 480,
format: 'json'
})
scope.get(path)
.query(params)
.replyWithFile(200, './test-data/flickr_2iYctUr_640x480.json', {
'Content-Type': 'application/json'
})
const result = await extract(url, { maxwidth: 640, maxheight: 480 })
expect(hasPhotoKeys(result)).toBe(true)
expect(result.provider_name).toEqual('Flickr')
expect(result.type).toEqual('photo')
expect(result.width).toBeLessThanOrEqual(640)
expect(result.height).toBeLessThanOrEqual(480)
})
const scope = nock(baseUrl, { encodedQueryParams: true })
const queries = new URLSearchParams({
url,
format: 'json',
...params
})
scope.get(path)
.query(queries)
.replyWithFile(200, file, {
'Content-Type': 'application/json'
})
test('test extract Instagram link', async () => {
const url = 'https://www.instagram.com/p/ic7kRDqOlt/'
const provider = findProvider(url)
const { baseUrl, path } = parseUrl(provider.fetchEndpoint)
const scope = nock(baseUrl, { encodedQueryParams: true })
const params = new URLSearchParams({
url,
format: 'json',
access_token: '845078789498971|8ff3ab4ddd45b8f018b35c4fb7edac62'
})
scope.get(path)
.query(params)
.replyWithFile(200, './test-data/instagram_ic7kRDqOlt.json', {
'Content-Type': 'application/json'
const {
maxwidth = 0,
maxheight = 0
} = params
const result = await extract(url, provider, { maxwidth, maxheight })
expect(result).toBeTruthy()
expect(checkFn(result)).toBe(true)
expect(result.provider_name).toEqual(expected.provider_name)
expect(result.type).toEqual(expected.type)
if (maxwidth > 0) {
expect(result.width).toBeLessThanOrEqual(expected.maxwidth)
}
if (maxheight > 0) {
expect(result.height).toBeLessThanOrEqual(expected.maxheight)
}
})
const result = await extract(url)
expect(hasInstagramKeys(result)).toBe(true)
expect(result.provider_name).toEqual('Instagram')
expect(result.type).toEqual('rich')
})
test('test extract Facebook video', async () => {
const url = 'https://www.facebook.com/facebook/videos/10153231379946729/'
const provider = findProvider(url)
const { baseUrl, path } = parseUrl(provider.fetchEndpoint)
const scope = nock(baseUrl, { encodedQueryParams: true })
const params = new URLSearchParams({
url,
format: 'json',
access_token: '845078789498971|8ff3ab4ddd45b8f018b35c4fb7edac62'
})
scope.get(path)
.query(params)
.replyWithFile(200, './test-data/facebook.json', {
'Content-Type': 'application/json'
})
const result = await extract(url)
expect(hasRichKeys(result)).toBe(true)
expect(result).toBeTruthy()
expect(result.provider_name).toEqual('Facebook')
expect(result.type).toEqual('video')
})

@@ -210,0 +230,0 @@

@@ -17,117 +17,102 @@ // fetchEmbed.test

test('test fetchEmbed(youtube video)', async () => {
const url = 'https://youtu.be/qQpb1oCernE'
const provider = findProvider(url)
const { baseUrl, path } = parseUrl(provider.fetchEndpoint)
describe('test if fetchEmbed() works correctly', () => {
const cases = [
{
input: {
url: 'https://youtu.be/qQpb1oCernE',
file: './test-data/youtube.json'
},
expected: {
provider_name: 'YouTube',
type: 'video'
}
},
{
input: {
url: 'https://twitter.com/ndaidong/status/1173592062878314497',
file: './test-data/twitter.json'
},
expected: {
provider_name: 'Twitter',
type: 'rich'
}
},
{
input: {
url: 'https://www.facebook.com/facebook/videos/10153231379946729/',
params: {
access_token: '845078789498971|8ff3ab4ddd45b8f018b35c4fb7edac62'
},
file: './test-data/facebook.json'
},
expected: {
provider_name: 'Facebook',
type: 'video'
}
},
{
input: {
url: 'http://farm4.static.flickr.com/3123/2341623661_7c99f48bbf_m.jpg',
file: './test-data/flickr-default.json'
},
expected: {
provider_name: 'Flickr',
type: 'photo',
maxwidth: 1024,
maxheight: 683
}
},
{
input: {
url: 'http://farm4.static.flickr.com/3123/2341623661_7c99f48bbf_m.jpg',
params: {
maxwidth: 800,
maxheight: 400
},
file: './test-data/flickr-sizelimit.json'
},
expected: {
provider_name: 'Flickr',
type: 'photo',
maxwidth: 800,
maxheight: 400
}
}
]
const scope = nock(baseUrl, { encodedQueryParams: true })
const params = new URLSearchParams({
url,
format: 'json'
})
scope.get(path)
.query(params)
.replyWithFile(200, './test-data/youtube.json', {
'Content-Type': 'application/json'
})
cases.forEach(({ input, expected }) => {
const { url, file, params = {} } = input
test(` check fetchEmbed("${url}")`, async () => {
const provider = findProvider(url)
const { baseUrl, path } = parseUrl(provider.fetchEndpoint)
const result = await fetchEmbed(url, provider)
expect(result).toBeTruthy()
expect(result.provider_name).toEqual('YouTube')
expect(result.type).toEqual('video')
})
const scope = nock(baseUrl, { encodedQueryParams: true })
const queries = new URLSearchParams({
url,
...params,
format: 'json'
})
scope.get(path)
.query(queries)
.replyWithFile(200, file, {
'Content-Type': 'application/json'
})
test('test fetchEmbed(twitter tweet)', async () => {
const url = 'https://twitter.com/ndaidong/status/1173592062878314497'
const provider = findProvider(url)
const { baseUrl, path } = parseUrl(provider.fetchEndpoint)
const {
maxwidth = 0,
maxheight = 0
} = params
const scope = nock(baseUrl, { encodedQueryParams: true })
const params = new URLSearchParams({
url,
format: 'json'
})
scope.get(path)
.query(params)
.replyWithFile(200, './test-data/twitter.json', {
'Content-Type': 'application/json'
const result = await fetchEmbed(url, provider, { maxwidth, maxheight })
expect(result).toBeTruthy()
expect(result.provider_name).toEqual(expected.provider_name)
expect(result.type).toEqual(expected.type)
if (maxwidth > 0) {
expect(result.width).toBeLessThanOrEqual(expected.maxwidth)
}
if (maxheight > 0) {
expect(result.height).toBeLessThanOrEqual(expected.maxheight)
}
})
const result = await fetchEmbed(url, provider)
expect(result).toBeTruthy()
expect(result.provider_name).toEqual('Twitter')
expect(result.type).toEqual('rich')
})
test('test fetchEmbed(facebook video)', async () => {
const url = 'https://www.facebook.com/facebook/videos/10153231379946729/'
const provider = findProvider(url)
const { baseUrl, path } = parseUrl(provider.fetchEndpoint)
const scope = nock(baseUrl, { encodedQueryParams: true })
const params = new URLSearchParams({
url,
format: 'json',
access_token: '845078789498971|8ff3ab4ddd45b8f018b35c4fb7edac62'
})
scope.get(path)
.query(params)
.replyWithFile(200, './test-data/facebook.json', {
'Content-Type': 'application/json'
})
const result = await fetchEmbed(url, provider)
expect(result).toBeTruthy()
expect(result.provider_name).toEqual('Facebook')
expect(result.type).toEqual('video')
})
test('test fetchEmbed(flikr photo)', async () => {
const url = 'http://farm4.static.flickr.com/3123/2341623661_7c99f48bbf_m.jpg'
const provider = findProvider(url)
const { baseUrl, path } = parseUrl(provider.fetchEndpoint)
const scope = nock(baseUrl, { encodedQueryParams: true })
const params = new URLSearchParams({
url,
format: 'json'
})
scope.get(path)
.query(params)
.replyWithFile(200, './test-data/flickr-default.json', {
'Content-Type': 'application/json'
})
const result = await fetchEmbed(url, provider)
expect(result).toBeTruthy()
expect(result.provider_name).toEqual('Flickr')
expect(result.type).toEqual('photo')
expect(result.width).toEqual(1024)
expect(result.height).toEqual(683)
})
test('test fetchEmbed(flikr photo) with size limit', async () => {
const url = 'http://farm4.static.flickr.com/3123/2341623661_7c99f48bbf_m.jpg'
const provider = findProvider(url)
const { baseUrl, path } = parseUrl(provider.fetchEndpoint)
const scope = nock(baseUrl, { encodedQueryParams: true })
const params = new URLSearchParams({
url,
maxwidth: 800,
maxheight: 400,
format: 'json'
})
scope.get(path)
.query(params)
.replyWithFile(200, './test-data/flickr-sizelimit.json', {
'Content-Type': 'application/json'
})
const result = await fetchEmbed(url, provider, { maxwidth: 800, maxheight: 400 })
expect(result).toBeTruthy()
expect(result.provider_name).toEqual('Flickr')
expect(result.type).toEqual('photo')
expect(result.width).toBeLessThan(1024)
expect(result.height).toBeLessThan(683)
})
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc