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 🙏

© 2026 – Pkg Stats / Ryan Hefner

lw-watermark

v1.0.2

Published

A lightweight, dependency-free JavaScript ES6 class for adding persistent text watermarks to any webpage.

Readme

EN | ZH

Lightweight Watermark

A lightweight, dependency-free JavaScript ES6 class for adding persistent text watermarks to any webpage.

The watermark is drawn using <canvas> and applied as a repeating background, with automatic restoration if removed from the DOM.

✨ Features

  • No dependencies — pure vanilla JavaScript.
  • Persistent protection — uses MutationObserver to detect and restore watermark if removed.
  • Highly customizable — text, font, size, weight, color, rotation, z-index.
  • Performance-friendly — generates a single small repeating image instead of heavy DOM elements.
  • Error-safe — built-in validation with clear error codes.
  • Works everywhere — compatible with modern browsers.

📦 Installation

use npm

npm install lw-watermark

🚀Usage

Basic Example

import Watermark from 'lw-watermark';

const wm = new Watermark({
  content: 'lightweight watermark',
  font: 'Arial',
  fontSize: 24,
  fontWeight: 'bold',
  rotate: 30,
  color: 'rgba(255, 0, 0, 0.15)',
  zIndex: 999999999
});

wm.create()
  .then(() => console.log('Watermark added!'))
  .catch(err => console.error('Watermark error:', err));

Options

| Option | Type | Default | Description | | ------------ | ------------------ | ---------------------- | ------------------------------------------------------ | | content | string | "lw-watermark" | Text to display in the watermark | | font | string | "serif" | CSS font family | | fontSize | number | string | 30 | Font size in pixels | | fontWeight | string | number | "normal" | CSS font-weight (e.g., normal, bold, 300, 700) | | rotate | number | 30 | Rotation angle in degrees | | color | string (rgba) | "rgba(0, 0, 0, 0.6)" | Watermark color | | zIndex | number | 999999999 | CSS z-index | | maxLength | number | 30 | Max allowed length of content text |

Methods

  • create(): Promise<void>

    Creates and applies the watermark. Returns a promise that resolves when the watermark is successfully added.

  • destroy(): void

    Removes the watermark and stops the DOM observer.

Error Handling

The class throws custom ErrorMessage instances with both code and message.

| Code | Message | | :----: | :----------------------------------------------------------- | | 1011 | The maximum length of content is exceeded | | 1021 | The content should be of string type | | 1022 | The font-size should be of string or number type | | 1023 | The font-weight should be of string or number type | | 1031 | The font-size is invalid | | 1032 | The font-weight is invalid | | 1033 | The color is invalid, you should use rgba(R, G, B, alpha) format |

Advantages over other solutions

  • DOM tamper-proof: Automatically restores itself if someone tries to delete it via dev tools.

  • Lightweight: No large image files — generated entirely from <canvas> in memory.

  • Customizable: Full control over text, style, rotation, and positioning.

  • Cross-browser: Works in Chrome, Firefox, Edge, and most modern browsers without polyfills.

  • Non-intrusive: Uses pointer-events: none so it doesn’t block clicks or UI interactions.

License

MIT

Tip: This watermark is a visual deterrent. It won't stop determined users from copying text or screenshots, but it's great for discouraging casual sharing and maintaining brand presence.