Namespace: CSS:cssUrlValueToUrl

CSS:cssUrlValueToUrl

Source:

Methods

cssUrlValueToUrl(urlValue, baseUrlopt, nullable, baseUrlSubstitutionopt, nullable) → {String|Array.<String>|null}

Converts a CSS-URL-value ("url('/foo/bar/baz.jpg')") to a plain URL usable in requests or src-attributes.

Parameters:
Name Type Attributes Default Description
urlValue String

the URL-value from CSS

baseUrl String <optional>
<nullable>
null

if you want to transform the URL by substituting the start of the path or URL with something fitting for your context, define what to replace here

baseUrlSubstitution String <optional>
<nullable>
null

if you want to transform the URL by substituting the start of the path or URL with something fitting for your context, define what to replace the baseUrl with here

Source:
Returns:
the extracted URL (or list of URLs if value contained several) with substitutions (if defined) or null if no URL-values were found
Type
String | Array.<String> | null
Example
cssUrlValueToUrl('url("https://foobar.com/test.jpg")', 'https://foobar.com', '..');
=> '../test.jpg'
cssUrlValueToUrl(`url(/foo/bar),
url('https://google.de') url("test.jpg"),url(omg.svg)
url(http://lol.com)`)
=> ['/foo/bar', 'https://google.com', 'test.jpg', 'omg.svg', 'http://lol.com']