npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

youtube-link-to-id

v1.0.2

Published

Get a YouTube video ID from a strings containing YouTube link(s).

Downloads

11

Readme

youtube-link-to-id

Get a YouTube video ID from a strings containing YouTube link(s).

About

This module takes strings that may contain YouTube links and pulls out the video ids. Optionally it can also create embed tags from the video ids. It is small and self contained and has no dependencies. The newest language features in the module are ES5 so it should be ok to use in a browser.

This should match all of the various formats of links that YouTube supports (and there are several). If I missed one, open up an issue with an example!

Install

npm install --save youtube-link-to-id

Usage and Methods

The examples below show the various extraction and transformation methods. All of the methods perform greedy regex operations and return arrays, so if you only plan on passing one link in per call, just grab the first result of the array. If there are no matches you should get an empty array for all methods.

var idGetter = require('youtube-link-to-id');

// Simply pull the video ID from a set of links
var ids = idGetter.linkStringToIds('some extra text https://www.youtube.com/watch?v=D9TpswDIBS8 test');
// ids: ['D9TpswDIBS8']

// Create embed tags from a set of links
var embeds = idGetter.linksToEmbedTags('some extra text https://www.youtube.com/watch?v=D9TpswDIBS8 test');
// embeds: ['<iframe width="385" height="300" src="http://www.youtube.com/embed/D9TpswDIBS8?feature=player_embedded" frameborder="0"></iframe>']

// Extract a link from text:
var links = idGetter.extractLink('some extra text https://www.youtube.com/watch?v=D9TpswDIBS8 test');
// links: ['https://www.youtube.com/watch?v=D9TpswDIBS8']

// Extract a link from text for given ID
var links = idGetter.extractLinkForId('some extra text https://www.youtube.com/watch?v=D9TpswDIBS8 test', 'C8TpswDIBS8');
// links: [] <-- EMPTY Array! The ID did not match and the link was filtered!

Tests

This module has a test suite. Mocha installs as a dev dependency so you can run it as an npm script:

npm run test

Changelog:

7/2/2016 - v1.0.2