npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@hal313/html-amend

v1.0.3

Published

Amends HTML by inserting attributes into elements, or elements into the DOM.

Downloads

8

Readme

html-amend

Amends HTML by inserting attributes into elements, or elements into the DOM.

Build Status NPM version Dependency Status

Information

No HTML parsing! This is good because it is quick and easy... but also limited. Currently, only the first occurrence of an element is supported. It should be fairly trivial to add advanced locators.

Usage

Install

$ npm install html-amend --save-dev

API

  /**
   * Replaces content specified by a regular expression with specified content.
   *
   * @param {String|Function} input the input to replace
   * @param {String|RegExp|Function} regEx the regular expression (or string) to replace within the input
   * @param {String|Function} [content] the content to replace
   * @return {String} a String which has the first occurrence of the regular expression within input replaced with the content
   * @throws {String} when input or regex are not defined
   */
  function replaceWith(input, regex, content);
  /**
   * Inserts content into the input string after the first occurrence of the element has been opened.
   *
   * @param {String|Function} input the input to replace
   * @param {String|Function} element the element to insert after
   * @param {String|Function} [content] the content to insert within the input string
   * @return {String} a String which has the content added after the first occurrence of the element open tag within the input string
   * @throws {String} when input or element are not defined
   */
  function afterElementOpen(input, element, content);
  /**
   * Inserts content into the input string before the first occurrence of the element close tag.
   *
   * @param {String|Function} input the input to replace
   * @param {String|Function} element the element to insert before close
   * @param {String|Function} content the content to replace within the input string
   * @return {String} a String which has the content added before the first occurrence of the element close tag within the input string
   * @throws {String} when input or element are not defined
   */
  function beforeElementClose(input, element, content)
  /**
   * Inserts an HTML comment into the input string after the first occurrence of the element close tag.
   *
   * @param {String|Function} input the input to replace
   * @param {String|Function} element the element to add the comment after
   * @param {String|Function} [content] the comment to add.
   * @return {String} a String which has the comment added after the first occurrence of the element close tag within the input string
   * @throws {String} when input or element are not defined
   */
  function insertComment(input, element, comment)
  /**
   * Inserts an attribute into the input string within the first occurrence of the element open tag.
   *
   * @param {String|Function} input the input string
   * @param {String|Function} element the element tag to modify
   * @param {String|Function} attributeName the attribute name to add
   * @param {String|Function} [attributeValue] the attribute value to add
   * @return {String} a String which has the attribute added into the first occurrence of the element open tag
   * @throws {String} when input, element or attributeName are not defined
   */
  function insertAttribute(input, element, attributeName, attributeValue);

Building

npm install
npm run build

Running Tests

Tests expect to be run against an distribution, so be sure to build before running tests.

npm run test

To re-run tests during development:

npm run test:watch

Deploying

This is a basic script which can be used to build and deploy (to NPM) the project.

export VERSION=<NEXT VERSION>
git checkout -b release/$VERSION
npm version --no-git-tag-version patch
npm run build
npm run test
git add package*
git commit -m 'Version bump'
npx auto-changelog -p
git add CHANGELOG.md
git commit -m 'Updated changelog'
git checkout master
git merge --no-ff release/$VERSION
git tag -a -m 'Tagged for release' $VERSION
git branch -d release/$VERSION
git checkout develop
git merge --no-ff master
git push --all && git push --tags

LICENSE

MIT License