Skip to content

Commit 1d5c494

Browse files
authored
Merge pull request #178 from extractus/3.2.1
v3.2.1
2 parents 05dc91c + c74f6fd commit 1d5c494

File tree

7 files changed

+7739
-2
lines changed

7 files changed

+7739
-2
lines changed

build.js

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/**
2+
* build.js
3+
* @ndaidong
4+
**/
5+
6+
import { readFileSync, writeFileSync, copyFileSync, rmSync, mkdirSync } from 'fs'
7+
8+
import { buildSync } from 'esbuild'
9+
10+
const pkg = JSON.parse(readFileSync('./package.json', { encoding: 'utf-8' }))
11+
12+
rmSync('dist', {
13+
force: true,
14+
recursive: true,
15+
})
16+
mkdirSync('dist')
17+
18+
const buildTime = (new Date()).toISOString()
19+
const comment = [
20+
`// ${pkg.name}@${pkg.version}, by ${pkg.author}`,
21+
`built with esbuild at ${buildTime}`,
22+
`published under ${pkg.license} license`,
23+
].join(' - ')
24+
25+
const baseOpt = {
26+
entryPoints: ['src/main.js'],
27+
bundle: true,
28+
charset: 'utf8',
29+
target: ['es2020', 'node14'],
30+
pure: ['console.log', 'debug', 'alert'],
31+
legalComments: 'none',
32+
minify: false,
33+
sourcemap: false,
34+
write: true,
35+
}
36+
37+
const esmVersion = {
38+
...baseOpt,
39+
platform: 'browser',
40+
format: 'esm',
41+
mainFields: ['module'],
42+
outfile: 'dist/oembed-extractor.esm.js',
43+
banner: {
44+
js: comment,
45+
},
46+
}
47+
buildSync(esmVersion)
48+
49+
const cjsVersion = {
50+
...baseOpt,
51+
platform: 'node',
52+
format: 'cjs',
53+
mainFields: ['main'],
54+
outfile: 'dist/cjs/oembed-extractor.js',
55+
banner: {
56+
js: comment,
57+
},
58+
}
59+
buildSync(cjsVersion)
60+
61+
const cjspkg = {
62+
name: pkg.name,
63+
version: pkg.version,
64+
main: `./${pkg.name}.js`,
65+
}
66+
67+
writeFileSync(
68+
'dist/cjs/package.json',
69+
JSON.stringify(cjspkg, null, ' '),
70+
'utf8'
71+
)
72+
73+
// copy types definition to cjs dir
74+
copyFileSync('./index.d.ts', 'dist/cjs/index.d.ts')

build.test.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// release.test
2+
3+
/* eslint-env jest */
4+
5+
import {
6+
existsSync,
7+
readFileSync
8+
} from 'fs'
9+
10+
const pkg = JSON.parse(readFileSync('./package.json'))
11+
12+
const esmFile = './dist/oembed-extractor.esm.js'
13+
const cjsFile = './dist/cjs/oembed-extractor.js'
14+
const cjsPkg = JSON.parse(readFileSync('./dist/cjs/package.json'))
15+
16+
describe('Validate commonjs version output', () => {
17+
test(`Check if ${cjsFile} created`, () => {
18+
expect(existsSync(cjsFile)).toBeTruthy()
19+
})
20+
const constent = readFileSync(cjsFile, 'utf8')
21+
const lines = constent.split('\n')
22+
test('Check if file meta contains package info', () => {
23+
expect(lines[0].includes(`${pkg.name}@${pkg.version}`)).toBeTruthy()
24+
expect(lines[0].includes(pkg.author)).toBeTruthy()
25+
expect(lines[0].includes(pkg.license)).toBeTruthy()
26+
})
27+
test('Check if cjs package info updated', () => {
28+
expect(cjsPkg.name).toEqual(pkg.name)
29+
expect(cjsPkg.version).toEqual(pkg.version)
30+
})
31+
})
32+
33+
describe('Validate ESM version output', () => {
34+
test(`Check if ${esmFile} created`, () => {
35+
expect(existsSync(esmFile)).toBeTruthy()
36+
})
37+
const constent = readFileSync(esmFile, 'utf8')
38+
const lines = constent.split('\n')
39+
test('Check if file meta contains package info', () => {
40+
expect(lines[0].includes(`${pkg.name}@${pkg.version}`)).toBeTruthy()
41+
expect(lines[0].includes(pkg.author)).toBeTruthy()
42+
expect(lines[0].includes(pkg.license)).toBeTruthy()
43+
})
44+
})

