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

simple-mask-money

v4.1.3

Published

Simple money mask developed with pure JavaScript. To run on Client Side and Server Side

Downloads

10,126

Readme

Simple money mask developed with pure JavaScript 🗃️ 0 dependecies, 🍃 Super light just 1.65kB gzipped, 🔒 100% Secure (no npm audit problems or dependabot issues) which you can run on Client Side and Server Side. Try live demo.

🎉 Getting Started

Installation

First install it:

  npm i simple-mask-money --save

Or access the GitHub release directly:

<script src="https://github.com/codermarcos/simple-mask-money/releases/download/<RELEASE_VERSION_HERE>/simple-mask-money.js"></script>

Remember to replace <RELEASE_VERSION_HERE> with the latest version

Implementation

After installed is just implement, for it choose the best example for you.

React JS Basic Example

For use with React JS you can pass only the id:

import { useEffect } from 'react';
import { setMask } from 'simple-mask-money';

function InputMoneyComponent() {
  useEffect(setMask('#my-input'), []);

  return <input id="my-input" />
}

If you prefer you can use a ref:

import { useEffect } from 'react';
import { setMask, useRef } from 'simple-mask-money';

function InputMoneyComponent() {
  const inputRef = useRef(null);

  useEffect(setMask(inputRef.current), []);

  return <input ref={inputRef} />
}

These are only the basic usage if you need configure some arguments you can check documentation about full api reference

Vanilla JS Basic Example

Here is a usage example with Vanilla JS:

  <body>
    <!-- Set inputmode to numeric to show only numbers on mobile -->
    <input id="my-input" />

    <script src="./node_modules/simple-mask-money/lib/simple-mask-money.js"></script>
    
    <script>
      // Select the element
      const removeMask = SimpleMaskMoney.setMask('#my-input');
      // Convert the input value to a number, which you can save e.g. to a database:
      SimpleMaskMoney.formatToNumber(input.value);
    </script>
  </body>

These are only the basic usage if you need configure some arguments you can check documentation about full api reference

Vue JS Basic Example

Here is a usage example with Vue JS:

<template>
  <form>
    <input type="text" id="my-input" />
  </form>
</template>

<script>
import { setMask, formatToNumber } from 'simple-mask-money'; // import mask

export default {
  mounted() {
    SimpleMaskMoney.setMask('#my-input'); // set mask on your input you can passing a querySelector
  },
  beforeUnmount() {
    SimpleMaskMoney.removeMask('#my-input'); // remove mask destroy listeners
  },
}
</script>

These are only the basic usage if you need configure some arguments you can check documentation about full api reference

Angular Basic Example

Here is a usage example with Angular JS:

import { setMask, removeMask, formatToNumber } from 'simple-mask-money'; // import mask
import { Component, OnInit, AfterViewInit } from '@angular/core';

@Component({
  template: '<input id="my-input" />'
})
export class InputMoneyComponent implements AfterViewInit, OnDestroy {

  ngAfterViewInit() {
    setMask('#my-input'); // set mask on your input you can pass a querySelector or your input element and options
  }

  ngOnDestroy() { 
    removeMask('#my-input'); // remove mask destroy listeners
  }
}

These are only the basic usage if you need configure some arguments you can check documentation about full api reference

📚 Detailed documentation

Read the docs or chose your implementation to check an example:

✨ Some features and behaviours

  • Clear the mask
    • Remove listeners
  • Allow type only numbers
    • Block user to type non-numeric chars
  • Allow negative numbers
    • It permit user add a negative sign
  • Allow choose if negative sign is before or after
  • Allow lock the carret bar on end
  • Allow choose how many fractionalDigits
  • Allow choose decimal and thousands separators

🦾 Contribute to this project

This project needs your help, all contributions are welcome!

For it please take a look for some patterns in this documentation.

Requirements to run this project

This repository uses:

| Dependencies | Description | Docs | | -------------------------------------------- | ------------------ | ---------------- | | node-version | Javascript Runtime | 📚 |

You can use NVM to select correct node version based on file .nvmrc.

Developing in this project

  1. Clone it:
git clone [email protected]:codermarcos/simple-mask-money.git

Or just make a fork.

  1. Install the dependecies whitout change the lock file:
npm ci

Just change the lock file if necessary.

  1. Run build to generate a build:
npm run build

Before open a PR

Remember of write unit and e2e tests, and make it works!

  1. Run unit tests
npm run test
  1. Run e2e tests
npx cypress open

📖 Learn More

To learn more about this project, take a look at the following resources:

  • Typescript - understand about typescript.
  • Rollup - understand about the bundler used by this project.
  • Jest - understand about the tool that we use for write unit tests.
  • Cypress - understand about the tool that we use for write e2e tests.