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 🙏

© 2025 – Pkg Stats / Ryan Hefner

whatsapp-messager

v1.0.1

Published

Messaging template for building whatsapp messages

Readme

WhatsApp Messager (Message Builder)

Easily construct rich WhatsApp messages with bold, italic, strikethrough, monospace, and more! This library extends string-builder npm package with custom formatting options to simplify building professional, formatted WhatsApp messages programmatically.


Installation

Install the package using npm:

npm install whatsapp-messager
yarn add whatsapp-messager

Features

  • Rich Text Formatting: Bold, italic, strikethrough, and monospace text.
  • Lists: Create ordered and unordered lists effortlessly.
  • Template Placeholders: Easily replace placeholders with dynamic values.
  • Quoting: Add blockquotes seamlessly.
  • Chaining: Use method chaining for clean, readable code.

Getting Started

Here’s how you can get started with the WhatsApp Messager:

Example Usage

import StringBuilder from 'whatsapp-messager';

const builder = new StringBuilder();

const message = builder
  .bold("Welcome to WhatsApp!")
  .italic("We hope you enjoy your stay.")
  .quote("Here are some tips to get started:")
  .unorderedList([
    "Send messages to your friends.",
    "Create group chats for family or work.",
    "Use formatting for emphasis.",
  ])
  .strikethrough("This is an outdated feature.")
  .toString();

console.log(message);

Output

*Welcome to WhatsApp!*
_We hope you enjoy your stay._
> Here are some tips to get started:
* Send messages to your friends.
* Create group chats for family or work.
* Use formatting for emphasis.
~This is an outdated feature.~

API Reference

1. append(text: string): StringBuilder

Append/add text in the string.

Example:

builder.append("This is some text.");

2. appendLine(text: string): StringBuilder

Appends text in a new line.

Example:

builder.appendLine("This is in a new line.");

3. bold(text: string, isNewLine?: boolean): StringBuilder

Formats the given text as bold.

Example:

builder.bold("This is bold text.");

4. italic(text: string, isNewLine?: boolean): StringBuilder

Formats the given text as italic.

Example:

builder.italic("This is italic text.");

5. strikethrough(text: string, isNewLine?: boolean): StringBuilder

Formats the given text with strikethrough.

Example:

builder.strikethrough("This is strikethrough text.");

6. monospace(text: string, isNewLine?: boolean): StringBuilder

Formats the given text as monospace.

Example:

builder.monospace("This is monospace text.");

7. quote(text: string): StringBuilder

Adds a blockquote.

Example:

builder.quote("This is a quote.");

8. list(texts: string[], isOrdered?: boolean): StringBuilder

Creates a list, either ordered or unordered.

Example:

builder.list(["First item", "Second item"], true); // Ordered
builder.list(["First item", "Second item"]); // Unordered
builder.list(["First item", "Second item"], false); // Unordered

9. toString(data?: object): string

Returns the constructed message as a string. Optionally replaces placeholders with values from an object.

Example:

const template = "Hello, {name}! Your order {orderNumber} is ready.";
const message = builder.toString({ name: "Jane", orderNumber: "12345" });
console.log(message);

Output:

Hello, Jane! Your order 12345 is ready.

10. clear(): StringBuilder

Clears string.

Example:

builder.clear();

Advanced Usage

Dynamic Templates with Escaping

Use placeholders and escape {} if needed:

const message = builder
  .bold("Order Details:")
  .append("Your order {reference} has been confirmed.")
  .toString({ reference: 12345 });

console.log(message);

Output:

*Order Details:*
Your order 12345 has been confirmed.

const message = builder
  .bold("Order Details:")
  .append("Your order \{12345\} has been confirmed.")
  .toString();

console.log(message);

Output:

*Order Details:*
Your order {12345} has been confirmed.

Why Use This Library?

  1. Efficiency: Build complex messages programmatically.
  2. Clean Code: Avoid messy string concatenation.
  3. Dynamic Messages: Replace placeholders with dynamic values easily.

Contribution

Feel free to submit issues or pull requests to help improve this library. Contributions are always welcome!


License

MIT