Skip to main content

data ()

Creates a data URL for the provided data of the specified type.

Parameters

$data
The data which is to be delivered by the URL.
Type
String
$media-type
The media type indicates the MIME type to be delivered by the URL.
Type
String
Default
'text/plain'
$encode
Whether or not the given data should be percent-encoded.
Type
Boolean
Default
true

Return Value

String
A new string representing a data URL.

Example

@use '@sass-fairy/url';

// 1. Simple text
@debug url.data('Hello, 100% of World!');
// url('data:text/plain,Hello, 100%25 of World!'')

// 2. SVG data
$svg: '<svg viewBox="0 0 100 100"><circle fill="#f00" cx="50" cy="50" r="50"/></svg>';

@debug url.data($svg, 'image/svg+xml');
// url('data:image/svg+xml,<svg viewBox="0 0 100 100"><circle fill="%23f00" cx="50" cy="50" r="50"/></svg>')