GithubHelp home page GithubHelp logo

silvajohnny / vanilla-masker Goto Github PK

View Code? Open in Web Editor NEW

This project forked from vanilla-masker/vanilla-masker

0.0 2.0 0.0 239 KB

VanillaMasker is a pure javascript input mask

Home Page: http://bankfacil.github.io/vanilla-masker

vanilla-masker's Introduction

What's this

Build Status Code Climate

It's a pure JavaScript input mask.
Now you can use a simple and pure javascript lib to mask html elements.
Fuck jQuery, Zepto and any others javascript frameworks!

Let's live now in a lightweight client-side world using VanillaMasker.
This is a cross-browser and cross-device lib for desktop and responsible sites.

The demo page.

How to use

Download the lib:

Or install it using Bower: bower install --save vanilla-masker

Include it into your html page:

<script src="vanilla-masker.min.js"></script>

And given these simple inputs tag:

<input type="text">

You can use the code below...

// Constructor
// Input number example: 1234567890
var masker = new VanillaMasker({
  // Decimal precision -> "90"
  precision: 2, 
  // Decimal separator -> ",90"
  separator: ',', 
  // Number delimiter -> "12.345.678"
  delimiter: '.', 
  // Money unit -> "R$ 12.345.678,90"
  unit: 'R$', 
  // Force type only number instead decimal,
  // masking decimals with ",00"
  // Zero cents -> "R$ 1.234.567.890,00"
  zeroCents: true,
  // Phone format
  phone: '(99) 9999-9999',
  // Date format
  date: '99/99/9999'
});

// Functions
// Listen the input element masking it to money.
masker.maskMoney(document.querySelector("input"));

// Listen array of input elements masking it to money.
masker.maskMoney(document.querySelectorAll("input"));

// Converts number to money string
masker.toMoney(1234); // -> R$ 1.234,00

// Listen the input element masking it to number.
masker.maskNumber(document.querySelector("input"));

// Converts any string to number 
masker.toNumber("123ac34"); // -> 12334

// Listen the input element masking it to date format.
masker.maskDate(document.querySelector("input"));

// Converts any string to date string 
masker.toDate("12121900"); // -> 12/12/1990

// Listen the input element masking it to cpf format.
masker.maskCPF(document.querySelector("input"));

// Converts any string to cpf format 
masker.toCPF("99999999999"); // -> 999.999.999-99

// Listen the input element masking it to cnpj format.
masker.maskCNPJ(document.querySelector("input"));

// Converts any string to cnpj format 
masker.toCNPJ("99999999000199"); // -> 99.999.999.0001-99

// Listen the input element masking it to phone format.
masker.maskPhone(document.querySelector("input"));

// Converts any string to phone format 
masker.toPhone("1199999999"); // -> (11) 9999-9999

How to run localhost

Run test

  • Run the command: grunt test

Build project

  • Run the command: grunt build

TODO - we need pull requests :]

  • AMD support;
  • Beautify Demo Page;

Compatibility

Desktop browsers:

  • Chrome
  • Firefox
  • Safari
  • Opera
  • Internet Explorer 9+ (coming soon IE8 support)

Mobile browsers:

  • Android (2.2+) native browsers
  • Chrome mobile
  • Dolphin
  • Opera mobile (not tested yet)
  • iOS

Contributors

Caio Ribeiro Pereira - [email protected]
Leandro Alvares da Costa - [email protected]
Henrique Antonini Silvério - [email protected]

License

MIT License: http://bankfacil.mit-license.org

Powered by

Bankfacil: http://www.bankfacil.com.br

vanilla-masker's People

Contributors

caio-ribeiro-pereira avatar leandroadacosta avatar

Watchers

James Cloos avatar Johnny Ramos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.