
Security News
OWASP 2025 Top 10 Adds Software Supply Chain Failures, Ranked Top Community Concern
OWASP’s 2025 Top 10 introduces Software Supply Chain Failures as a new category, reflecting rising concern over dependency and build system risks.
link-to-iframe
Advanced tools
A TypeScript package that transforms URLs from various services (YouTube, Loom, Asciinema, etc.) into embeddable iframe HTML.
😘 Maintainer: @baptistejamin
| Crisp |
👋 You use this library and you want to be listed there? Contact us.
This library transforms URLs from various services into embeddable iframe HTML code:
npm install link-to-iframe
import { linkToIframe } from "link-to-iframe";
// YouTube example
const youtubeHtml = linkToIframe("https://www.youtube.com/watch?v=dQw4w9WgXcQ");
console.log(youtubeHtml);
// <iframe width="560" height="315" src="https://www.youtube.com/embed/dQw4w9WgXcQ" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
// Loom example
const loomHtml = linkToIframe("https://www.loom.com/share/abcdef123456");
console.log(loomHtml);
// <iframe width="560" height="315" src="https://www.loom.com/embed/abcdef123456" frameborder="0" allowfullscreen></iframe>
// Custom attributes for all iframes
const customHtml = linkToIframe("https://www.youtube.com/watch?v=dQw4w9WgXcQ", {
defaultAttributes: {
width: 640,
height: 360,
style: "border: none;"
}
});
console.log(customHtml);
// <iframe width="640" height="360" src="https://www.youtube.com/embed/dQw4w9WgXcQ" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen style="border: none;"></iframe>
// Get attributes object instead of HTML
const attributesObj = linkToIframe("https://www.youtube.com/watch?v=dQw4w9WgXcQ", {
returnObject: true
});
console.log(attributesObj);
// {
// src: "https://www.youtube.com/embed/dQw4w9WgXcQ",
// width: "560",
// height: "315",
// allow: "accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture",
// allowfullscreen: true
// }
// Adding custom URL transformers
import { Transformer } from "link-to-iframe";
const vimeoTransformer: Transformer = {
pattern: /(?:https?:\/\/)?(?:www\.)?vimeo\.com\/(\d+)/i,
transform: (url, matches) => {
const videoId = matches[1];
return {
src: `https://player.vimeo.com/video/${videoId}`,
allowfullscreen: true,
frameborder: 0,
width: 560,
height: 315
};
}
};
const vimeoHtml = linkToIframe("https://vimeo.com/123456789", {
additionalTransformers: [vimeoTransformer]
});
console.log(vimeoHtml);
// <iframe width="560" height="315" src="https://player.vimeo.com/video/123456789" allowfullscreen frameborder="0"></iframe>
// Get all available transformers
import { getAllTransformers } from "link-to-iframe";
const transformers = getAllTransformers();
console.log(transformers);
// [
// { key: "youtube", name: "YouTube", priority: 10 },
// { key: "loom", name: "Loom", priority: 0 },
// ...
// ]
// Include custom transformers in the list
const customTransformer = {
key: "custom-service",
name: "Custom Service",
priority: 100, // Higher priority will appear first in the sorted list
pattern: /custom-service\.com\/video\/(\d+)/i,
transform: (url, matches) => ({
src: `https://custom-service.com/embed/${matches[1]}`,
width: 560,
height: 315,
})
};
const allTransformers = getAllTransformers({
includeAdditional: [customTransformer]
});
// First item will be the custom transformer due to higher priority
Currently, the following services are supported out of the box:
The library is designed to be easy to extend and non-opinionated. Contributions for new service integrations are welcome and will be merged easily as long as they are simple enough. Contributions made with AI assistance (like GPT) are also accepted. See the custom transformer example in the Usage section for a starting point.
Converts a URL to an iframe HTML string or attributes object.
Parameters:
url (string): The URL to convert to an iframeoptions (object, optional): Configuration options
defaultAttributes (object, optional): Default attributes to apply to all iframesadditionalTransformers (array, optional): Additional transformers to usereturnObject (boolean, optional): Return attributes object instead of HTML stringReturns:
Get all available transformers with their key, name, and priority, sorted by priority (highest first).
Parameters:
options (object, optional): Configuration options
includeAdditional (array, optional): Additional transformers to include in the listReturns:
key (string): Unique identifier for the transformername (string): Display name of the transformerpriority (number): Priority value (higher priorities are listed first)You can customize the output in two ways:
By default, all iframes are rendered with a width of 560 and height of 315 pixels (standard YouTube dimensions). You can customize these values using the defaultAttributes option.
By default, the linkToIframe function returns an HTML string. You can set the returnObject option to true to get the attributes object instead:
const attributes = linkToIframe("https://www.youtube.com/watch?v=dQw4w9WgXcQ", {
returnObject: true
});
// Now you can use the attributes with your own templating system
// For example, with React:
// <iframe {...attributes}></iframe>
This is useful if you want to:
link-to-iframe is released under the MIT License. See the bundled LICENSE file for details.
FAQs
Transform links to embeddable iframes
We found that link-to-iframe demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
OWASP’s 2025 Top 10 introduces Software Supply Chain Failures as a new category, reflecting rising concern over dependency and build system risks.

Research
/Security News
Socket researchers discovered nine malicious NuGet packages that use time-delayed payloads to crash applications and corrupt industrial control systems.

Security News
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.