# @flourish/number-localization

> Input and output number separators

Latest version **0.0.1** (published 2018-08-20) · UNLICENSED license · 0 weekly downloads

## Install

```sh
npm install @flourish/number-localization
pnpm add @flourish/number-localization
yarn add @flourish/number-localization
bun add @flourish/number-localization
```

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.1 |
| Published | 2018-08-20 |
| First published | 2018-06-21 |
| Weekly downloads | 0 |
| License | UNLICENSED |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 16.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Kiln Enterprises Ltd |
| Maintainers | annaps, daanlouter, duncanclark, felixmichel, gavrilov, hughsk, julien1993, robinhouston, timbrock |

## Links

- npm: https://www.npmjs.com/package/@flourish/number-localization
- npm.io page: https://npm.io/package/@flourish/number-localization

## Dependencies (2)

- [d3-format](https://npm.io/package/d3-format.md) ^1.3.0
- [rollup-plugin-node-resolve](https://npm.io/package/rollup-plugin-node-resolve.md) ^3.3.0

## Recent versions

- 0.0.1 (latest) — 2018-08-20
- 0.0.1-alpha4 — 2018-06-22
- 0.0.1-alpha3 — 2018-06-21
- 0.0.1-alpha2 — 2018-06-21

## README

# Flourish number localization

Flourish module for setting the numeric separators used in a template. Used in conjunction with [Flourish number formatter](https://github.com/kiln/flourish-number-formatter).

## Install

To install the module, type:
``` shell
npm install @flourish/number-localization
```

To add the module's settings block, include the following in a templates' template.yml file:
``` yml
- property: localization
  import: "@flourish/number-localization"
```

## Usage

Include a (usually empty) object in the state declaration:

``` js
	var state = {
		/* Other declarations of default values */
		localization: {},
		/* Any further state properties */
	}
```

Make sure an instance of the module is initialised somewhere in the code before draw is called:

``` js
import initLocalization from "@flourish/number-localization";;
/* Other imports and code */
var localization = initLocalization(state.localization);
/* Other initialisation code, eg Flourish-number-formatter instances */
export { localization/*, etc */ };
```

This will add two properties to `state.localization` (if they don't already exist), `input_decimal_separator` (defaults to ".") and `output_separators` (defaults to ",."). The exported `localization` object contains two methods, `getParser` and `getFormatterFunction`.

The `getParser` method returns a function for parsing text into numbers based on the value of `input_decimal_separator` at the time it is called;

``` js
import { localization } from "init.js";
var parser = localization.getParser();
["1.2", "-4,000", "$326k"].map(parser) // Returns [1.2, -4000, 326] for input_decimal_separator === "."
// The above would return [12, -4, 326] for input_decimal_separator === ","
```

The `getFormatterFunction` method creates a locale function based on the value of `output_separators` at the time it is called. It is meant to  be passed on to instances of Flourish number formatter:
```js
import { localization, getXAxisFormatter, getYAxisFormatter } from "init.js";
var localeFunction = localization.getFormatterFunction();
var xFormat = getXAxisFormatter(localeFunction);
var yFormat = getYAxisFormatter(localeFunction);
```

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