Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

posthtml-rename-id

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

posthtml-rename-id

PostHTML plugin to rename id attributes and it's references

  • 1.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
250K
decreased by-1.67%
Maintainers
1
Weekly downloads
 
Created
Source

PostHTML rename plugin

Plugin to rename id attributes and it's references. Inspired by grunt-svgstore.

Handle following cases:

  • href="#id" and xlink:href="#id"
  • style attribute values like style="fill: url(#id)"
  • <style> tag values like .selector {fill: url(#id)"}
  • any other attribute value like attr="url(#id)"

Install

npm install posthtml-rename-id --save

Usage

const posthtml = require('posthtml');
const rename = require('posthtml-rename-id');

posthtml()
  .use(rename('prefix_[id]'))
  .process('<div id="qwe"></div> <a href="#qwe"></a>')
  .then((result) => {
    console.log(result);
  });

// <div id="prefix_qwe"></div> <a href="#prefix_qwe"></a>

Configuration

plugin(pattern: string|Function) (optional, [id] by default)

Renaming pattern. [id] placeholder can be used as current id of an element. If pattern provided as a function it will be called with current id as first argument. Function should return the new id as string ([id] can be used as well).

Uppercase all ids:

posthtml([
  renameId(id => id.toUpperCase())
]);

Rename all ids to elem_{counter}:

let c = 0;
posthtml([
  renameId((id) => { c++; return 'elem_' + c; })
]);

FAQs

Package last updated on 27 Apr 2017

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc