1.2.0 • Published 6 years ago

css-absolutely v1.2.0

Weekly downloads
3
License
MIT
Repository
github
Last release
6 years ago

css-absolutely

Pass in CSS from stylesheets or inline css tags and receive back CSS with all urls resolved to an absolute url.

JavaScript Style Guide

Credits for the regex to parse css urls go to jrit's web-resource-inliner.

Rebuilding API documentation

npm run docs

This will append to README.md by default.

Table of Contents

absoluteCss

Pass in CSS from stylesheets or inline css tags and receive back CSS with all urls resolved to an absolute url.

Parameters

  • css string the css string to resolve to an absolute url
  • resolveTo string the absolute url to resolve relative urls (urls without a protocol) to

Examples

const absCss = require('css-absolutely', 'http://www.example.com/')
const input = `<div style="background-image: url('assets/icon.png');"></div>`
const expected = `<div style="background-image: url('http://www.example.com/assets/icon.png');"></div>`
const css = absCss(input, baseUrl)
console.log(css === expected) // true

Returns string an example return type