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 `format` 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.8kB
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) )
TIP
For usage with the UMD build see here.
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.8kB
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
import { format } from 'quasar' const { normalizeToInterval } = format // (Number) normalizeToInterval(Number, Number lower_margin, Number upper_margin) console.log( normalizeToInterval(21, 10, 20) ) // 10 console.log( normalizeToInterval(33, 10, 20) ) // 11 console.log( normalizeToInterval(52, 10, 20) ) // 19 console.log( normalizeToInterval(5, 10, 16) ) // 12
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'