2.1.2 • Published 10 years ago

@stridekick/formatters v2.1.2

Weekly downloads
-
License
UNLICENSED
Repository
github
Last release
10 years ago

@stridekick/formatters

A collection of formatter functions

Table of Contents

Installation

npm install --save-dev @stridekick/formatters

Usage

Import the formatters needed

All formatters have chainable operations (denoted by chainable)

import {DateFormatter, NumberFormatter, StringFormatter} from '@stridekick/formatters'

const dateFormatter   = new DateFormatter(new Date())
const numberFormatter = new NumberFormatter(10000)
const stringFormatter = new StringFormatter('https://stridekick.com')

const stringFormatter = new StringFormatter('https://stridekick.com')
  .chompLeft('https://')
  .chompRight('.com')
  .toString() // stridekick

Formatters

NumberFormatter

Numbers can be formatted to look like currency, percentages, times, or even plain old numbers with decimal places, thousands, and abbreviations.

const numberFormatter = new NumberFormatter(10000)

toString

Returns the result of the chained operations

API {numberFormatter}.toString([format])

numberFormatter (required)

  • Description: an instance of NumberFormatter
  • Type: NumberFormatter
  • Default: undefined

format (optional)

  • Description: format to be applied to number
  • Type: string
  • Default: NumberFormatter.formats.DEFAULT === 0,0
  • Supported options:

Example

import {NumberFormatter} from '@stridekick/formatters'

new NumberFormatter(100).toString() // 100
new NumberFormatter(1000).toString() // 1,000
new NumberFormatter(10000).toString() // 10,000
new NumberFormatter(10000.00).toString() // 10,000
new NumberFormatter(10000.10).toString() // 10,000
new NumberFormatter(10000.10).toString(NumberFormatter.formats.TWO_DECIMAL_PLACES) // 10,000.10

formats

Named formats

  • DEFAULT === 0,0
  • TWO_DECIMAL_PLACES === 0,0.00

string

chompLeft

Removes prefix from start of string

API chompLeft(string, prefix)

string (required)

  • Description: original string
  • Type: string
  • Default: undefined

prefix (required)

  • Description: string to be chomped
  • Type: string
  • Default: undefined

Example

import {string} from '@stridekick/formatters'

string.chompLeft(`http://url.com`, `http://`) // url.com

Publishing

To publish updates to the npm repository:

  1. Push all code changes to the code repository

  2. npm install

  3. Perform one of the following:

  • npm run publish:patch - {major}.{minor}.{patch +1}
  • npm run publish:minor - {major}.{minor + 1}.0
  • npm run publish:major - {major + 1}.0.0
2.1.2

10 years ago

2.1.1

10 years ago

2.1.0

10 years ago

2.0.0

10 years ago

1.0.9

10 years ago

1.0.8

10 years ago

1.0.7

10 years ago

1.0.6

10 years ago

1.0.5

10 years ago

1.0.4

10 years ago

1.0.3

10 years ago

1.0.2

10 years ago

1.0.0

10 years ago