Nearsighted Paramecium Multiverse
    Wondering what’s next for npm?Check out our public roadmap! »

    simple-mask-money

    3.0.1 • Public • Published

    SimpleMaskMoney

    WARNING

    if you are having problems check the version you are using. The docs to old (2.x.x) version stay here

    NPM

    build Status npm version npm Downloads Codacy Badge License

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

    Getting Started

    First, install it.

      npm i simple-mask-money --save

    Or use direct of github release

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

    remember change <RELEASE_VERSION_HERE> by the last version

    Read the docs or chose your implementation:

    Then, follow the example to use in your browser:

      <body>
        <!-- 
          Put inputmode numeric to mobile show only numbers 
        -->
        <input id="myInput" inputmode="numeric" value="0,00">
     
        <script src="./node_modules/simple-mask-money/lib/simple-mask-money.js"></script> 
        <script>
     
          // configuration
          const args = {
            afterFormat(e) { console.log('afterFormat', e); },
            allowNegative: false,
            beforeFormat(e) { console.log('beforeFormat', e); },
            negativeSignAfter: false,
            prefix: '',
            suffix: '',
            fixed: true,
            fractionDigits: 2,
            decimalSeparator: ',',
            thousandsSeparator: '.',
            cursor: 'move'
          };
     
          // select the element
          const input = SimpleMaskMoney.setMask('#myInput', args);
     
          // This method return value of your input in format number to save in your database
          input.formatToNumber();
     
        </script> 
      </body>

    Or if you prefer use the methods in your events

      <body>
        <!-- 
          Put inputmode numeric to mobile show only numbers 
        -->
        <input inputmode="numeric" value="0,00">
     
        <script src="./node_modules/simple-mask-money/lib/simple-mask-money.js"></script> 
        <script>
          // select the element
          let input = document.getElementsByTagName('input')[0];
     
          // configuration
          SimpleMaskMoney.args = {
            afterFormat(e) { console.log('afterFormat', e); },
            allowNegative: false,
            beforeFormat(e) { console.log('beforeFormat', e); },
            negativeSignAfter: false,
            prefix: '',
            suffix: '',
            fixed: true,
            fractionDigits: 2,
            decimalSeparator: ',',
            thousandsSeparator: '.',
            cursor: 'move'
          };
     
          input.oninput = () => {
            input.value = SimpleMaskMoney.format(input.value);
          }
     
          // Your send method
          input.onkeyup = (e) => {
            if (e.key !== "Enter") return;
            // This method return value of your input in format number to save in your database
            SimpleMaskMoney.formatToNumber(input.value);
          }
        </script> 
      </body>

    Install

    npm i simple-mask-money

    DownloadsWeekly Downloads

    774

    Version

    3.0.1

    License

    Apache-2.0

    Unpacked Size

    199 kB

    Total Files

    9

    Last publish

    Collaborators

    • avatar