# pollen8-number-formatter

> Format numbers according to our schema setup. Packaged up to be shared between FE and BE

Latest version **0.0.1** (published 2022-05-10) · ISC license · 0 weekly downloads

## Install

```sh
npm install pollen8-number-formatter
pnpm add pollen8-number-formatter
yarn add pollen8-number-formatter
bun add pollen8-number-formatter
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.1 |
| Published | 2022-05-10 |
| First published | 2022-05-10 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 25.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Nathan Chicken |
| Maintainers | cowfields |

## Links

- npm: https://www.npmjs.com/package/pollen8-number-formatter
- Repository: https://github.com/pollen8io/pollen8-number-formatter
- Homepage: https://github.com/pollen8io/pollen8-number-formatter#readme
- Issues: https://github.com/pollen8io/pollen8-number-formatter/issues
- npm.io page: https://npm.io/package/pollen8-number-formatter

## Recent versions

- 0.0.1 (latest) — 2022-05-10

## README

# Number Formatter

This is a simple micro-utility that helps you format a number and add
prefixes and suffixes - most likely a currency or percentage and adding the
appropriate commas.

We use it when we have a field configuration that might store a currency code
and we need to be able to easily choose the currency simple based on that
code, or if it's a percentage to add that symbol too. 

## Usage

There are two functions, they're pretty similar. Most likely you want to
apply different styles to the components for legibility so you would use
`formatNumber` like so:

```javascript
import { formatNumber } from 'pollen8-number-formatter'
const { prefix, suffix, value } = formatNumber(4000, { currency: 'GBP' })

console.log(prefix, suffix, value) // logs '£', 'GBP', '4,000' 

```

For example:

```vue
<template>
  <div>
    <span v-if="formatted.prefix" class="light-grey">
      {{ formatted.prefix }}
    </span>
    {{ value }}
    <span v-if="formatted.suffix"  class="light-grey">
      {{ formatted.suffix }}
    </span>
  </div>
</template>

<script>
import { formatNumber } from 'pollen8-number-formatter'

export default {
  computed: {
    formatted () {
      return formatNumber(4000, { currency: 'GBP' })
    }
  }
}
</script>
```

### Simpler usage:

You can just output a joined string if you wish:

```javascript
import { formatNumberString } from 'pollen8-number-formatter'
const formatted = formatNumberString(4000, { currency: 'GBP' })
console.log(formatted) // logs '£4,000GBP'

```

---
_Source: https://npm.io/package/pollen8-number-formatter · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
