youtube-url-parser
![Build Status](https://travis-ci.org/iktakahiro/youtube-url-parser.svg?branch=master)
Install
npm install @iktakahiro/youtube-url-parser
How to use
import { YouTubeURLParser } from "@iktakahiro/youtube-url-parser"
const parser = new YouTubeURLParser("https://youtu.be/7lmCu8wz8ro?t=2m10s")
console.log(parser.isValid())
console.log(parser.getId())
console.log(parser.getCanonicalURL())
console.log(parser.getShortURL())
console.log(parser.getThumbnailURL())
console.log(parser.getStartAtSecond())
getIframe()
:
console.log(parser.getIframe())
getIframe()
method returns HTML strings containing an iframe element for embedding.
<div class="embed-responsive embed-responsive-16by9">
<iframe
class="embed-responsive-item" type="text/html"
src="https://www.youtube.com/embed/7lmCu8wz8ro?rel=0&start=4830"
frameborder="0" allowfullscreen></iframe>
</div>
with options:
const options = {
allowFullScreen: false,
frameBorder: 1,
noCookie: true,
}
console.log(parser.getIframe(options))
When the params is set, the following HTML strings are returned.
<div class="embed-responsive embed-responsive-16by9">
<iframe
class="embed-responsive-item" type="text/html"
src="https://www.youtube-nocookie.com/embed/7lmCu8wz8ro?rel=0&start=4830"
frameborder="1"></iframe>
</div>
Test
npm test