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

input-transform

v1.0.2

Published

Transform and format input values

Downloads

19

Readme

Input Transform

InputTransform is a lightweight JavaScript library that provides various input transformations, such as formatting text, validating file uploads, and converting images to Base64 or WebP format.

Installation

NPM

Install the library using NPM:

npm i input-transform

Import

// CommonJS
const InputTransform = require('input-transform');

// ES Modules
import InputTransform from 'input-transform';

CDN

<script src='https://cdn.jsdelivr.net/gh/lullaby6/input-transform/input-transform.min.umd.js'></script>

You can aslo import the Module format:

<script type="module">
    import InputFormat from "https://cdn.jsdelivr.net/gh/lullaby6/input-transform/input-transform.min.mjs.js";
</script>

Download

Download and include the downloaded file in your project:

<script src="/path/to/input-transform.min.umd.js"></script>

Usage

// Simple example
InputTransform.init('input#username', {
    capitalize: true,
    trim: true,
    maxLength: 20,
})

// Change option
document.getElementById('username').InputTransformOptions.maxLength = 25;

// Initialize image transformations
InputTransform.init('input#image-upload', {
    fileType: 'jpg,png,webp',
    maxImageSize: 500000, // 500 KB
    imageBase64: true // transform the input image to a image in base64 encoded string
});

Using initOne and initAll

Instead of manually defining transformations in JavaScript, you can use HTML data attributes. The initOne method applies transformations based on an element's attributes, while initAll applies them to all inputs on the page.

Example:

<input type="text" id="username" data-input-transform-max-length="25" data-input-transform-trim="true">
InputTransform.initOne('#username');

This will automatically trim spaces and limit the input to 25 characters.

Alternatively, to initialize all matching inputs on the page:

InputTransform.initAll();

This will apply transformations to all elements that have data-input-transform-* attributes.

API

| Method | Description | Parameters | |---------------|-------------|------------| | regex | Applies a regex replacement to the input value. | regex (RegExp), replace (string, optional) | | regexs | Applies multiple regex replacements. | regexs (array of { regex, replace }) | | minNumber | Ensures the number is at least a minimum value. | minNumber (number) | | maxNumber | Ensures the number is at most a maximum value. | maxNumber (number) | | uppercase | Converts the input to uppercase. | None | | lowercase | Converts the input to lowercase. | None | | capitalize | Capitalizes the first letter of the input. | None | | trim | Removes leading and trailing spaces. | None | | clearSpaces | Removes all spaces from the input. | None | | clearNumbers | Removes all numbers from the input. | None | | onlyNumbers | Removes all non-numeric characters. | None | | clearSymbols | Removes all symbols except letters and numbers. | None | | onlySymbols | Removes all letters and numbers, keeping only symbols. | None | | clearLetters | Removes all letters from the input. | None | | onlyLetters | Removes all non-letter characters. | None | | maxLength | Limits the input to a maximum number of characters. | maxLength (number) | | clear | Removes a specific substring. | clear (string) | | clears | Removes multiple substrings. | clears (comma-separated string) | | fileType | Validates allowed file extensions. | fileType (comma-separated string) | | maxImageSize | Restricts file size for uploaded images. | maxImageSize (bytes) | | imageBase64 | Converts uploaded images to Base64. | None | | imageBase64Webp | Converts uploaded images to WebP format. | None |

Initialization Methods

| Method | Description | Parameters | |-------------|-------------|------------| | init | Initializes an input field with specified transformation methods. | input (string or Element), options (object) | | initOne | Automatically initializes a single input using data attributes. | input (string or Element) | | initAll | Automatically initializes all inputs on the page that have transformation data attributes. | None |

Events

InputTransform emits custom events that you can listen to:

| Event Name | Description | |-----------|-------------| | input-transform.init | Triggered when an input transformation is initialized. | | input-transform.error | Triggered when an error occurs (e.g., invalid file type or size). | | input-transform.change | Triggered when the input value is transformed. |

Example:

document.getElementById('username').addEventListener('input-transform.change', event => {
    console.log('Transformed value:', event.detail.value);
});

window.addEventListener('input-transform.error', event => {
    console.error('Error:', event.detail.message);
})

License

MIT