Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including get-src with all npm packages installed. Try it out:

var getSrc = require("get-src")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

get-src v1.0.1

Get the 'src' value from any string containing a src="" (embed, iframe, html, etc).

get-src Build Status Coverage Status

Get the 'src' value from any string containing a src="" (embed, iframe, html, etc).

Install

$ npm install --save get-src

Usage

const getSrc = require('get-src');

getSrc('<image src="image.png" />');
//=> 'image.png'

getSrc('<iframe width="400" height="300" src="video.mp4"></iframe>');
//=> 'video.mp4'

API

getSrc(input)

input

Type: string

The string containing the src="" from which you want to extract the src value.

Double Quotes Only

Currently, there is only support for double quotes, meaning the value you want to extract must rest inside two double quotes:

Valid

src="this is valid"

Invalid

src='this will return undefined'

Pull requests are welcome if you want to add support for double AND single quotes.

License

MIT © Michael Wuergler

Metadata

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free