Formatter Utils     

Helping Tree-Shake

You will notice all examples import format Object from Quasar. However, if you need only one formatter method from it, then you can use ES6 destructuring to help Tree Shaking embed only that method and not all of format.

Example:

// we import all of `date`
import { format } from 'quasar'
// destructuring to keep only what is needed
const { capitalize, humanStorageSize } = format

console.log( capitalize('some text') )
// Some text
console.log( humanStorageSize(13087) )
// 12.78 kB

You can also import all formatters and use whatever you need like this (but note that your bundle will probably contain unused methods too):

import { format } from 'quasar'

console.log( format.capitalize('some text') )
console.log( format.humanStorageSize(13087) )

Capitalize

import { format } from 'quasar'
const { capitalize } = format

console.log( capitalize('some text') )
// Some text

Format to Human Readable Size

import { format } from 'quasar'
const { humanStorageSize } = format

console.log( humanStorageSize(13087) )
// 12.78 kB

Normalize Number to Interval

import { format } from 'quasar'
const { between } = format

// (Number) between(Number, Number min, Number max)
console.log( between(50, 10, 20) )
// 20

Pad String

import { format } from 'quasar'
const { pad } = format

// (String) pad(String toPad, Number length, String paddingCharacter)
// length is default 2
// paddingCharacter is default '0'
console.log( pad('2', 4) )
// '0002'