Skip to content

Commit

Permalink
Merge ebff70e into 44fba5f
Browse files Browse the repository at this point in the history
  • Loading branch information
ndaidong committed Sep 18, 2022
2 parents 44fba5f + ebff70e commit 7da3745
Show file tree
Hide file tree
Showing 28 changed files with 11,496 additions and 25,950 deletions.
52 changes: 5 additions & 47 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,13 @@ Extract oEmbed content from given URL.
import { extract } from 'oembed-parser'

// with CommonJS environments

// const { extract } = require('oembed-parser')

// or specify exactly path to cjs variant
// const { extract } = require('oembed-parser/dist/cjs/oembed-parser.js')

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

extract(url).then((oembed) => {
console.log(oembed)
Expand Down Expand Up @@ -85,40 +89,6 @@ Here are several popular params:
Note that some params are supported by these providers but not by the others.
Please see the provider's oEmbed API docs carefully for exact information.

### `.hasProvider(String URL)`

Check if a URL matches with any provider in the list.

Examples:

```js
import { hasProvider } from 'oembed-parser'

hasProvider('https://www.youtube.com/watch?v=ciS8aCrX-9s') // return true
hasProvider('https://trello.com/b/BO3bg7yn/notes') // return false
```

### `.findProvider(String URL)`

Get the provider which is relevant to given URL.

For example:

```js
import { findProvider } from 'oembed-parser'

findProvider('https://www.facebook.com/video.php?v=999999999')
```

Result looks like below:

```json
{
fetchEndpoint: 'https://graph.facebook.com/v10.0/oembed_video',
providerName: 'Facebook',
providerUrl: 'https://www.facebook.com/'
}
```

### `.setProviderList(Array providers)`

Expand Down Expand Up @@ -154,18 +124,6 @@ const providers = [
setProviderList(providers)
```

### `.setRequestOptions(Object requestOptions)`

Define options to call oembed HTTP request.

`oembed-parser` is using [axios](https://github.com/axios/axios) to send HTTP requests. Please refer [axios' request config](https://axios-http.com/docs/req_config) for more info.

### `.getRequestOptions()`

Return current request options.

Default values can be found [here](https://github.com/ndaidong/oembed-parser/blob/main/src/config.js#L5).

## Facebook and Instagram

In order to work with the links from Facebook and Instagram, you need a [reviewed Facebook's app](https://developers.facebook.com/docs/app-review) with [oEmbed Read](https://developers.facebook.com/docs/features-reference/oembed-read) permission.
Expand Down
31 changes: 15 additions & 16 deletions build.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @ndaidong
**/

import { readFileSync, writeFileSync, copyFileSync } from 'fs'
import { readFileSync } from 'fs'
import { execSync } from 'child_process'

import { buildSync } from 'esbuild'
Expand All @@ -25,7 +25,10 @@ const baseOpt = {
bundle: true,
charset: 'utf8',
target: ['es2020', 'node14'],
pure: ['console.log', 'debug', 'alert'],
legalComments: 'none',
minify: false,
sourcemap: false,
write: true
}

Expand All @@ -34,25 +37,21 @@ const cjsVersion = {
platform: 'node',
format: 'cjs',
mainFields: ['main'],
outfile: `dist/cjs/${pkg.name}.js`,
outfile: `dist/${pkg.name}.js`,
banner: {
js: comment
}
}
buildSync(cjsVersion)

const cjspkg = {
name: pkg.name + '-cjs',
version: pkg.version,
main: `./${pkg.name}.js`
const esmVersion = {
...baseOpt,
platform: 'browser',
format: 'esm',
mainFields: ['module'],
outfile: `dist/${pkg.name}.esm.js`,
banner: {
js: comment
}
}
writeFileSync(
'dist/cjs/package.json',
JSON.stringify(cjspkg, null, ' '),
'utf8'
)

copyFileSync(
'src/utils/providers.latest.js',
'dist/cjs/providers.latest.js'
)
buildSync(esmVersion)
21 changes: 15 additions & 6 deletions build.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,13 @@ import {

const pkg = JSON.parse(readFileSync('./package.json'))

const cjsFile = `./dist/cjs/${pkg.name}.js`
const cjsPkg = JSON.parse(readFileSync('./dist/cjs/package.json'))
const cjsFile = `./dist/${pkg.name}.js`
const esmFile = `./dist/${pkg.name}.esm.js`

describe('Validate commonjs version output', () => {
test(`Check if ${cjsFile} created`, () => {
expect(existsSync(cjsFile)).toBeTruthy()
})
test('Check if cjs package info updated', () => {
expect(cjsPkg.name).toEqual(`${pkg.name}-cjs`)
expect(cjsPkg.version).toEqual(pkg.version)
})
const constent = readFileSync(cjsFile, 'utf8')
const lines = constent.split('\n')
test('Check if file meta contains package info', () => {
Expand All @@ -28,3 +24,16 @@ describe('Validate commonjs version output', () => {
expect(lines[0].includes(pkg.license)).toBeTruthy()
})
})

describe('Validate ESM version output', () => {
test(`Check if ${esmFile} created`, () => {
expect(existsSync(esmFile)).toBeTruthy()
})
const constent = readFileSync(esmFile, 'utf8')
const lines = constent.split('\n')
test('Check if file meta contains package info', () => {
expect(lines[0].includes(`${pkg.name}@${pkg.version}`)).toBeTruthy()
expect(lines[0].includes(pkg.author)).toBeTruthy()
expect(lines[0].includes(pkg.license)).toBeTruthy()
})
})
2 changes: 1 addition & 1 deletion cjs-eval.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// cjs-eval.js
// to quickly test with a single url or file

const { extract } = require('./dist/cjs/oembed-parser')
const { extract } = require('./dist/oembed-parser')

const run = async (url) => {
try {
Expand Down
Loading

0 comments on commit 7da3745

Please sign in to comment.