Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
posthtml-url-parameters
Advanced tools
Readme
This is a PostHTML plugin that allows you to add query string parameters to URLs.
npm i posthtml posthtml-url-parameters
import posthtml from 'posthtml'
import urlParams from 'posthtml-url-parameters'
posthtml([
urlParams({
parameters: { foo: 'bar', baz: 'qux' }
})
])
.process('<a href="https://example.com">Test</div>')
.then(result => console.log(result.html)))
// <a href="https://example.com?baz=qux&foo=bar">Test</div>
parameters
Type: Object
Default: undefined
Object containing parameter name (key) and its value.
Example:
import posthtml from 'posthtml'
import urlParams from 'posthtml-url-parameters'
posthtml([
urlParams({
parameters: {
utm_source: 'Campaign',
'1stDraft': true
}
})
])
.process('<a href="https://example.com">Test</a>')
.then(result => console.log(result.html))
tags
Type: Array
Default: ['a']
Array of tag names to process.
By default, only URLs inside known attributes of tags in this array will be processed.
Example:
import posthtml from 'posthtml'
import urlParams from 'posthtml-url-parameters'
posthtml([
urlParams({
tags: ['a', 'img']
})
])
.process(`
<a href="https://example.com">Test</a>
<img src="https://example.com/image.jpg">
`)
.then(result => console.log(result.html))
You may use some CSS selectors when specifying tags:
posthtml([
urlParams({
tags: ['a.button', 'a[href*="example.com"]' 'link'],
})
])
.process(/*...*/)
All posthtml-match-helper
selectors are supported.
Type: Array
Default: ['src', 'href', 'poster', 'srcset', 'background']
Array of attributes to process for the given tags.
You may override this with your own list of attributes - the plugin will only process URLs in these attributes.
posthtml([
urlParams({
parameters: {foo: 'bar'},
attributes: ['data-href']
})
])
.process('<a href="foo.html" data-href="https://example.com">Test</a>')
.then(result => console.log(result.html)))
// <a href="foo.html" data-href="https://example.com?foo=bar">Test</a>
strict
Type: Boolean
Default: false
By default, the plugin will append query parameters only to valid URLs.
You may disable strict
mode to append parameters to any string:
import posthtml from 'posthtml'
import urlParams from 'posthtml-url-parameters'
posthtml([
urlParams({
parameters: { foo: 'bar' },
strict: false,
})
])
.process('<a href="https://example.com/campaigns/{{ id }}">Details</a>')
.then(result => console.log(result.html)))
// <a href="https://example.com/campaigns/{{ id }}?foo=bar">Details</a>
qs
Type: Object
Default: undefined
Options to pass to query-string
- see available options here.
For example, you may disable encoding:
import posthtml from 'posthtml'
import urlParams from 'posthtml-url-parameters'
posthtml([
urlParams({
parameters: { foo: '@Bar@' },
qs: {
encode: false
}
})
])
.process('<a href="https://example.com">Test</a>')
.then(result => console.log(result.html)))
// <a href="https://example.com?foo=@Bar@">Test</a>
FAQs
PostHTML plugin for adding parameters to URLs.
The npm package posthtml-url-parameters receives a total of 8,093 weekly downloads. As such, posthtml-url-parameters popularity was classified as popular.
We found that posthtml-url-parameters demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.