1.1.2 • Published 7 years ago

js-text-formatter v1.1.2

Weekly downloads
13
License
-
Repository
-
Last release
7 years ago

Js-Text-Formatter Build Statuscodecov.io

Js-Text-Formatter is a small module that allows you to easily format your input e.g. zipCode in a generic way. You can use either the angular directive, the jQuery plugin or the formatter on its own.

Installing Js-Text-Formatter

  • Clone the repo: git clone https://github.com/Avoran/js-text-formatter.git

  • Install with NPM: npm install js-text-formatter

Using Js-Text-Formatter

native javascript

<script src="/path/to/your/scripts/here/dist/formatter.min.js"></script>
  • Use the formatter like:
var formatter = new Formatter({format: '4D 2S'});
var formattedVar = formatter.format(varToFormat);

angular

<script src="/path/to/your/scripts/here/dist/angular-formatter.min.js"></script>
  • Add a dependency to av.format in your app module, eg: angular.module('myModule', ['av.format'])
  • Format an input like:
<div>
  <input ng-model="zipCode" av-format="4D 2S" />
</div>

jQuery

<script src="/path/to/your/scripts/here/dist/jquery-formatter.min.js"></script>
  • Format an input in html like:
<div>
  <input av-format="4D 2S" />
</div>
  • or call the formatter on an input like:
$('input').avFormat('4D 2S');

Documentation

There are currently 3 types of data you can give in your format string:

  • Quantifier
  • Command
  • Extra content

Quantifier

A quantifier is nothing more than an whole, positive, number you add to your string. Directly after it should de command be found. A quantifier is to specify how much times you want to use the following command, e.g. how many digits you want formatted.

Command

The following command can be a D or a S. With the D you specify to format digits and with the S currently the rest, spaces excluded.

Extra content

Extra content is everything else. You can escape Quantifiers by adding a slash. This is not nescessary when no command is followed. Adding slashes on it's own is currently not featured.

1.1.2

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago