Gathering detailed insights and metrics for posthtml-base-url
Gathering detailed insights and metrics for posthtml-base-url
Gathering detailed insights and metrics for posthtml-base-url
Gathering detailed insights and metrics for posthtml-base-url
npm install posthtml-base-url
Typescript
Module System
Min. Node Version
Node Version
NPM Version
96.2
Supply Chain
99
Quality
81.3
Maintenance
100
Vulnerability
100
License
JavaScript (61.7%)
HTML (36.84%)
TypeScript (1.47%)
Total Downloads
1,229,273
Last Day
2,867
Last Week
34,586
Last Month
138,020
Last Year
600,594
MIT License
6 Stars
345 Commits
3 Watchers
10 Branches
10 Contributors
Updated on May 06, 2025
Minified
Minified + Gzipped
Latest Version
3.1.7
Package Id
posthtml-base-url@3.1.7
Unpacked Size
21.65 kB
Size
4.93 kB
File Count
8
NPM Version
10.9.2
Node Version
22.14.0
Published on
Mar 04, 2025
Cumulative downloads
Total Downloads
Last Day
29.4%
2,867
Compared to previous day
Last Week
18%
34,586
Compared to previous week
Last Month
102.2%
138,020
Compared to previous month
Last Year
67%
600,594
Compared to previous year
1
4
This PostHTML plugin can prepend a string to various HTML attribute values and CSS property values.
Input:
1<img src="test.jpg">
Output:
1<img src="https://example.com/test.jpg">
Works on the following attributes:
src=""
href=""
srcset=""
poster=""
background=""
... and the following CSS properties:
background: url()
background-image: url()
@font-face { src: url() }
Both <style>
tags and style=""
attributes are supported.
CSS property values with multiple url()
sources are supported as well.
npm i posthtml posthtml-base-url
1import posthtml from 'posthtml' 2import baseUrl from 'posthtml-base-url' 3 4posthtml([ 5 baseUrl({ 6 url: 'https://example.com', 7 tags: ['img'] 8 }) 9]) 10 .process('<img src="test.jpg">') 11 .then(result => console.log(result.html))
Result:
1<img src="https://example.com/test.jpg">
If the target attribute value is an URL, the plugin will not modify it.
If the prefix string to prepend to the target attribute value is an URL, the two strings will be concatenated.
If both the prefix and the attribute value are relative paths, the plugin will intelligently join the paths instead of simply concatenating them.
You can configure what to prepend to which attribute values.
url
Type: string
Default: ''
The string to prepend to the attribute value.
allTags
Type: boolean
Default: false
The plugin is opt-in, meaning that by default it doesn't affect any tag.
When you set allTags
to true
, the plugin will prepend your url
to all attribute values in all the tags that it supports.
styleTag
Type: boolean
Default: false
When set to true
, the plugin will prepend your url
to all url()
sources in <style>
tags.
inlineCss
Type: boolean
Default: false
When set to true
, the plugin will prepend your url
to all url()
sources in style=""
attributes.
tags
Type: array|object
Default: defaultTags (object)
Define a list of tags and their attributes to handle.
When using the tags
option, the plugin will only handle those tags.
tags
To replace all known attributes for a list of tags, use the array format:
1posthtml([ 2 baseUrl({ 3 url: 'https://example.com', 4 tags: ['img', 'script'], 5 }) 6]) 7 .process( 8 `<a href="foo/bar.html"> 9 <img src="img.jpg" srcset="img-HD.jpg 2x,img-xs.jpg 100w"> 10 </a> 11 12 <script src="javascript.js"></script>` 13 ) 14 .then(result => console.log(result.html))
Result:
1<a href="foo/bar.html"> 2 <img src="https://example.com/img.jpg" srcset="https://example.com/img-HD.jpg 2x, https://example.com/img-xs.jpg 100w"> 3</a> 4 5<script src="https://example.com/javascript.js"></script>
tags
You may use an object for granular control over how specific attributes should be handled:
1posthtml([ 2 baseUrl({ 3 url: 'https://foo.com/', 4 tags: { 5 img: { 6 src: true, 7 srcset: 'https://bar.com/', 8 }, 9 }, 10 }) 11]) 12 .process( 13 `<a href="foo/bar.html"> 14 <img src="img.jpg" srcset="img-HD.jpg 2x, img-xs.jpg 100w"> 15 </a>` 16 ) 17 .then(result => console.log(result.html))
Result:
1<a href="foo/bar.html"> 2 <img src="https://foo.com/img.jpg" srcset="https://bar.com/img-HD.jpg 2x, https://bar.com/img-xs.jpg 100w"> 3</a>
You may set the value of an attribute to true
and the plugin will use the url
option value - we did that above for the src
attribute.
attributes
Type: object
Default: {}
Key-value pairs of attributes and what to prepend to them.
Example:
1posthtml([ 2 baseUrl({ 3 attributes: { 4 'data-url': 'https://example.com/', 5 } 6 }) 7]) 8 .process('<div data-url="foo/bar.html"></div>') 9 .then(result => console.log(result.html))
Result:
1<div data-url="https://example.com/foo/bar.html"></div>
No vulnerabilities found.
No security vulnerabilities found.