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

@ryangjchandler/alpine-mask

v0.2.0

Published

A clean Cleave integration for Alpine.js.

Downloads

1,308

Readme

✨ Help support the maintenance of this package by sponsoring me.

Alpine Mask

This packages provide a custom x-mask directive and $mask magic variable, powered by Cleave.js.

GitHub tag (latest by date) Build size Brotli Monthly downloads via CDN

This package only supports Alpine v3.x.

Installation

CDN

Include the following <script> tag in the <head> of your document, just before Alpine.

<script
    src="https://cdn.jsdelivr.net/npm/@ryangjchandler/[email protected]/dist/cdn.min.js"
    defer
></script>

NPM

npm install @ryangjchandler/alpine-mask

Add the x-mask directive and $mask magic property to your project by registering the plugin with Alpine.

import Alpine from "alpinejs";
import Mask from "@ryangjchandler/alpine-mask";

Alpine.plugin(Mask);

window.Alpine = Alpine;
window.Alpine.start();

Usage

To mask an input, add the x-mask directive to your element.

<input x-data x-mask="{ ...allMyCleaveOptionsHere }">

By default, the x-mask directive will expect a configuration object. This gives you full control over the Cleave.js instance.

There's also a list of convenience modifiers below that configure Cleave.js for you with sensible defaults.

Credit Cards

<input x-mask.card>

This will format your input as a credit card input. By default, it will separate each section of the card number into blocks separated by a space.

If you would like to support 19-digit PANs, you can add the .strict modifier to the directive.

<input x-mask.card.strict>

Date

To format your input as a date, use the .date modifier.

<input x-mask.date>

By default, Cleave will format your data in a d/m/Y pattern. If you wish to change this, provide a custom pattern inside of the directive expression.

<input x-mask.date="['Y', 'm', 'd']">

The input will now be formatted as Y/m/d.

Time

To format your input as a time, use the .time modifier.

<input x-mask.time>

By default, Cleave will format your time with the h:m:s pattern. If you wish to change this, provide a custom pattern inside of the directive expression.

<input x-mask.date="['h', 'm']">

The input will now be formatted as h:m.

Numeral / Numeric

If you would like to format a number inside of your input, you can use the .numeral modifier.

To format your input as a date, use the .date modifier.

<input x-mask.date>

By default, Cleave will format your data in a d/m/Y pattern. If you wish to change this, provide a custom pattern inside of the directive expression.

<input x-mask.numeral>

By default, Cleave formats your number using a comma (,) as the thousands-separator and a full-stop (.) as the decimal-separator.

If you would to change the thousands delimiter, you can provide either .delimiter.dot or .delimiter.comma.

<input x-mask.numeral.delimiter.dot>

The number 100,000 will now be formatted as 100.000.

If you would to provide a custom prefix (money fields, etc), you can use the .prefix modifier followed by your prefix of choice.

<input x-mask.numeral.prefix.£>

This will prefix your input with £.

NOTE: HTML attributes are case-insensitive. If you would like to use a more complex prefix or configuration, I recommend using x-mask with a custom configuration object.

Blocks

If you would like to segment your input and format the data in blocks, you can use the .blocks modifier and provide a list of block lengths as the directive expression.

<input x-mask.blocks="[3, 4, 5]">

This would input the following input 333444455555 as 333 4444 55555.

Two-way data binding

<div x-data="{ raw: 2000 }">
    <input x-mask.numeral x-model="raw" >
</div>

When this input is initialised, raw will be formatted and the value will be set on the input. Anytime the input is updated, the raw value will be synced back to the raw property.

All changes made to the raw property outside of Cleave.js (other functions, etc) will also sync back and be formatted.

Versioning

This projects follow the Semantic Versioning guidelines.

License

Copyright (c) 2021 Ryan Chandler and contributors

Licensed under the MIT license, see LICENSE.md for details.