Skip to content

Commit e4b536a

Browse files
authored
Merge pull request #120 from ndaidong/v3.0.0rc1
v3.0.0rc1
2 parents 77228e4 + 09c77d9 commit e4b536a

25 files changed

+3346
-102
lines changed

.github/workflows/ci-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212

1313
strategy:
1414
matrix:
15-
node_version: [10.14.2, 14.x, 15.x, 16.x, 17.x]
15+
node_version: [14.x, 15.x, 16.x, 17.x]
1616

1717
steps:
1818
- uses: actions/checkout@v2

README.md

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,28 +16,28 @@ Extract oEmbed content from given URL.
1616
- [Example FaaS](https://extractor.pwshub.com/oembed/parse?url=https://www.youtube.com/watch?v=8jPQjjsBbIc&apikey=demo-orePhhidnWKWPvF8EYKap7z55cN)
1717

1818

19-
## Installation
19+
## Setup
2020

21-
```bash
22-
$ npm install oembed-parser
21+
- Node.js
2322

24-
# pnpm
25-
$ pnpm install oembed-parser
23+
```bash
24+
npm i oembed-parser
2625

27-
# yarn
28-
$ yarn add oembed-parser
29-
```
26+
# pnpm
27+
pnpm i oembed-parser
3028

29+
# yarn
30+
yarn add oembed-parser
31+
```
3132

32-
## Usage
33+
### Usage
3334

3435
```js
35-
const { extract } = require('oembed-parser')
36-
37-
// es6 module syntax
3836
import { extract } from 'oembed-parser'
3937

40-
// test
38+
// with CommonJS environments
39+
// const { extract } = require('oembed-parser/dist/cjs/oembed-parser.js')
40+
4141
const url = 'https://www.youtube.com/watch?v=8jPQjjsBbIc'
4242

4343
extract(url).then((oembed) => {
@@ -47,6 +47,12 @@ extract(url).then((oembed) => {
4747
})
4848
```
4949

50+
##### Note:
51+
52+
> Since Node.js v14, ECMAScript modules [have became the official standard format](https://nodejs.org/docs/latest-v14.x/api/esm.html#esm_modules_ecmascript_modules).
53+
> Just ensure that you are [using module system](https://nodejs.org/api/packages.html#determining-module-system) and enjoy with ES6 import/export syntax.
54+
55+
5056
## APIs
5157

5258
#### .extract(String url [, Object params])
@@ -56,7 +62,7 @@ Load and extract oembed data.
5662
Example:
5763

5864
```js
59-
const { extract } = require('oembed-parser')
65+
import { extract } from 'oembed-parser'
6066

6167
const getOembed = async (url) => {
6268
try {
@@ -91,7 +97,7 @@ Check if a URL matches with any provider in the list.
9197
Examples:
9298

9399
```js
94-
const { hasProvider } = require('oembed-parser')
100+
import { hasProvider } from 'oembed-parser'
95101

96102
hasProvider('https://www.youtube.com/watch?v=ciS8aCrX-9s') // return true
97103
hasProvider('https://trello.com/b/BO3bg7yn/notes') // return false
@@ -104,7 +110,7 @@ Get the provider which is relevant to given URL.
104110
For example:
105111

106112
```js
107-
const { findProvider } = require('oembed-parser')
113+
import { findProvider } from 'oembed-parser'
108114

109115
findProvider('https://www.facebook.com/video.php?v=999999999')
110116
```
@@ -131,7 +137,7 @@ Default list of resource providers is synchronized from [oembed.com](http://oemb
131137
For example:
132138

133139
```js
134-
const { setProviderList } = require('oembed-parser')
140+
import { setProviderList } from 'oembed-parser'
135141

136142
const providers = [
137143
{
@@ -163,7 +169,7 @@ Default option:
163169
```js
164170
{
165171
headers: {
166-
'user-agent': 'Mozilla/5.0 (X11; Linux i686; rv:94.0) Gecko/20100101 Firefox/94.0',
172+
'user-agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:95.0) Gecko/20100101 Firefox/95.0',
167173
accept: 'application/json; charset=utf-8'
168174
},
169175
responseType: 'json',

build.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/**
2+
* build.js
3+
* @ndaidong
4+
**/
5+
6+
import { readFileSync, writeFileSync } from 'fs'
7+
import { execSync } from 'child_process'
8+
9+
import { buildSync } from 'esbuild'
10+
11+
const pkg = JSON.parse(readFileSync('./package.json'))
12+
13+
execSync('rm -rf dist')
14+
execSync('mkdir dist')
15+
16+
const buildTime = (new Date()).toISOString()
17+
const comment = [
18+
`// ${pkg.name}@${pkg.version}, by ${pkg.author}`,
19+
`built with esbuild at ${buildTime}`,
20+
`published under ${pkg.license} license`
21+
].join(' - ')
22+
23+
const baseOpt = {
24+
entryPoints: ['src/main.js'],
25+
bundle: true,
26+
charset: 'utf8',
27+
target: ['es2020', 'node14'],
28+
minify: false,
29+
write: true
30+
}
31+
32+
const cjsVersion = {
33+
...baseOpt,
34+
platform: 'node',
35+
format: 'cjs',
36+
mainFields: ['main'],
37+
outfile: `dist/cjs/${pkg.name}.js`,
38+
banner: {
39+
js: comment
40+
}
41+
}
42+
buildSync(cjsVersion)
43+
44+
const cjspkg = {
45+
name: pkg.name + '-cjs',
46+
version: pkg.version,
47+
main: `./${pkg.name}.js`
48+
}
49+
writeFileSync(
50+
'dist/cjs/package.json',
51+
JSON.stringify(cjspkg, null, ' '),
52+
'utf8'
53+
)

cjs-eval.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// cjs-eval.js
2+
// to quickly test with a single url or file
3+
4+
const { extract } = require('./dist/cjs/oembed-parser')
5+
6+
const run = async (url) => {
7+
try {
8+
const art = await extract(url)
9+
console.log(art)
10+
} catch (err) {
11+
console.trace(err)
12+
}
13+
}
14+
15+
const init = (argv) => {
16+
if (argv.length === 3) {
17+
const url = argv[2]
18+
return run(url)
19+
}
20+
return 'Nothing to do!'
21+
}
22+
23+
init(process.argv)

0 commit comments

Comments
 (0)