@social-embed/lib
Advanced tools
Comparing version 0.1.0-next.7 to 0.1.0-next.8
@@ -10,6 +10,21 @@ --- | ||
## 0.1.0-next.6 (2023-11-25) | ||
## 0.1.0-next.8 (2024-12-31) | ||
### Breaking changes | ||
- Security: Fixes to mitigate polynomial regex expressions (#24) | ||
- Limit URL lengths for Loom, EdPuzzle, and Wistia | ||
### Development | ||
- Move from `prettier` to `biome` (#27) | ||
- Move from `eslint` to ~`oxc` (#26)~ `biome` (#27) | ||
Faster linting, as it is rust-based. | ||
## 0.1.0-next.7 (2023-11-25) | ||
### Breaking changes | ||
- Security: Fixes to mitigate polynomial regex expressions (#17) | ||
@@ -36,2 +51,6 @@ | ||
## 0.1.0-next.6 (2023-11-25) | ||
_Skipped directly to v0.1.0-next.7_ due to publishing error. | ||
## 0.1.0-next.5 (2023-10-15) | ||
@@ -38,0 +57,0 @@ |
@@ -1,5 +0,5 @@ | ||
export * from "./providers"; | ||
export { Provider } from "./constants"; | ||
export type { ProviderKey, ProviderType } from "./types"; | ||
export { ProviderIdFunctionMap, ProviderIdUrlFunctionMap, getProviderFromUrl, convertUrlToEmbedUrl, } from "./utils"; | ||
export * from './providers'; | ||
export { Provider } from './constants'; | ||
export type { ProviderKey, ProviderType } from './types'; | ||
export { ProviderIdFunctionMap, ProviderIdUrlFunctionMap, getProviderFromUrl, convertUrlToEmbedUrl, } from './utils'; | ||
//# sourceMappingURL=index.d.ts.map |
132
dist/lib.js
@@ -7,26 +7,41 @@ const S = (t) => { | ||
} | ||
}, a = /^(?:(?:https?):)?(?:\/\/)?(?:www\.)?(?:youtube(?:-nocookie)?.com|youtu.be)(?:\/watch\?v)?[=/]([a-zA-Z0-9_-]{11})(?:\\?|=|&|$)/, d = (t) => { | ||
}, d = /^(?:(?:https?):)?(?:\/\/)?(?:www\.)?(?:youtube(?:-nocookie)?.com|youtu.be)(?:\/watch\?v)?[=/]([a-zA-Z0-9_-]{11})(?:\\?|=|&|$)/, a = (t) => { | ||
var o; | ||
return t ? ((o = t.match(a)) == null ? void 0 : o[1]) ?? "" : ""; | ||
}, u = (t) => `https://www.youtube.com/embed/${t}`, l = /^(?:(?:https?):)?(?:\/\/)?(?:www\.)?(?:(?:dailymotion\.com(?:\/embed)?\/video)|dai\.ly)\/([a-zA-Z0-9]+)(?:_[\w_-]+)?(?:\?playlist=[a-zA-Z0-9]+)?$/, p = (t) => { | ||
return t ? ((o = t.match(d)) == null ? void 0 : o[1]) ?? "" : ""; | ||
}, p = (t) => `https://www.youtube.com/embed/${t}`, y = /^(?:(?:https?):)?(?:\/\/)?(?:www\.)?(?:(?:dailymotion\.com(?:\/embed)?\/video)|dai\.ly)\/([a-zA-Z0-9]+)(?:_[\w_-]+)?(?:\?playlist=[a-zA-Z0-9]+)?$/, w = (t) => { | ||
var o; | ||
return ((o = t.match(l)) == null ? void 0 : o[1]) ?? ""; | ||
}, y = (t) => `https://www.dailymotion.com/embed/video/${t}`, w = /^(?:(?:https?):)?(?:\/\/)?(?:embed\.|open\.)(?:spotify\.com\/)(?:(album|track|playlist)\/|\?uri=spotify:track:)([-\w]{22})(?:\?si=[_-\w]{22})?$/, f = /spotify:(?:(album|track|playlist):|\?uri=spotify:track:)([-\w]{22})/, b = (t) => { | ||
const [, o, r] = t.match(w) || t.match(f) || []; | ||
return [r, o]; | ||
}, h = (t, o) => `https://open.spotify.com/embed/${o}/${t}`, U = /(?:(?:https?):)?(?:\/\/)?(?:www\.|player\.)?vimeo\.com\/(?:channels\/(?:\w+\/)?|groups\/(?:[^/]*)\/videos\/|video\/|)(\d+)(?:|\/\?)/, g = (t) => { | ||
return ((o = t.match(y)) == null ? void 0 : o[1]) ?? ""; | ||
}, l = (t) => `https://www.dailymotion.com/embed/video/${t}`, u = /^(?:(?:https?):)?(?:\/\/)?(?:embed\.|open\.)(?:spotify\.com\/)(?:(album|track|playlist)\/|\?uri=spotify:track:)([-\w]{22})(?:\?si=[_-\w]{22})?$/, f = /spotify:(?:(album|track|playlist):|\?uri=spotify:track:)([-\w]{22})/, h = (t) => { | ||
const [, o, i] = t.match(u) || t.match(f) || []; | ||
return [i, o]; | ||
}, b = (t, ...o) => `https://open.spotify.com/embed/${typeof o[0] == "string" ? o[0] : ""}/${t}`, g = /(?:(?:https?):)?(?:\/\/)?(?:www\.|player\.)?vimeo\.com\/(?:channels\/(?:\w+\/)?|groups\/(?:[^/]*)\/videos\/|video\/|)(\d+)(?:|\/\?)/, U = (t) => { | ||
var o; | ||
return ((o = t.match(U)) == null ? void 0 : o[1]) ?? ""; | ||
}, z = (t) => `https://player.vimeo.com/video/${t}`, I = /^(?:(?:https?):)?(?:\/\/)?(?:www\.)?edpuzzle.com[=/]media\/([-\w]+)/, F = (t) => { | ||
return ((o = t.match(g)) == null ? void 0 : o[1]) ?? ""; | ||
}, z = (t) => `https://player.vimeo.com/video/${t}`, E = /^(?:(?:https?):)?(?:\/\/)?(?:www\.)?edpuzzle.com[=/]media\/([-\w]+)/, I = (t) => { | ||
var o; | ||
return t ? ((o = t.match(I)) == null ? void 0 : o[1]) ?? "" : ""; | ||
}, E = (t) => `https://edpuzzle.com/embed/media/${t}`, v = /^(?:(?:https?):)?(?:\/\/)?(?:www|fast|support\.)?(?:wistia.com|wi.st)[=/](?:medias|embed)\/([-\w]+)/, s = (t) => { | ||
if (t) { | ||
if ((t == null ? void 0 : t.length) > 1e3) | ||
throw new Error("URL too long"); | ||
return ((o = t.match(E)) == null ? void 0 : o[1]) ?? ""; | ||
} | ||
return ""; | ||
}, F = (t) => `https://edpuzzle.com/embed/media/${t}`, T = /^(?:(?:https?):)?(?:\/\/)?(?:www|fast|support\.)?(?:wistia.com|wi.st)[=/](?:medias|embed)\/([-\w]+)/, s = (t) => { | ||
var o; | ||
return t ? ((o = t.match(v)) == null ? void 0 : o[1]) ?? "" : ""; | ||
}, T = (t) => `https://fast.wistia.net/embed/iframe/${t}`, $ = /^(?:(?:https?):)?(?:\/\/)?(?:www\.)?loom.com[=/]share\/([-\w]+)/, c = (t) => { | ||
if (t) { | ||
if ((t == null ? void 0 : t.length) > 1e3) | ||
throw new Error("URL too long"); | ||
return ((o = t.match(T)) == null ? void 0 : o[1]) ?? ""; | ||
} | ||
return ""; | ||
}, v = (t) => `https://fast.wistia.net/embed/iframe/${t}`, R = /^(?:(?:https?):)?(?:\/\/)?(?:www\.)?loom.com[=/]share\/([-\w]+)/, c = (t) => { | ||
var o; | ||
return t ? ((o = t.match($)) == null ? void 0 : o[1]) ?? "" : ""; | ||
}, M = (t) => `https://www.loom.com/embed/${t}`; | ||
if (t) { | ||
if ((t == null ? void 0 : t.length) > 1e3) | ||
throw new Error("URL too long"); | ||
return ((o = t.match(R)) == null ? void 0 : o[1]) ?? ""; | ||
} | ||
return ""; | ||
}, L = (t) => `https://www.loom.com/embed/${t}`; | ||
var e = /* @__PURE__ */ ((t) => (t.YouTube = "YouTube", t.Spotify = "Spotify", t.Vimeo = "Vimeo", t.DailyMotion = "DailyMotion", t.EdPuzzle = "EdPuzzle", t.Loom = "Loom", t.Wistia = "Wistia", t))(e || {}); | ||
const x = (t) => { | ||
const $ = (t) => { | ||
if (t) { | ||
@@ -48,58 +63,57 @@ if (t.match(/dailymotion/)) | ||
} | ||
}, R = { | ||
[e.DailyMotion]: p, | ||
[e.Spotify]: b, | ||
[e.Vimeo]: g, | ||
[e.YouTube]: d, | ||
[e.EdPuzzle]: F, | ||
}, M = { | ||
[e.DailyMotion]: w, | ||
[e.Spotify]: h, | ||
[e.Vimeo]: U, | ||
[e.YouTube]: a, | ||
[e.EdPuzzle]: I, | ||
[e.Loom]: c, | ||
[e.Wistia]: s | ||
}, L = { | ||
[e.DailyMotion]: y, | ||
[e.Spotify]: h, | ||
}, x = { | ||
[e.DailyMotion]: l, | ||
[e.Spotify]: b, | ||
[e.Vimeo]: z, | ||
[e.YouTube]: u, | ||
[e.EdPuzzle]: E, | ||
[e.Loom]: M, | ||
[e.Wistia]: T | ||
[e.YouTube]: p, | ||
[e.EdPuzzle]: F, | ||
[e.Loom]: L, | ||
[e.Wistia]: v | ||
}, V = (t) => { | ||
const o = x(t); | ||
if (!o) | ||
return ""; | ||
const r = R[o], m = L[o], i = r(t); | ||
if (Array.isArray(i)) { | ||
const n = i.shift(); | ||
return n ? m(n, ...i) : ""; | ||
const o = $(t); | ||
if (!o) return ""; | ||
const i = M[o], n = x[o], r = i(t); | ||
if (Array.isArray(r)) { | ||
const m = r.shift(); | ||
return m ? n(m, ...r) : ""; | ||
} | ||
return m(i); | ||
return n(r); | ||
}; | ||
export { | ||
e as Provider, | ||
R as ProviderIdFunctionMap, | ||
L as ProviderIdUrlFunctionMap, | ||
M as ProviderIdFunctionMap, | ||
x as ProviderIdUrlFunctionMap, | ||
V as convertUrlToEmbedUrl, | ||
l as dailyMotionUrlRegex, | ||
I as edPuzzleUrlRegex, | ||
y as getDailyMotionEmbedFromId, | ||
p as getDailyMotionIdFromUrl, | ||
E as getEdPuzzleEmbedUrlFromId, | ||
F as getEdPuzzleIdFromUrl, | ||
M as getLoomEmbedUrlFromId, | ||
y as dailyMotionUrlRegex, | ||
E as edPuzzleUrlRegex, | ||
l as getDailyMotionEmbedFromId, | ||
w as getDailyMotionIdFromUrl, | ||
F as getEdPuzzleEmbedUrlFromId, | ||
I as getEdPuzzleIdFromUrl, | ||
L as getLoomEmbedUrlFromId, | ||
c as getLoomIdFromUrl, | ||
x as getProviderFromUrl, | ||
h as getSpotifyEmbedUrlFromIdAndType, | ||
b as getSpotifyIdAndTypeFromUrl, | ||
$ as getProviderFromUrl, | ||
b as getSpotifyEmbedUrlFromIdAndType, | ||
h as getSpotifyIdAndTypeFromUrl, | ||
z as getVimeoEmbedUrlFromId, | ||
g as getVimeoIdFromUrl, | ||
T as getWistiaEmbedUrlFromId, | ||
U as getVimeoIdFromUrl, | ||
v as getWistiaEmbedUrlFromId, | ||
s as getWistiaIdFromUrl, | ||
u as getYouTubeEmbedUrlFromId, | ||
d as getYouTubeIdFromUrl, | ||
p as getYouTubeEmbedUrlFromId, | ||
a as getYouTubeIdFromUrl, | ||
S as isValidUrl, | ||
$ as loomUrlRegex, | ||
R as loomUrlRegex, | ||
f as spotifySymbolRegex, | ||
w as spotifyUrlRegex, | ||
U as vimeoUrlRegex, | ||
v as wistiaUrlRegex, | ||
a as youTubeUrlRegex | ||
u as spotifyUrlRegex, | ||
g as vimeoUrlRegex, | ||
T as wistiaUrlRegex, | ||
d as youTubeUrlRegex | ||
}; |
@@ -1,9 +0,9 @@ | ||
export * from "./generic"; | ||
export * from "./youtube"; | ||
export * from "./dailymotion"; | ||
export * from "./spotify"; | ||
export * from "./vimeo"; | ||
export * from "./edpuzzle"; | ||
export * from "./wistia"; | ||
export * from "./loom"; | ||
export * from './generic'; | ||
export * from './youtube'; | ||
export * from './dailymotion'; | ||
export * from './spotify'; | ||
export * from './vimeo'; | ||
export * from './edpuzzle'; | ||
export * from './wistia'; | ||
export * from './loom'; | ||
//# sourceMappingURL=index.d.ts.map |
export declare const spotifyUrlRegex: RegExp; | ||
export declare const spotifySymbolRegex: RegExp; | ||
export declare const getSpotifyIdAndTypeFromUrl: (url: string) => [string, string]; | ||
export declare const getSpotifyEmbedUrlFromIdAndType: (id: string, spotifyType: string) => string; | ||
export declare const getSpotifyEmbedUrlFromIdAndType: (id: string, ...args: unknown[]) => string; | ||
//# sourceMappingURL=spotify.d.ts.map |
@@ -1,2 +0,2 @@ | ||
import { Provider } from "./constants"; | ||
import { Provider } from './constants'; | ||
export type ProviderKey = keyof typeof Provider; | ||
@@ -3,0 +3,0 @@ export type ProviderType = (typeof Provider)[Provider]; |
@@ -1,3 +0,3 @@ | ||
import { Provider } from "./constants"; | ||
import type { ValueOfProvider } from "./types"; | ||
import { Provider } from './constants'; | ||
import { ValueOfProvider } from './types'; | ||
export declare const getProviderFromUrl: (url: string) => Provider | undefined; | ||
@@ -8,3 +8,3 @@ export declare const ProviderIdFunctionMap: { | ||
type ProviderIdFn = { | ||
[P in ValueOfProvider]: (id: string, ...args: any[]) => string; | ||
[P in ValueOfProvider]: (id: string, ...args: unknown[]) => string; | ||
}; | ||
@@ -23,4 +23,4 @@ export declare const ProviderIdUrlFunctionMap: ProviderIdFn; | ||
*/ | ||
export declare const matcher: (regex: RegExp | string) => (value: string) => boolean; | ||
export declare const matcher: (regex: RegExp | string) => ((value: string) => boolean); | ||
export {}; | ||
//# sourceMappingURL=utils.d.ts.map |
{ | ||
"name": "@social-embed/lib", | ||
"description": "URL detection and parsing for embed providers (YouTube, other OEmbed compatible providers),", | ||
"version": "0.1.0-next.7", | ||
"version": "0.1.0-next.8", | ||
"main": "dist/lib.umd.cjs", | ||
@@ -9,6 +9,3 @@ "module": "dist/lib.js", | ||
"type": "module", | ||
"files": [ | ||
"dist", | ||
"types" | ||
], | ||
"files": ["dist", "types"], | ||
"exports": { | ||
@@ -21,8 +18,3 @@ ".": { | ||
"license": "MIT", | ||
"keywords": [ | ||
"embed", | ||
"typescript", | ||
"youtube", | ||
"dailymotion" | ||
], | ||
"keywords": ["embed", "typescript", "youtube", "dailymotion"], | ||
"publishConfig": { | ||
@@ -49,14 +41,14 @@ "access": "public" | ||
"test": "vitest", | ||
"lint": "eslint src", | ||
"lint": "biome lint", | ||
"ncu": "ncu", | ||
"update": "ncu", | ||
"prettier": "prettier", | ||
"format": "yarn run prettier . --write" | ||
"biome": "biome", | ||
"format": "yarn run biome format . --write" | ||
}, | ||
"devDependencies": { | ||
"eslint-plugin-redos-detector": "^2.4.0", | ||
"typescript": "^5.3.2", | ||
"vite": "^5.0.2", | ||
"vite-plugin-dts": "^3.6.3", | ||
"vitest": "^0.34.6" | ||
"@biomejs/biome": "1.9.4", | ||
"typescript": "^5.7.2", | ||
"vite": "^6.0.6", | ||
"vite-plugin-dts": "^4.4.0", | ||
"vitest": "^2.1.8" | ||
}, | ||
@@ -63,0 +55,0 @@ "engines": { |
@@ -5,3 +5,3 @@ # [`@social-embed/lib`](https://social-embed.git-pull.com/) · [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/social-embed/social-embed/blob/master/LICENSE) [![npm version](https://img.shields.io/npm/v/@social-embed/lib.svg?style=flat)](https://www.npmjs.com/package/@social-embed/lib) | ||
To use [the lib](https://oembed-components.git-pull.com/api/) you can do: | ||
Install the package: | ||
@@ -14,7 +14,12 @@ ```bash | ||
Then import and use as such: | ||
Then import and use it like so: | ||
```typescript | ||
import { getYouTubeIdFromUrl } from "@social-embed/lib"; | ||
import { convertUrlToEmbedUrl, getYouTubeIdFromUrl } from "@social-embed/lib"; | ||
console.log( | ||
convertUrlToEmbedUrl("https://www.youtube.com/watch?v=Bd8_vO5zrjo"), | ||
); | ||
// output: https://www.youtube.com/embed/Bd8_vO5zrjo | ||
console.log(getYouTubeIdFromUrl("https://www.youtube.com/watch?v=Bd8_vO5zrjo")); | ||
@@ -24,12 +29,13 @@ // output: Bd8_vO5zrjo | ||
If you support ESM / Urls, you can also import via like this: | ||
If your environment supports ESM or direct URLs, you can also import the library like this: | ||
```typescript | ||
// unpkg | ||
import {getYouTubeIdFromUrl} from 'https://www.unpkg.com/@social-embed/lib?module'; | ||
import { getYouTubeIdFromUrl } from "https://www.unpkg.com/@social-embed/lib?module"; | ||
// skypack | ||
import {getYouTubeIdFromUrl} from 'https://cdn.skypack.dev/@social-embed/lib'; | ||
import { getYouTubeIdFromUrl } from "https://cdn.skypack.dev/@social-embed/lib"; | ||
``` | ||
## API reference | ||
## API Reference | ||
@@ -40,4 +46,4 @@ [https://social-embed.git-pull.com/api/](https://social-embed.git-pull.com/api/) | ||
- [CodePen], [codepen console] | ||
- [jsfiddle] | ||
- [CodePen], [CodePen Console] | ||
- [JSFiddle] | ||
@@ -44,0 +50,0 @@ [codepen]: https://codepen.io/attachment/pen/VwPPrNq |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
23539
274
49