dist/cjs/index.d.ts

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
// Type definitions for oembed-extractor
2+
// Project: https://github.com/extractus/oembed-extractor
3+
// Definitions by: BendingBender <https://github.com/BendingBender>
4+
// CodeBast4rd <https://github.com/CodeBast4rd>
5+
// Marc McIntosh <https://github.com/MarcMcIntosh>
6+
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
7+
8+
export interface Endpoint {
9+
schemes?: string[];
10+
url: string;
11+
formats?: string[]; // "json" "xml"
12+
discovery?: boolean;
13+
}
14+
15+
export interface Provider {
16+
"provider_name": string;
17+
"provider_url": string;
18+
"endpoints": Endpoint[];
19+
}
20+
21+
export interface FindProviderResult {
22+
"fetchEndpoint": string;
23+
"provider_name": string;
24+
"provider_url": string;
25+
}
26+
27+
/**
28+
* Basic data structure of every oembed response see https://oembed.com/
29+
*/
30+
export interface OembedData {
31+
type: 'rich' | 'video' | 'photo' | 'link';
32+
version: string;
33+
/** A text title, describing the resource. */
34+
title?: string;
35+
/** The name of the author/owner of the resource. */
36+
author_name?: string;
37+
/** A URL for the author/owner of the resource. */
38+
author_url?: string;
39+
/** The name of the resource provider. */
40+
provider_name?: string;
41+
/** The url of the resource provider. */
42+
provider_url?: string;
43+
/** The suggested cache lifetime for this resource, in seconds. Consumers may choose to use this value or not. */
44+
cache_age?: string | number;
45+
/**
46+
* A URL to a thumbnail image representing the resource.
47+
* The thumbnail must respect any maxwidth and maxheight parameters.
48+
* If this parameter is present, thumbnail_width and thumbnail_height must also be present.
49+
*/
50+
thumbnail_url?: string;
51+
/**
52+
* The width of the optional thumbnail.
53+
* If this parameter is present, thumbnail_url and thumbnail_height must also be present.
54+
*/
55+
thumbnail_width?: number;
56+
/**
57+
* The height of the optional thumbnail.
58+
* If this parameter is present, thumbnail_url and thumbnail_width must also be present.
59+
*/
60+
thumbnail_height?: number;
61+
}
62+
63+
export interface LinkTypeData extends OembedData {
64+
readonly type: 'link';
65+
}
66+
67+
export interface PhotoTypeData extends OembedData {
68+
readonly type: 'photo';
69+
/**
70+
* The source URL of the image. Consumers should be able to insert this URL into an <img> element.
71+
* Only HTTP and HTTPS URLs are valid.
72+
*/
73+
url: string;
74+
/** The width in pixels of the image specified in the url parameter. */
75+
width: number;
76+
/** The height in pixels of the image specified in the url parameter. */
77+
height: number;
78+
}
79+
80+
export interface VideoTypeData extends OembedData {
81+
readonly type: 'video';
82+
/**
83+
* The HTML required to embed a video player.
84+
* The HTML should have no padding or margins.
85+
* Consumers may wish to load the HTML in an off-domain iframe to avoid XSS vulnerabilities.
86+
*/
87+
html: string;
88+
/** The width in pixels required to display the HTML. */
89+
width: number;
90+
/** The height in pixels required to display the HTML. */
91+
height: number;
92+
}
93+
94+
export interface RichTypeData extends OembedData {
95+
readonly type: 'rich';
96+
/**
97+
* The HTML required to display the resource.
98+
* The HTML should have no padding or margins.
99+
* Consumers may wish to load the HTML in an off-domain iframe to avoid XSS vulnerabilities.
100+
* The markup should be valid XHTML 1.0 Basic.
101+
*/
102+
html: string;
103+
/** The width in pixels required to display the HTML. */
104+
width: number;
105+
/** The height in pixels required to display the HTML. */
106+
height: number;
107+
}
108+
109+
export interface Params {
110+
/**
111+
* max width of embed size
112+
* Default: null
113+
*/
114+
maxwidth?: number
115+
/**
116+
* max height of embed size
117+
* Default: null
118+
*/
119+
maxheight?: number
120+
/**
121+
* theme for the embed, such as "dark" or "light"
122+
* Default: null
123+
*/
124+
theme?: string
125+
/**
126+
* language for the embed, e.g. "en", "fr", "vi", etc
127+
* Default: null
128+
*/
129+
lang?: string
130+
}
131+
132+
export interface ProxyConfig {
133+
target?: string;
134+
headers?: Record<string, string>;
135+
}
136+
137+
export interface FetchOptions {
138+
/**
139+
* list of request headers
140+
* default: null
141+
*/
142+
headers?: Record<string, string>;
143+
/**
144+
* the values to configure proxy
145+
* default: null
146+
*/
147+
proxy?: ProxyConfig;
148+
/**
149+
* http proxy agent
150+
* default: null
151+
*/
152+
agent?: object;
153+
/**
154+
* signal to terminate request
155+
* default: null
156+
*/
157+
signal?: object;
158+
}
159+
160+
export function extract(url: string, params?: Params, fetchOptions?: FetchOptions): Promise<OembedData>;
161+
162+
export function hasProvider(url: string): boolean
163+
164+
export function findProvider(url: string): FindProviderResult
165+
166+
export function setProviderList(providers: Provider[]): void

0 commit comments

Comments
 (0)