Skip to content

Instantly share code, notes, and snippets.

@jeanlescure
Last active September 23, 2015 09:55
Show Gist options
  • Save jeanlescure/1db7cee46d10eff8712f to your computer and use it in GitHub Desktop.
Save jeanlescure/1db7cee46d10eff8712f to your computer and use it in GitHub Desktop.

Number Prettifier NodeJS Package

(This README is written using Markdown notation, for better viewing visit: https://goo.gl/aIEm4Y)

This is my submission for the Crossover Tech Trial. A NodeJS package which can be used to extend back-end and front-end applications alike with the ability to transform number types less than a Quadrillion in the short scale to prettified strings.

The package includes two demo files, one for back-end (using NodeJS) and another for front-end (browser).

Requirements - Back-end

Back-end usage of Number Prettifier requires having NodeJS installed.

For more information on installing NodeJS visit: https://nodejs.org/

In order to install requirements for back-end usage, specially if you plan on running specs, navigate to the Code folder and run on the terminal:

  $ npm install

This will install dependencies.

Usage - Back-end

Usage in NodeJS applications is straight-forward:

  var Pretty = require('./prettifier');
  var pretty = new Pretty();
  
  pretty.prettify_number(1000000); // -> '1M'

Requirements & Usage - Front-end

For usage in front-end applications, there are no requirements, simply include the prettifier.js file within HTML as such:

  <script src="/path/to/prettifier.js"></script>

and use like this:

  var pretty = new Pretty();
  
  pretty.prettify_number(1000000); // -> '1M'

Running Specs

To run specs, navigate to Code folder and run the following command on the terminal:

  $ npm test

Running Demo - Back-end

Navigate to the Code folder and run on the terminal:

  $ node demo.js

Running Demo - Front-end

Navigate to the Code folder and open file demo.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment