number-display
Advanced tools
Comparing version 2.2.3 to 2.3.0
114
CHANGELOG.md
@@ -1,52 +0,53 @@ | ||
## 1.0.0 | ||
## 2.3.0 | ||
**2018-09-26** | ||
**2020-03-12** | ||
* Init this package. | ||
- Make seporator and units configurable. | ||
## 1.1.0 | ||
## 2.2.3 | ||
**2018-09-26** | ||
**2020-01-08** | ||
- Change the commafy method from toLocaleString to rgx, as toLocaleString went work in android/safari. | ||
- Put config params in a object. | ||
- `allowText` default to false, to prevent unexpected result of input `''`. | ||
## 1.1.1 | ||
## 2.2.2 | ||
**2018-09-26** | ||
**2020-01-08** | ||
- Optimize unitfy method. | ||
- Fix config params to be optional in index.d.ts. | ||
## 1.2.0 | ||
## 2.2.1 | ||
**2018-09-26** | ||
**2020-01-08** | ||
- Add units config params. | ||
- Deal overflow with placeholder. | ||
- Fix file set in package.json. | ||
## 1.2.1 | ||
## 2.2.0 | ||
**2019-02-07** | ||
**2020-01-08** | ||
- Fix unitfy retrun array. | ||
- Add built-in types for Typescript. | ||
- Update license to 2020. | ||
## 2.0.0 | ||
## 2.1.2 | ||
**2019-07-25** | ||
**2019-12-07** | ||
- Simplify APIs, details in README.md. | ||
- Optimize performance. | ||
- Add unit test. | ||
- Change back param precision name to 'decimal', to avoid confusion with the common 'toPrecision' meaning. | ||
- Add inner precision limit to avoid float error. | ||
## 2.0.1 | ||
## 2.1.1 | ||
**2019-07-26** | ||
**2019-12-05** | ||
- Fix wrong return of '' and '-'. | ||
- Change param decimal name to 'precision', and default to equal to param length, witch means no additional limit. | ||
- Opt the rounding function. | ||
- Change param comma name to 'separator'. | ||
## 2.0.2 | ||
## 2.1.0 | ||
**2019-07-30** | ||
**2019-12-02** | ||
- Remove decimal trailing zeros. | ||
- Add feature: roundingType. Now you can set the way to round the decimal in 'round', 'floor' or 'ceil', witch default to 'round'. | ||
- When the length is too small, number-display will return the origin value as a string, instead of throwing an error. | ||
@@ -59,47 +60,52 @@ ## 2.0.3 | ||
## 2.1.0 | ||
## 2.0.2 | ||
**2019-12-02** | ||
**2019-07-30** | ||
- Add feature: roundingType. Now you can set the way to round the decimal in 'round', 'floor' or 'ceil', witch default to 'round'. | ||
- When the length is too small, number-display will return the origin value as a string, instead of throwing an error. | ||
- Remove decimal trailing zeros. | ||
## 2.1.1 | ||
## 2.0.1 | ||
**2019-12-05** | ||
**2019-07-26** | ||
- Change param decimal name to 'precision', and default to equal to param length, witch means no additional limit. | ||
- Opt the rounding function. | ||
- Change param comma name to 'separator'. | ||
- Fix wrong return of '' and '-'. | ||
## 2.1.2 | ||
## 2.0.0 | ||
**2019-12-07** | ||
**2019-07-25** | ||
- Change back param precision name to 'decimal', to avoid confusion with the common 'toPrecision' meaning. | ||
- Add inner precision limit to avoid float error. | ||
- Simplify APIs, details in README.md. | ||
- Optimize performance. | ||
- Add unit test. | ||
## 2.2.0 | ||
## 1.2.1 | ||
**2020-01-08** | ||
**2019-02-07** | ||
- Add built-in types for Typescript. | ||
- Update license to 2020. | ||
- Fix unitfy retrun array. | ||
## 2.2.1 | ||
## 1.2.0 | ||
**2020-01-08** | ||
**2018-09-26** | ||
- Fix file set in package.json. | ||
- Add units config params. | ||
- Deal overflow with placeholder. | ||
## 2.2.2 | ||
## 1.1.1 | ||
**2020-01-08** | ||
**2018-09-26** | ||
- Fix config params to be optional in index.d.ts. | ||
- Optimize unitfy method. | ||
## 2.2.3 | ||
## 1.1.0 | ||
**2020-01-08** | ||
**2018-09-26** | ||
- `allowText` default to false, to prevent unexpected result of input `''`. | ||
- Change the commafy method from toLocaleString to rgx, as toLocaleString went work in android/safari. | ||
- Put config params in a object. | ||
## 1.0.0 | ||
**2018-09-26** | ||
* Init this package. |
@@ -8,4 +8,5 @@ /** | ||
* @param allowText - (Default false) Allow text as results, if false text will convert to placeholder, text will be slice within length param. | ||
* @param separator - (Default true) Show commas between digits in group of 3, if there are rooms. | ||
* @param roundingType - (Derault 'round') Rounding type of decimals, enum in 'round', 'floor' or 'ceil'. | ||
* @param {boolean} [separator] set separators between digits in group of 3, if there are rooms; default is ',' | ||
* @param {string} [roundingType] rounding type of decimals, enum in 'round', 'floor' or 'ceil'; default 'round' | ||
* @param {Array<string>} [units] digital units, default is ['k', 'M', 'G', 'T', 'P'] | ||
* | ||
@@ -21,2 +22,3 @@ * @returns The display function. | ||
roundingType, | ||
units, | ||
}?: { | ||
@@ -27,4 +29,5 @@ length?: number, | ||
allowText?: boolean, | ||
separator?: boolean, | ||
separator?: string, | ||
roundingType?: 'round' | 'floor' | 'ceil', | ||
units?: Array<string>, | ||
}): (value: any) => string; |
@@ -21,4 +21,5 @@ const maxPrecision = 12; | ||
* @param {boolean} [allowText] allow text as results, if false text will convert to placeholder, text will be slice within length param; default false | ||
* @param {boolean} [separator] show commas between digits in group of 3, if there are rooms; default true | ||
* @param {string} [roundingType] Rounding type of decimals, enum in 'round', 'floor' or 'ceil'; default 'round' | ||
* @param {boolean} [separator] set separators between digits in group of 3, if there are rooms; default is ',' | ||
* @param {string} [roundingType] rounding type of decimals, enum in 'round', 'floor' or 'ceil'; default 'round' | ||
* @param {Array<string>} [units] digital units, default is ['k', 'M', 'G', 'T', 'P'] | ||
*/ | ||
@@ -30,4 +31,5 @@ const createDisplay = ({ | ||
allowText = false, | ||
separator = true, | ||
separator = ',', | ||
roundingType = 'round', | ||
units = ['k', 'M', 'G', 'T', 'P'], | ||
} = {}) => value => { | ||
@@ -64,3 +66,3 @@ if (decimal == null) { | ||
deci = deci.replace(/0+$/, ''); | ||
return `${negative}${localeInt}${deci && '.'}${deci}`; | ||
return `${negative}${localeInt.replace(/,/g, separator.slice(0, 1))}${deci && '.'}${deci}`; | ||
} | ||
@@ -79,4 +81,4 @@ | ||
const tailSection = sections.slice(1).join(''); | ||
const units = ['k', 'M', 'G', 'T', 'P']; | ||
const unit = units[sections.length - 2]; | ||
const baseUnits = ['k', 'M', 'G', 'T', 'P']; | ||
const unit = ((units && units[sections.length - 2]) || baseUnits[sections.length - 2]).slice(0, 1); | ||
space = length - negative.length - mainSection.length - 1; | ||
@@ -83,0 +85,0 @@ if (space >= 0) { |
{ | ||
"name": "number-display", | ||
"version": "2.2.3", | ||
"version": "2.3.0", | ||
"description": "Display number smartly within a certain length.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -122,5 +122,5 @@ [中文](https://github.com/entronad/number-display/blob/master/README_CN.md) | ||
( default: true ) | ||
( default: ',' ) | ||
Whether the locale string has commas ( 1,234,222 ), if there are rooms. | ||
Set the locale string separators ( 1,234,222 ), if there are rooms. Set it to null if you don't need any. Only the first char is kept. | ||
@@ -133,2 +133,8 @@ **roundingType** | ||
**units** | ||
( default: ['k', 'M', 'G', 'T', 'P'] ) | ||
The digit units to use. Only the first char is kept for each unit. If the property is set to null or too short, it will fallback to the default. | ||
## Blogs | ||
@@ -135,0 +141,0 @@ |
12350
110
142