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

text-marshal

v0.0.2

Published

Text Marshal is used to format, assemble and arrange the text as per the assigned pattern.

Downloads

1,158

Readme

Text Marshal

npm version

Text Marshal is used to format text according to the assigned patterns.

Features

The main purpose of the package is to pattern format the input text while typing (in real-time). The key features for this package is listed below

  • Text format itself as per the assigned pattern e.g. date format, card format, etc
  • Define Infinite text pattern
  • Disallow Character

Install

We can install the package by executing the below command in the terminal:

> npm i text-marshal

Package usage

To use this package, we can import it as below

import { textMarshal } from "text-marshal";

To get started, we can write the textMarshal function as below.

console.log(
  textMarshal({
    input: "4242424242424242",
    template: "xxxx xxxx xxxx xxxx",
  })
);

The above code output in the browser as below:

// output:
{
 template: "xxxx xxxx xxxx xxxx",
 plaintext: "4242424242424242",
 marshaltext: "4242 4242 4242 4242"
}

The textMarshal function accepts JSON objects as input. In the JSON object, we have the option to pass the following parameters:

  • input: It is the user's input text that we need to format.
  • template: It is the defined pattern that the input text needs to match
  • disallowCharacters: It is an array of characters that should be disallowed from the output text
  • isRepeat.value: Bool that triggers the infinite pattern
  • isRepeat.removeStart: Remove the start character e.g. space, dot, etc
  • isRepeat.removeEnd: Remove the end character e.g. space, dot, etc

The output of the textMarshal function is the JSON object. The JSON object output the parameters as below

  • template: It defines the text pattern of the output marshaltext.
  • plaintext: It is the text without formating.
  • marshaltext: The format text output of the input text.

With the textMarshal function, we can also define the infinite patterns. To understand it, we can write the below code.

console.log(
  textMarshal({
    input: "1.s23456789",
    template: "xx.",
    disallowCharacters: [".", "s"],
    isRepeat: {
      value: true,
      removeStart: true,
      removeEnd: true,
    },
  })
);

The output of the above code is shown below:

// output:
{
 template: "xx.xx.xx.xx.x",
 plaintext: "123456789",
 marshaltext: "12.34.56.78.9"
}

You can use this plugin to auto-format the input text while typing. For that, we can define the Card Number input in HTML as below.

<div class="input">
  <label for="cardnumber">Enter Card Number</label>

  <input
    class="headline headline__text"
    type="text"
    id="cardnumber"
    name="cardnumber"
    data-pattern="xxxx xxxx xxxx xxxx"
  />
</div>

By using the textMarshal function, we can automatically format the input text to match the assigned pattern.

const cardnumber = document.getElementById("cardnumber");

cardnumber.oninput = function (e) {
  let data = textMarshal({
    input: e.target.value,
    template: cardnumber.getAttribute("data-pattern"),
    disallowCharacters: [/[a-z]/],
  });

  cardnumber.value = data.marshaltext;
};

Resources

License

Text Marshal is licensed under the MIT license