Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including lisk-prettify with all npm packages installed. Try it out:

var liskPrettify = require("lisk-prettify")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

lisk-prettify v1.1.1

Formats raw Lisk amounts to be more human-readable. Adds decimal point and commas where necessary.

lisk-prettify

Format raw Lisk amounts to be more human-readable. Adds decimal point and commas where necessary.

e.g. 100251338358 becomes 1,002.51338358

Install

npm install --save lisk-prettify

Include in scripts

// require
var liskPrettify = require('lisk-prettify').liskPrettify

// require (ES6 version)
const { liskPrettify } = require('lisk-prettify')

// import
import liskPrettify from 'liskPrettify'

Usage Example

liskPrettify(100251338358)
// "1,002.51338358"

API

liskPrettify(rawLskValue, config <optional>)

Parameters

rawLskValue (number) - The raw LSK amount, usually returned when performing API calls to the Lisk network.

config (object) <optional> - Configuration for the returned result. The configurations are:

  • commas (boolean) - Choose whether or not to display commas where necessary e.g. 1,000,000.00000000. Default: true
  • decimals (boolean) - Choose whether or not to display decimal places. Default: true

Examples

Prettify a LSK amount

liskPrettify(100251338358)
// Result: "1,002.51338358"
// returns a string

Prettify a LSK amount without commas

liskPrettify(100251338358, { commas: false })
// Result: 1002.51338358
// returns a number

Prettify a LSK amount without decimal places

liskPrettify(100251338358, { decimals: false })
// Result: "1,002"

Tests

/* run this command inside lisk-prettify's
   node_modules folder */

npm run test

Feedback

Pull requests and opened issues are welcome!

License

MIT

Metadata

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free