@sb1/ffe-formatters 4.0.0 → 4.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
1
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
2
2
 
3
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
3
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
4
4
 
5
5
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
6
 
@@ -20,9 +20,10 @@ export default function formatCurrency(amount) {
20
20
 
21
21
 
22
22
  if (parseNumber(amount) % 1 !== 0) {
23
+ var decimalPostfix = ![',–', ',-'].includes(postfix) ? postfix : '';
23
24
  return "".concat(prefix).concat(formatNumber(amount, {
24
25
  decimals: 2
25
- }));
26
+ })).concat(decimalPostfix);
26
27
  }
27
28
 
28
29
  return "".concat(prefix).concat(formatNumber(amount)).concat(postfix);
@@ -1,6 +1,6 @@
1
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
1
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
2
2
 
3
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
3
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
4
4
 
5
5
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
6
 
@@ -13,9 +13,9 @@ var _unicode = require("./internal/unicode");
13
13
 
14
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
15
 
16
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
16
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
17
17
 
18
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
18
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
19
19
 
20
20
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
21
21
 
@@ -32,9 +32,10 @@ function formatCurrency(amount) {
32
32
 
33
33
 
34
34
  if ((0, _parseNumber.default)(amount) % 1 !== 0) {
35
+ var decimalPostfix = ![',–', ',-'].includes(postfix) ? postfix : '';
35
36
  return "".concat(prefix).concat((0, _formatNumber.default)(amount, {
36
37
  decimals: 2
37
- }));
38
+ })).concat(decimalPostfix);
38
39
  }
39
40
 
40
41
  return "".concat(prefix).concat((0, _formatNumber.default)(amount)).concat(postfix);
@@ -13,9 +13,9 @@ var _parseNumber = _interopRequireDefault(require("./internal/parseNumber"));
13
13
 
14
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
15
 
16
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
16
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
17
17
 
18
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
18
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
19
19
 
20
20
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
21
21
 
package/lib/index.js CHANGED
@@ -27,22 +27,22 @@ Object.defineProperty(exports, "formatDistance", {
27
27
  return _formatDistance.default;
28
28
  }
29
29
  });
30
- Object.defineProperty(exports, "formatNumber", {
30
+ Object.defineProperty(exports, "formatFodselsnummer", {
31
31
  enumerable: true,
32
32
  get: function get() {
33
- return _formatNumber.default;
33
+ return _formatFodselsnummer.default;
34
34
  }
35
35
  });
36
- Object.defineProperty(exports, "formatPercentage", {
36
+ Object.defineProperty(exports, "formatNumber", {
37
37
  enumerable: true,
38
38
  get: function get() {
39
- return _formatPercentage.default;
39
+ return _formatNumber.default;
40
40
  }
41
41
  });
42
- Object.defineProperty(exports, "formatFodselsnummer", {
42
+ Object.defineProperty(exports, "formatPercentage", {
43
43
  enumerable: true,
44
44
  get: function get() {
45
- return _formatFodselsnummer.default;
45
+ return _formatPercentage.default;
46
46
  }
47
47
  });
48
48
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sb1/ffe-formatters",
3
- "version": "4.0.0",
3
+ "version": "4.0.4",
4
4
  "description": "JavaScript general use string formatters",
5
5
  "keywords": [
6
6
  "ffe"
@@ -21,11 +21,8 @@
21
21
  "url": "ssh://git@github.com:SpareBank1/designsystem.git"
22
22
  },
23
23
  "scripts": {
24
- "build": "npm run build:cjs && npm run build:es && npm run build:types",
25
- "build:cjs": "babel -d lib/. --root-mode=upward --env-name=cjs --ignore=*.spec.js src/.",
26
- "build:es": "babel -d es/. --root-mode=upward --env-name=es --ignore=*.spec.js src/.",
27
- "build:types": "copyfiles -f src/index.d.ts types/",
28
- "lint": "eslint src/.",
24
+ "build": "ffe-buildtool babel",
25
+ "lint": "eslint src",
29
26
  "test": "jest",
30
27
  "test:watch": "jest --watch"
31
28
  },
@@ -33,11 +30,12 @@
33
30
  "underscore.string": "^3.3.4"
34
31
  },
35
32
  "devDependencies": {
33
+ "@sb1/ffe-buildtool": "^0.2.0",
36
34
  "eslint": "^5.9.0",
37
35
  "jest": "^26.0.0"
38
36
  },
39
37
  "publishConfig": {
40
38
  "access": "public"
41
39
  },
42
- "gitHead": "0e5bd1b64f9106470df0edfb6cb75ec27412f168"
40
+ "gitHead": "a5d3cae083cb82a539dd817b03814035537b2834"
43
41
  }
package/types/index.d.ts CHANGED
@@ -2,7 +2,7 @@ declare module '@sb1/ffe-formatters' {
2
2
  export function formatAccountNumber(accountNumber: string): string;
3
3
 
4
4
  export function formatCurrency(
5
- amount: string,
5
+ amount: number | string,
6
6
  opts?: { prefix?: string; postfix?: string },
7
7
  ): string;
8
8
 
package/CHANGELOG.md DELETED
@@ -1,252 +0,0 @@
1
- # Change Log
2
-
3
- All notable changes to this project will be documented in this file.
4
- See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
-
6
- # [4.0.0](https://github.com/SpareBank1/designsystem/compare/@sb1/ffe-formatters@3.1.5...@sb1/ffe-formatters@4.0.0) (2021-02-11)
7
-
8
-
9
- ### Features
10
-
11
- * **ffe-formatters:** added types ([a26264d](https://github.com/SpareBank1/designsystem/commit/a26264d1fa4e80939ed45ceccb6f4997d6ed2abb))
12
-
13
-
14
- ### BREAKING CHANGES
15
-
16
- * **ffe-formatters:** formatDate does not accept moment any more.
17
-
18
-
19
-
20
-
21
-
22
- ## [3.1.5](https://github.com/SpareBank1/designsystem/compare/@sb1/ffe-formatters@3.1.4...@sb1/ffe-formatters@3.1.5) (2021-02-02)
23
-
24
-
25
- ### Bug Fixes
26
-
27
- * packages/ffe-formatters/package.json to reduce vulnerabilities ([8b90ace](https://github.com/SpareBank1/designsystem/commit/8b90ace5def900bd093f75269f116caf4cc04db2))
28
-
29
-
30
-
31
-
32
-
33
- ## [3.1.4](https://github.com/SpareBank1/designsystem/compare/@sb1/ffe-formatters@3.1.3...@sb1/ffe-formatters@3.1.4) (2021-02-02)
34
-
35
-
36
- ### Bug Fixes
37
-
38
- * **ffe-formatters:** reduce vulnerabilities ([d07213f](https://github.com/SpareBank1/designsystem/commit/d07213fd7c223612efcec50818c14330f9726385))
39
-
40
-
41
-
42
-
43
-
44
- ## [3.1.3](https://github.com/SpareBank1/designsystem/compare/@sb1/ffe-formatters@3.1.2...@sb1/ffe-formatters@3.1.3) (2018-12-11)
45
-
46
- ### Bug Fixes
47
-
48
- - Build tree shakeable packages ([fb4a9ea](https://github.com/SpareBank1/designsystem/commit/fb4a9ea))
49
-
50
- ## [3.1.2](https://github.com/SpareBank1/designsystem/compare/@sb1/ffe-formatters@3.1.1...@sb1/ffe-formatters@3.1.2) (2018-12-06)
51
-
52
- ### Bug Fixes
53
-
54
- - **ffe-formatters:** Make sure formatters are transpiled also ([659d143](https://github.com/SpareBank1/designsystem/commit/659d143))
55
-
56
- ## [3.1.1](https://github.com/SpareBank1/designsystem/compare/@sb1/ffe-formatters@3.1.0...@sb1/ffe-formatters@3.1.1) (2018-12-04)
57
-
58
- **Note:** Version bump only for package @sb1/ffe-formatters
59
-
60
- <a name="3.1.0"></a>
61
-
62
- # [3.1.0](https://github.com/SpareBank1/designsystem/compare/@sb1/ffe-formatters@3.0.3...@sb1/ffe-formatters@3.1.0) (2018-10-02)
63
-
64
- ### Features
65
-
66
- - **ffe-formatters:** Add minDecimals option to formatPercentage. ([07cd558](https://github.com/SpareBank1/designsystem/commit/07cd558))
67
-
68
- <a name="3.0.3"></a>
69
-
70
- ## [3.0.3](https://github.com/SpareBank1/designsystem/compare/@sb1/ffe-formatters@3.0.2...@sb1/ffe-formatters@3.0.3) (2018-08-09)
71
-
72
- **Note:** Version bump only for package @sb1/ffe-formatters
73
-
74
- <a name="3.0.2"></a>
75
-
76
- ## [3.0.2](https://github.com/SpareBank1/designsystem/compare/@sb1/ffe-formatters@3.0.0...@sb1/ffe-formatters@3.0.2) (2018-03-07)
77
-
78
- **Note:** Version bump only for package @sb1/ffe-formatters
79
-
80
- <a name="3.0.1"></a>
81
-
82
- ## [3.0.1](https://github.com/SpareBank1/designsystem/compare/@sb1/ffe-formatters@3.0.0...@sb1/ffe-formatters@3.0.1) (2018-03-02)
83
-
84
- **Note:** Version bump only for package @sb1/ffe-formatters
85
-
86
- <a name="3.0.0"></a>
87
-
88
- # 3.0.0 (2018-02-25)
89
-
90
- ### Bug Fixes
91
-
92
- - remove all references to internal system ([ff22340](https://github.com/SpareBank1/designsystem/commit/ff22340))
93
-
94
- ### Chores
95
-
96
- - add [@sb1](https://github.com/sb1)/ scope to all packages ([37efbb4](https://github.com/SpareBank1/designsystem/commit/37efbb4))
97
-
98
- ### BREAKING CHANGES
99
-
100
- - All packages have been renamed to add the @sb1 scope.
101
-
102
- See links [1] and [2] to read more about package scopes.
103
-
104
- Unfortunately this requires you update both your dependencies in
105
- `package.json` and all `import` or `require` statements in your code.
106
- Also, you unfortunately have to upgrade all FFE packages at once due to
107
- dependency between packages. If you are on the latest version prior to
108
- this breaking change the upgrade should be a matter of updating
109
- `package.json` with new package names and versions, and updating your
110
- imports.
111
-
112
- To help find the proper package versions you can either browse to the
113
- packages you need or check out the list of Git tags either on
114
- Github [3] or by cloning the repository and running the `git tag`
115
- command. All package versions get a tag in the format
116
- _package@version_.
117
-
118
- Update your `package.json` with the latest package version and add the
119
- @sb1 scope to the package name:
120
-
121
- ```diff
122
- - "ffe-core": "11.0.2",
123
- + "@sb1/ffe-core": "11.0.2",
124
- ```
125
-
126
- Scoped packages all get put in a subdirectory in `node_modules/`. In our
127
- case packages will be put in the `node_modules/@sb1/` directory. If your
128
- build depends on file paths (for instance for copying fonts) you need to
129
- update that path to include the scope.
130
-
131
- The directory structure also means you have to update your imports, both
132
- in Less and in JavaScript.
133
-
134
- Using `less-plugin-npm-import`:
135
-
136
- ```diff
137
- - @import 'npm://ffe-core/less/ffe';
138
- + @import 'npm://@sb1/ffe-core/less/ffe';
139
- ```
140
-
141
- Using Webpack:
142
-
143
- ```diff
144
- - @import '~ffe-core/less/ffe';
145
- + @import '~@sb1/ffe-core/less/ffe';
146
- ```
147
-
148
- Using plain old paths:
149
-
150
- ```diff
151
- - @import '../path/to/node_modules/ffe-core/less/ffe';
152
- + @import '../path/to/node_modules/@sb1/ffe-core/less/ffe';
153
- ```
154
-
155
- JavaScript `import`:
156
-
157
- ```diff
158
- - import { ActionButton } from 'ffe-buttons-react';
159
- + import { ActionButton } from '@sb1/ffe-buttons-react';
160
- ```
161
-
162
- JavaScript `require`:
163
-
164
- ```diff
165
- - const { ActionButton } = require('ffe-buttons-react').default;
166
- + const { ActionButton } = require('@sb1/ffe-buttons-react').default;
167
- ```
168
-
169
- [1]: https://docs.npmjs.com/misc/scope
170
- [2]: https://docs.npmjs.com/getting-started/scoped-packages
171
- [3]: https://github.com/sparebank1/designsystem/tags
172
-
173
- <a name="2.1.7"></a>
174
-
175
- ## [2.1.7](https://github.com/SpareBank1/designsystem/compare/ffe-formatters@2.1.6...ffe-formatters@2.1.7) (2018-02-23)
176
-
177
- **Note:** Version bump only for package ffe-formatters
178
-
179
- <a name="2.1.6"></a>
180
-
181
- ## [2.1.6](https://github.com/SpareBank1/designsystem/compare/ffe-formatters@2.1.5...ffe-formatters@2.1.6) (2018-02-22)
182
-
183
- **Note:** Version bump only for package ffe-formatters
184
-
185
- <a name="2.1.5"></a>
186
-
187
- ## [2.1.5](https://github.com/SpareBank1/designsystem/compare/ffe-formatters@2.1.4...ffe-formatters@2.1.5) (2018-01-31)
188
-
189
- **Note:** Version bump only for package ffe-formatters
190
-
191
- <a name="2.1.4"></a>
192
-
193
- ## [2.1.4](https://github.com/SpareBank1/designsystem/compare/ffe-formatters@2.1.3...ffe-formatters@2.1.4) (2018-01-22)
194
-
195
- **Note:** Version bump only for package ffe-formatters
196
-
197
- <a name="2.1.3"></a>
198
-
199
- ## [2.1.3](https://github.com/SpareBank1/designsystem/compare/ffe-formatters@2.1.2...ffe-formatters@2.1.3) (2018-01-19)
200
-
201
- **Note:** Version bump only for package ffe-formatters
202
-
203
- <a name="2.1.2"></a>
204
-
205
- ## [2.1.2](https://github.com/SpareBank1/designsystem/compare/ffe-formatters@2.1.1...ffe-formatters@2.1.2) (2018-01-18)
206
-
207
- **Note:** Version bump only for package ffe-formatters
208
-
209
- <a name="2.1.1"></a>
210
-
211
- ## 2.1.1 (2018-01-16)
212
-
213
- **Note:** Version bump only for package ffe-formatters
214
-
215
- # 2.1.0
216
-
217
- - `formatNumber` now accepts additional props to the `opts`-argument. - `thousandSeparator` (defaults to NON_BREAKING_SPACE) - `decimalMark` (defaults to ',')
218
-
219
- ## 2.0.4
220
-
221
- - Bugfix: Fixed a bug where - `formatNumber(0)` returns 0, (expected: '0') - `formatNumber(0, { decimals: 2 })` returns 0, (expected: '0,00')
222
-
223
- ## 2.0.3
224
-
225
- - `formatDistance` no longer returns the empty string if the input is equal to
226
- the result of `formatNumber(input)` (solves part of SFO-6995)
227
-
228
- ## 2.0.2
229
-
230
- - Bugfix: Include correct files in NPM package.
231
-
232
- ## 2.0.1
233
-
234
- - Bugfix: Fix broken export of `formatFodselsnummer` from the main index file.
235
-
236
- # 2.0.0
237
-
238
- **BREAKING:** `formatPercentage` now expects the actual percentage instead of the fraction.
239
- Previously: `formatPercentage(0.123) === 12.3 %`, now: `formatPercentage(0.123) === 0.12 %`.
240
- To migrate, just make sure the value you send in is in the correct order of magnitude.
241
-
242
- # 1.0.0
243
-
244
- Initial version of `ffe-formatters`. Includes the following formatters:
245
-
246
- - formatAccountNumber
247
- - formatCurrency
248
- - formatDate
249
- - formatFodselsnummer
250
- - formatKm
251
- - formatNumber
252
- - formatPercentage
@@ -1,19 +0,0 @@
1
- import formatAccountNumber from './formatAccountNumber';
2
- import { NON_BREAKING_SPACE } from './internal/unicode';
3
- describe('format account number', function () {
4
- test('returns input when account number is undefined', function () {
5
- expect(formatAccountNumber(undefined)).toBe(undefined);
6
- });
7
- test('returns input when account number is null', function () {
8
- expect(formatAccountNumber(null)).toBe(null);
9
- });
10
- test('returns input when account number is empty', function () {
11
- expect(formatAccountNumber('')).toBe('');
12
- });
13
- test('returns input when account number length is not 11', function () {
14
- expect(formatAccountNumber('1234567890')).toBe('1234567890');
15
- });
16
- test('formats account number correctly', function () {
17
- expect(formatAccountNumber('12345678901')).toBe("1234".concat(NON_BREAKING_SPACE, "56").concat(NON_BREAKING_SPACE, "78901"));
18
- });
19
- });
@@ -1,24 +0,0 @@
1
- import { NON_BREAKING_SPACE } from './internal/unicode';
2
- import formatCurrency from './formatCurrency';
3
- describe('format currency', function () {
4
- test('does not show decimals for whole moneys', function () {
5
- expect(formatCurrency('999.00')).toBe("kr".concat(NON_BREAKING_SPACE, "999,\u2013"));
6
- expect(formatCurrency('1234')).toBe("kr".concat(NON_BREAKING_SPACE, "1").concat(NON_BREAKING_SPACE, "234,\u2013"));
7
- });
8
- test('show decimals for moneys which are not whole', function () {
9
- expect(formatCurrency('999.99')).toBe("kr".concat(NON_BREAKING_SPACE, "999,99"));
10
- expect(formatCurrency('1234.90')).toBe("kr".concat(NON_BREAKING_SPACE, "1").concat(NON_BREAKING_SPACE, "234,90"));
11
- });
12
- test('allows overrides of post and prefix', function () {
13
- expect(formatCurrency('1234.10', {
14
- prefix: ''
15
- })).toBe("1".concat(NON_BREAKING_SPACE, "234,10"));
16
- expect(formatCurrency('1234', {
17
- postfix: ''
18
- })).toBe("kr".concat(NON_BREAKING_SPACE, "1").concat(NON_BREAKING_SPACE, "234"));
19
- expect(formatCurrency('1234', {
20
- prefix: '',
21
- postfix: ''
22
- })).toBe("1".concat(NON_BREAKING_SPACE, "234"));
23
- });
24
- });
@@ -1,12 +0,0 @@
1
- import formatDate from './formatDate';
2
- describe('format date ', function () {
3
- it('in milliseconds', function () {
4
- expect(formatDate(1514808000000)).toBe('01.01.2018');
5
- });
6
- it('in javascript date format', function () {
7
- expect(formatDate(new Date(2016, 6, 6))).toBe('06.07.2016');
8
- });
9
- it('returns null when input is string', function () {
10
- expect(formatDate('06.07.2016')).toBe(null);
11
- });
12
- });
@@ -1,43 +0,0 @@
1
- import { NON_BREAKING_SPACE as nbsp } from './internal/unicode';
2
- import formatDistance from './formatDistance';
3
- describe('format distance', function () {
4
- test('formats distance with spaces between thousands', function () {
5
- expect(formatDistance(10)).toBe("10".concat(nbsp, "km"));
6
- expect(formatDistance(1000)).toBe("1".concat(nbsp, "000").concat(nbsp, "km"));
7
- });
8
- test('handles numeric strings where the result from formatNumber equals the input (<1000)', function () {
9
- expect(formatDistance('9')).toBe("9".concat(nbsp, "km"));
10
- expect(formatDistance('99')).toBe("99".concat(nbsp, "km"));
11
- expect(formatDistance('999')).toBe("999".concat(nbsp, "km"));
12
- });
13
- test('formats distance with spaces between thousands using string as input', function () {
14
- expect(formatDistance('1000')).toBe("1".concat(nbsp, "000").concat(nbsp, "km"));
15
- expect(formatDistance('1 000')).toBe("1".concat(nbsp, "000").concat(nbsp, "km"));
16
- });
17
- test('formats distance without decimals even if input has them', function () {
18
- expect(formatDistance(10.5)).toBe("11".concat(nbsp, "km"));
19
- expect(formatDistance('10.5')).toBe("11".concat(nbsp, "km"));
20
- });
21
- test('formats distance for input 0', function () {
22
- expect(formatDistance(0)).toBe("0".concat(nbsp, "km"));
23
- });
24
- test('returns an empty string for falsy inut values other than 0', function () {
25
- expect(formatDistance('')).toBe('');
26
- expect(formatDistance('hodor')).toBe('');
27
- expect(formatDistance(false)).toBe('');
28
- expect(formatDistance(NaN)).toBe('');
29
- expect(formatDistance(undefined)).toBe('');
30
- expect(formatDistance(null)).toBe('');
31
- });
32
- test('returns an empty string for non-numeric non-parseable inputs (objects, arrays)', function () {
33
- expect(formatDistance({
34
- hurr: 4
35
- })).toBe('');
36
- expect(formatDistance([4, 5])).toBe('');
37
- });
38
- test('returns the unit specified in options', function () {
39
- expect(formatDistance(100000, {
40
- unit: 'mi'
41
- })).toBe("100".concat(nbsp, "000").concat(nbsp, "mi"));
42
- });
43
- });
@@ -1,19 +0,0 @@
1
- import formatFodselsnummer from './formatFodselsnummer';
2
- import { NON_BREAKING_SPACE } from './internal/unicode';
3
- describe('formatFodselsnummer', function () {
4
- test('returns input when ssn is undefined', function () {
5
- expect(formatFodselsnummer(undefined)).toBe(undefined);
6
- });
7
- test('returns input when ssn is null', function () {
8
- expect(formatFodselsnummer(null)).toBe(null);
9
- });
10
- test('returns input when ssn is empty', function () {
11
- expect(formatFodselsnummer('')).toBe('');
12
- });
13
- test('returns input when ssn length is not 11', function () {
14
- expect(formatFodselsnummer('1234567890')).toBe('1234567890');
15
- });
16
- test('formats ssn correctly', function () {
17
- expect(formatFodselsnummer('12345678901')).toBe("123456".concat(NON_BREAKING_SPACE, "78901"));
18
- });
19
- });
@@ -1,115 +0,0 @@
1
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
2
-
3
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
4
-
5
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
-
7
- import formatNumber from './formatNumber';
8
- describe('formatNumber with default options', function () {
9
- test('noops on falsy values', function () {
10
- expect(formatNumber(null)).toBe(null);
11
- expect(formatNumber(undefined)).toBe(undefined);
12
- expect(formatNumber(false)).toBe(false);
13
- });
14
- test('noops on non-numeric strings', function () {
15
- expect(formatNumber('invalid')).toBe('invalid');
16
- });
17
- test('noops on arrays and objects', function () {
18
- expect(formatNumber(['invalid'])).toEqual(['invalid']);
19
- expect(formatNumber({
20
- invalid: true
21
- })).toEqual({
22
- invalid: true
23
- });
24
- });
25
- test('formats regular numbers', function () {
26
- expect(formatNumber(123)).toBe('123');
27
- expect(formatNumber(123456)).toBe('123 456');
28
- });
29
- test('formats negative numbers', function () {
30
- expect(formatNumber(-123)).toBe('-123');
31
- expect(formatNumber(-123456)).toBe('-123 456');
32
- });
33
- test('ignores decimal numbers by default', function () {
34
- expect(formatNumber(1234.5)).toBe('1 235');
35
- });
36
- test('format 0 without decimal numbers', function () {
37
- expect(formatNumber(0)).toBe('0');
38
- });
39
- test('format numeric strings', function () {
40
- expect(formatNumber('1234')).toBe('1 234');
41
- expect(formatNumber('-1234567')).toBe('-1 234 567');
42
- });
43
- });
44
- describe('formatNumber with options', function () {
45
- var opts = {
46
- thousandSeparator: ',',
47
- decimalMark: '.'
48
- };
49
- test('include decimal numbers if specified', function () {
50
- expect(formatNumber(1234.4, {
51
- decimals: 1
52
- })).toBe('1 234,4');
53
- expect(formatNumber(1234.4, {
54
- decimals: 2
55
- })).toBe('1 234,40');
56
- });
57
- test('format 0 with decimal numbers if specified', function () {
58
- expect(formatNumber(0, {
59
- decimals: 1
60
- })).toBe('0,0');
61
- expect(formatNumber(0, {
62
- decimals: 2
63
- })).toBe('0,00');
64
- });
65
- test('noops on falsy values', function () {
66
- expect(formatNumber(null, opts)).toBe(null);
67
- expect(formatNumber(undefined, opts)).toBe(undefined);
68
- expect(formatNumber(false, opts)).toBe(false);
69
- });
70
- test('noops on non-numeric strings', function () {
71
- expect(formatNumber('invalid', opts)).toBe('invalid');
72
- });
73
- test('noops on arrays and objects', function () {
74
- expect(formatNumber(['invalid'], opts)).toEqual(['invalid']);
75
- expect(formatNumber({
76
- invalid: true
77
- }, opts)).toEqual({
78
- invalid: true
79
- });
80
- });
81
- test('formats regular numbers', function () {
82
- expect(formatNumber(123, opts)).toBe('123');
83
- expect(formatNumber(123456, opts)).toBe('123,456');
84
- });
85
- test('formats negative numbers', function () {
86
- expect(formatNumber(-123, opts)).toBe('-123');
87
- expect(formatNumber(-123456, opts)).toBe('-123,456');
88
- });
89
- test('ignores decimal numbers by default', function () {
90
- expect(formatNumber(1234.5, opts)).toBe('1,235');
91
- });
92
- test('include decimal numbers if specified', function () {
93
- expect(formatNumber(1234.4, _objectSpread({
94
- decimals: 1
95
- }, opts))).toBe('1,234.4');
96
- expect(formatNumber(1234.4, _objectSpread({
97
- decimals: 2
98
- }, opts))).toBe('1,234.40');
99
- });
100
- test('format 0 without decimal numbers', function () {
101
- expect(formatNumber(0, opts)).toBe('0');
102
- });
103
- test('format 0 with decimal numbers if specified', function () {
104
- expect(formatNumber(0, _objectSpread({
105
- decimals: 1
106
- }, opts))).toBe('0.0');
107
- expect(formatNumber(0, _objectSpread({
108
- decimals: 2
109
- }, opts))).toBe('0.00');
110
- });
111
- test('format numeric strings', function () {
112
- expect(formatNumber('1234', opts)).toBe('1,234');
113
- expect(formatNumber('-1234567', opts)).toBe('-1,234,567');
114
- });
115
- });
@@ -1,53 +0,0 @@
1
- import { NON_BREAKING_SPACE } from './internal/unicode';
2
- import formatPercentage from './formatPercentage';
3
- describe('format percentage', function () {
4
- test('returns empty string non-number values', function () {
5
- expect(formatPercentage(null)).toBe('');
6
- expect(formatPercentage(undefined)).toBe('');
7
- expect(formatPercentage(false)).toBe('');
8
- expect(formatPercentage(true)).toBe('');
9
- expect(formatPercentage('invalid')).toBe('');
10
- expect(formatPercentage(['invalid'])).toBe('');
11
- expect(formatPercentage({
12
- invalid: true
13
- })).toBe('');
14
- });
15
- test('formats numbers as percentages', function () {
16
- expect(formatPercentage(30)).toBe("30".concat(NON_BREAKING_SPACE, "%"));
17
- expect(formatPercentage(125)).toBe("125".concat(NON_BREAKING_SPACE, "%"));
18
- });
19
- test('returns a maximum of 2 decimals by default', function () {
20
- expect(formatPercentage(11)).toBe("11".concat(NON_BREAKING_SPACE, "%"));
21
- expect(formatPercentage(11.1)).toBe("11,1".concat(NON_BREAKING_SPACE, "%"));
22
- expect(formatPercentage(11.11111111)).toBe("11,11".concat(NON_BREAKING_SPACE, "%"));
23
- });
24
- test('lets you specify number of maximum decimals', function () {
25
- expect(formatPercentage(10.10101, {
26
- maxDecimals: 4
27
- })).toBe("10,101".concat(NON_BREAKING_SPACE, "%"));
28
- expect(formatPercentage(12.3456, {
29
- maxDecimals: 1
30
- })).toBe("12,3".concat(NON_BREAKING_SPACE, "%"));
31
- });
32
- test('rounds numbers correctly', function () {
33
- expect(formatPercentage(54.545)).toBe("54,55".concat(NON_BREAKING_SPACE, "%"));
34
- expect(formatPercentage(54.544)).toBe("54,54".concat(NON_BREAKING_SPACE, "%"));
35
- });
36
- test('formats negative numbers with prefix', function () {
37
- var HYPHEN_MINUS = String.fromCharCode(45);
38
- var MINUS_SIGN = String.fromCharCode(8722);
39
- var ANY_MINUS_SIGN = "(".concat(HYPHEN_MINUS, "|").concat(MINUS_SIGN, ")");
40
- expect(formatPercentage(-73.2)).toMatch(new RegExp("^".concat(ANY_MINUS_SIGN, "73,2").concat(NON_BREAKING_SPACE, "%$")));
41
- expect(formatPercentage(-98.7654321, {
42
- maxDecimals: 3
43
- })).toMatch(new RegExp("^".concat(ANY_MINUS_SIGN, "98,765").concat(NON_BREAKING_SPACE, "%$")));
44
- });
45
- test('lets you specify minimum number of decimals', function () {
46
- expect(formatPercentage(1, {
47
- minDecimals: 2
48
- })).toBe("1,00".concat(NON_BREAKING_SPACE, "%"));
49
- expect(formatPercentage(3.2, {
50
- minDecimals: 2
51
- })).toBe("3,20".concat(NON_BREAKING_SPACE, "%"));
52
- });
53
- });
@@ -1,30 +0,0 @@
1
- import parseNumber from './parseNumber';
2
- describe('parseNumber', function () {
3
- test('noops on non-string arguments', function () {
4
- expect(parseNumber(null)).toBe(null);
5
- expect(parseNumber(undefined)).toBe(undefined);
6
- expect(parseNumber(false)).toBe(false);
7
- expect(parseNumber('')).toBe('');
8
- });
9
- test('parses regular numeric strings', function () {
10
- expect(parseNumber('123')).toBe(123);
11
- expect(parseNumber('0')).toBe(0);
12
- expect(parseNumber('000123456')).toBe(123456);
13
- });
14
- test('parses negative numbers', function () {
15
- expect(parseNumber('-1')).toBe(-1);
16
- expect(parseNumber('-123456')).toBe(-123456);
17
- });
18
- test('parses leading-zeroes strings as numbers', function () {
19
- expect(parseNumber('000123456')).toBe(123456);
20
- });
21
- test('parses formatted numeric strings', function () {
22
- expect(parseNumber('1 234 567')).toBe(1234567);
23
- expect(parseNumber('-1 234 567')).toBe(-1234567);
24
- expect(parseNumber('0,235')).toBe(0.235);
25
- });
26
- test('parses numeric strings with prefixes etc', function () {
27
- expect(parseNumber('kr 1 234')).toBe(1234);
28
- expect(parseNumber('1 tusenlapp og 234 kroner')).toBe(1234);
29
- });
30
- });
@@ -1,25 +0,0 @@
1
- "use strict";
2
-
3
- var _formatAccountNumber = _interopRequireDefault(require("./formatAccountNumber"));
4
-
5
- var _unicode = require("./internal/unicode");
6
-
7
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
8
-
9
- describe('format account number', function () {
10
- test('returns input when account number is undefined', function () {
11
- expect((0, _formatAccountNumber.default)(undefined)).toBe(undefined);
12
- });
13
- test('returns input when account number is null', function () {
14
- expect((0, _formatAccountNumber.default)(null)).toBe(null);
15
- });
16
- test('returns input when account number is empty', function () {
17
- expect((0, _formatAccountNumber.default)('')).toBe('');
18
- });
19
- test('returns input when account number length is not 11', function () {
20
- expect((0, _formatAccountNumber.default)('1234567890')).toBe('1234567890');
21
- });
22
- test('formats account number correctly', function () {
23
- expect((0, _formatAccountNumber.default)('12345678901')).toBe("1234".concat(_unicode.NON_BREAKING_SPACE, "56").concat(_unicode.NON_BREAKING_SPACE, "78901"));
24
- });
25
- });
@@ -1,30 +0,0 @@
1
- "use strict";
2
-
3
- var _unicode = require("./internal/unicode");
4
-
5
- var _formatCurrency = _interopRequireDefault(require("./formatCurrency"));
6
-
7
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
8
-
9
- describe('format currency', function () {
10
- test('does not show decimals for whole moneys', function () {
11
- expect((0, _formatCurrency.default)('999.00')).toBe("kr".concat(_unicode.NON_BREAKING_SPACE, "999,\u2013"));
12
- expect((0, _formatCurrency.default)('1234')).toBe("kr".concat(_unicode.NON_BREAKING_SPACE, "1").concat(_unicode.NON_BREAKING_SPACE, "234,\u2013"));
13
- });
14
- test('show decimals for moneys which are not whole', function () {
15
- expect((0, _formatCurrency.default)('999.99')).toBe("kr".concat(_unicode.NON_BREAKING_SPACE, "999,99"));
16
- expect((0, _formatCurrency.default)('1234.90')).toBe("kr".concat(_unicode.NON_BREAKING_SPACE, "1").concat(_unicode.NON_BREAKING_SPACE, "234,90"));
17
- });
18
- test('allows overrides of post and prefix', function () {
19
- expect((0, _formatCurrency.default)('1234.10', {
20
- prefix: ''
21
- })).toBe("1".concat(_unicode.NON_BREAKING_SPACE, "234,10"));
22
- expect((0, _formatCurrency.default)('1234', {
23
- postfix: ''
24
- })).toBe("kr".concat(_unicode.NON_BREAKING_SPACE, "1").concat(_unicode.NON_BREAKING_SPACE, "234"));
25
- expect((0, _formatCurrency.default)('1234', {
26
- prefix: '',
27
- postfix: ''
28
- })).toBe("1".concat(_unicode.NON_BREAKING_SPACE, "234"));
29
- });
30
- });
@@ -1,17 +0,0 @@
1
- "use strict";
2
-
3
- var _formatDate = _interopRequireDefault(require("./formatDate"));
4
-
5
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
6
-
7
- describe('format date ', function () {
8
- it('in milliseconds', function () {
9
- expect((0, _formatDate.default)(1514808000000)).toBe('01.01.2018');
10
- });
11
- it('in javascript date format', function () {
12
- expect((0, _formatDate.default)(new Date(2016, 6, 6))).toBe('06.07.2016');
13
- });
14
- it('returns null when input is string', function () {
15
- expect((0, _formatDate.default)('06.07.2016')).toBe(null);
16
- });
17
- });
@@ -1,49 +0,0 @@
1
- "use strict";
2
-
3
- var _unicode = require("./internal/unicode");
4
-
5
- var _formatDistance = _interopRequireDefault(require("./formatDistance"));
6
-
7
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
8
-
9
- describe('format distance', function () {
10
- test('formats distance with spaces between thousands', function () {
11
- expect((0, _formatDistance.default)(10)).toBe("10".concat(_unicode.NON_BREAKING_SPACE, "km"));
12
- expect((0, _formatDistance.default)(1000)).toBe("1".concat(_unicode.NON_BREAKING_SPACE, "000").concat(_unicode.NON_BREAKING_SPACE, "km"));
13
- });
14
- test('handles numeric strings where the result from formatNumber equals the input (<1000)', function () {
15
- expect((0, _formatDistance.default)('9')).toBe("9".concat(_unicode.NON_BREAKING_SPACE, "km"));
16
- expect((0, _formatDistance.default)('99')).toBe("99".concat(_unicode.NON_BREAKING_SPACE, "km"));
17
- expect((0, _formatDistance.default)('999')).toBe("999".concat(_unicode.NON_BREAKING_SPACE, "km"));
18
- });
19
- test('formats distance with spaces between thousands using string as input', function () {
20
- expect((0, _formatDistance.default)('1000')).toBe("1".concat(_unicode.NON_BREAKING_SPACE, "000").concat(_unicode.NON_BREAKING_SPACE, "km"));
21
- expect((0, _formatDistance.default)('1 000')).toBe("1".concat(_unicode.NON_BREAKING_SPACE, "000").concat(_unicode.NON_BREAKING_SPACE, "km"));
22
- });
23
- test('formats distance without decimals even if input has them', function () {
24
- expect((0, _formatDistance.default)(10.5)).toBe("11".concat(_unicode.NON_BREAKING_SPACE, "km"));
25
- expect((0, _formatDistance.default)('10.5')).toBe("11".concat(_unicode.NON_BREAKING_SPACE, "km"));
26
- });
27
- test('formats distance for input 0', function () {
28
- expect((0, _formatDistance.default)(0)).toBe("0".concat(_unicode.NON_BREAKING_SPACE, "km"));
29
- });
30
- test('returns an empty string for falsy inut values other than 0', function () {
31
- expect((0, _formatDistance.default)('')).toBe('');
32
- expect((0, _formatDistance.default)('hodor')).toBe('');
33
- expect((0, _formatDistance.default)(false)).toBe('');
34
- expect((0, _formatDistance.default)(NaN)).toBe('');
35
- expect((0, _formatDistance.default)(undefined)).toBe('');
36
- expect((0, _formatDistance.default)(null)).toBe('');
37
- });
38
- test('returns an empty string for non-numeric non-parseable inputs (objects, arrays)', function () {
39
- expect((0, _formatDistance.default)({
40
- hurr: 4
41
- })).toBe('');
42
- expect((0, _formatDistance.default)([4, 5])).toBe('');
43
- });
44
- test('returns the unit specified in options', function () {
45
- expect((0, _formatDistance.default)(100000, {
46
- unit: 'mi'
47
- })).toBe("100".concat(_unicode.NON_BREAKING_SPACE, "000").concat(_unicode.NON_BREAKING_SPACE, "mi"));
48
- });
49
- });
@@ -1,25 +0,0 @@
1
- "use strict";
2
-
3
- var _formatFodselsnummer = _interopRequireDefault(require("./formatFodselsnummer"));
4
-
5
- var _unicode = require("./internal/unicode");
6
-
7
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
8
-
9
- describe('formatFodselsnummer', function () {
10
- test('returns input when ssn is undefined', function () {
11
- expect((0, _formatFodselsnummer.default)(undefined)).toBe(undefined);
12
- });
13
- test('returns input when ssn is null', function () {
14
- expect((0, _formatFodselsnummer.default)(null)).toBe(null);
15
- });
16
- test('returns input when ssn is empty', function () {
17
- expect((0, _formatFodselsnummer.default)('')).toBe('');
18
- });
19
- test('returns input when ssn length is not 11', function () {
20
- expect((0, _formatFodselsnummer.default)('1234567890')).toBe('1234567890');
21
- });
22
- test('formats ssn correctly', function () {
23
- expect((0, _formatFodselsnummer.default)('12345678901')).toBe("123456".concat(_unicode.NON_BREAKING_SPACE, "78901"));
24
- });
25
- });
@@ -1,120 +0,0 @@
1
- "use strict";
2
-
3
- var _formatNumber = _interopRequireDefault(require("./formatNumber"));
4
-
5
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
6
-
7
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
8
-
9
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
10
-
11
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
12
-
13
- describe('formatNumber with default options', function () {
14
- test('noops on falsy values', function () {
15
- expect((0, _formatNumber.default)(null)).toBe(null);
16
- expect((0, _formatNumber.default)(undefined)).toBe(undefined);
17
- expect((0, _formatNumber.default)(false)).toBe(false);
18
- });
19
- test('noops on non-numeric strings', function () {
20
- expect((0, _formatNumber.default)('invalid')).toBe('invalid');
21
- });
22
- test('noops on arrays and objects', function () {
23
- expect((0, _formatNumber.default)(['invalid'])).toEqual(['invalid']);
24
- expect((0, _formatNumber.default)({
25
- invalid: true
26
- })).toEqual({
27
- invalid: true
28
- });
29
- });
30
- test('formats regular numbers', function () {
31
- expect((0, _formatNumber.default)(123)).toBe('123');
32
- expect((0, _formatNumber.default)(123456)).toBe('123 456');
33
- });
34
- test('formats negative numbers', function () {
35
- expect((0, _formatNumber.default)(-123)).toBe('-123');
36
- expect((0, _formatNumber.default)(-123456)).toBe('-123 456');
37
- });
38
- test('ignores decimal numbers by default', function () {
39
- expect((0, _formatNumber.default)(1234.5)).toBe('1 235');
40
- });
41
- test('format 0 without decimal numbers', function () {
42
- expect((0, _formatNumber.default)(0)).toBe('0');
43
- });
44
- test('format numeric strings', function () {
45
- expect((0, _formatNumber.default)('1234')).toBe('1 234');
46
- expect((0, _formatNumber.default)('-1234567')).toBe('-1 234 567');
47
- });
48
- });
49
- describe('formatNumber with options', function () {
50
- var opts = {
51
- thousandSeparator: ',',
52
- decimalMark: '.'
53
- };
54
- test('include decimal numbers if specified', function () {
55
- expect((0, _formatNumber.default)(1234.4, {
56
- decimals: 1
57
- })).toBe('1 234,4');
58
- expect((0, _formatNumber.default)(1234.4, {
59
- decimals: 2
60
- })).toBe('1 234,40');
61
- });
62
- test('format 0 with decimal numbers if specified', function () {
63
- expect((0, _formatNumber.default)(0, {
64
- decimals: 1
65
- })).toBe('0,0');
66
- expect((0, _formatNumber.default)(0, {
67
- decimals: 2
68
- })).toBe('0,00');
69
- });
70
- test('noops on falsy values', function () {
71
- expect((0, _formatNumber.default)(null, opts)).toBe(null);
72
- expect((0, _formatNumber.default)(undefined, opts)).toBe(undefined);
73
- expect((0, _formatNumber.default)(false, opts)).toBe(false);
74
- });
75
- test('noops on non-numeric strings', function () {
76
- expect((0, _formatNumber.default)('invalid', opts)).toBe('invalid');
77
- });
78
- test('noops on arrays and objects', function () {
79
- expect((0, _formatNumber.default)(['invalid'], opts)).toEqual(['invalid']);
80
- expect((0, _formatNumber.default)({
81
- invalid: true
82
- }, opts)).toEqual({
83
- invalid: true
84
- });
85
- });
86
- test('formats regular numbers', function () {
87
- expect((0, _formatNumber.default)(123, opts)).toBe('123');
88
- expect((0, _formatNumber.default)(123456, opts)).toBe('123,456');
89
- });
90
- test('formats negative numbers', function () {
91
- expect((0, _formatNumber.default)(-123, opts)).toBe('-123');
92
- expect((0, _formatNumber.default)(-123456, opts)).toBe('-123,456');
93
- });
94
- test('ignores decimal numbers by default', function () {
95
- expect((0, _formatNumber.default)(1234.5, opts)).toBe('1,235');
96
- });
97
- test('include decimal numbers if specified', function () {
98
- expect((0, _formatNumber.default)(1234.4, _objectSpread({
99
- decimals: 1
100
- }, opts))).toBe('1,234.4');
101
- expect((0, _formatNumber.default)(1234.4, _objectSpread({
102
- decimals: 2
103
- }, opts))).toBe('1,234.40');
104
- });
105
- test('format 0 without decimal numbers', function () {
106
- expect((0, _formatNumber.default)(0, opts)).toBe('0');
107
- });
108
- test('format 0 with decimal numbers if specified', function () {
109
- expect((0, _formatNumber.default)(0, _objectSpread({
110
- decimals: 1
111
- }, opts))).toBe('0.0');
112
- expect((0, _formatNumber.default)(0, _objectSpread({
113
- decimals: 2
114
- }, opts))).toBe('0.00');
115
- });
116
- test('format numeric strings', function () {
117
- expect((0, _formatNumber.default)('1234', opts)).toBe('1,234');
118
- expect((0, _formatNumber.default)('-1234567', opts)).toBe('-1,234,567');
119
- });
120
- });
@@ -1,59 +0,0 @@
1
- "use strict";
2
-
3
- var _unicode = require("./internal/unicode");
4
-
5
- var _formatPercentage = _interopRequireDefault(require("./formatPercentage"));
6
-
7
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
8
-
9
- describe('format percentage', function () {
10
- test('returns empty string non-number values', function () {
11
- expect((0, _formatPercentage.default)(null)).toBe('');
12
- expect((0, _formatPercentage.default)(undefined)).toBe('');
13
- expect((0, _formatPercentage.default)(false)).toBe('');
14
- expect((0, _formatPercentage.default)(true)).toBe('');
15
- expect((0, _formatPercentage.default)('invalid')).toBe('');
16
- expect((0, _formatPercentage.default)(['invalid'])).toBe('');
17
- expect((0, _formatPercentage.default)({
18
- invalid: true
19
- })).toBe('');
20
- });
21
- test('formats numbers as percentages', function () {
22
- expect((0, _formatPercentage.default)(30)).toBe("30".concat(_unicode.NON_BREAKING_SPACE, "%"));
23
- expect((0, _formatPercentage.default)(125)).toBe("125".concat(_unicode.NON_BREAKING_SPACE, "%"));
24
- });
25
- test('returns a maximum of 2 decimals by default', function () {
26
- expect((0, _formatPercentage.default)(11)).toBe("11".concat(_unicode.NON_BREAKING_SPACE, "%"));
27
- expect((0, _formatPercentage.default)(11.1)).toBe("11,1".concat(_unicode.NON_BREAKING_SPACE, "%"));
28
- expect((0, _formatPercentage.default)(11.11111111)).toBe("11,11".concat(_unicode.NON_BREAKING_SPACE, "%"));
29
- });
30
- test('lets you specify number of maximum decimals', function () {
31
- expect((0, _formatPercentage.default)(10.10101, {
32
- maxDecimals: 4
33
- })).toBe("10,101".concat(_unicode.NON_BREAKING_SPACE, "%"));
34
- expect((0, _formatPercentage.default)(12.3456, {
35
- maxDecimals: 1
36
- })).toBe("12,3".concat(_unicode.NON_BREAKING_SPACE, "%"));
37
- });
38
- test('rounds numbers correctly', function () {
39
- expect((0, _formatPercentage.default)(54.545)).toBe("54,55".concat(_unicode.NON_BREAKING_SPACE, "%"));
40
- expect((0, _formatPercentage.default)(54.544)).toBe("54,54".concat(_unicode.NON_BREAKING_SPACE, "%"));
41
- });
42
- test('formats negative numbers with prefix', function () {
43
- var HYPHEN_MINUS = String.fromCharCode(45);
44
- var MINUS_SIGN = String.fromCharCode(8722);
45
- var ANY_MINUS_SIGN = "(".concat(HYPHEN_MINUS, "|").concat(MINUS_SIGN, ")");
46
- expect((0, _formatPercentage.default)(-73.2)).toMatch(new RegExp("^".concat(ANY_MINUS_SIGN, "73,2").concat(_unicode.NON_BREAKING_SPACE, "%$")));
47
- expect((0, _formatPercentage.default)(-98.7654321, {
48
- maxDecimals: 3
49
- })).toMatch(new RegExp("^".concat(ANY_MINUS_SIGN, "98,765").concat(_unicode.NON_BREAKING_SPACE, "%$")));
50
- });
51
- test('lets you specify minimum number of decimals', function () {
52
- expect((0, _formatPercentage.default)(1, {
53
- minDecimals: 2
54
- })).toBe("1,00".concat(_unicode.NON_BREAKING_SPACE, "%"));
55
- expect((0, _formatPercentage.default)(3.2, {
56
- minDecimals: 2
57
- })).toBe("3,20".concat(_unicode.NON_BREAKING_SPACE, "%"));
58
- });
59
- });
@@ -1,35 +0,0 @@
1
- "use strict";
2
-
3
- var _parseNumber = _interopRequireDefault(require("./parseNumber"));
4
-
5
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
6
-
7
- describe('parseNumber', function () {
8
- test('noops on non-string arguments', function () {
9
- expect((0, _parseNumber.default)(null)).toBe(null);
10
- expect((0, _parseNumber.default)(undefined)).toBe(undefined);
11
- expect((0, _parseNumber.default)(false)).toBe(false);
12
- expect((0, _parseNumber.default)('')).toBe('');
13
- });
14
- test('parses regular numeric strings', function () {
15
- expect((0, _parseNumber.default)('123')).toBe(123);
16
- expect((0, _parseNumber.default)('0')).toBe(0);
17
- expect((0, _parseNumber.default)('000123456')).toBe(123456);
18
- });
19
- test('parses negative numbers', function () {
20
- expect((0, _parseNumber.default)('-1')).toBe(-1);
21
- expect((0, _parseNumber.default)('-123456')).toBe(-123456);
22
- });
23
- test('parses leading-zeroes strings as numbers', function () {
24
- expect((0, _parseNumber.default)('000123456')).toBe(123456);
25
- });
26
- test('parses formatted numeric strings', function () {
27
- expect((0, _parseNumber.default)('1 234 567')).toBe(1234567);
28
- expect((0, _parseNumber.default)('-1 234 567')).toBe(-1234567);
29
- expect((0, _parseNumber.default)('0,235')).toBe(0.235);
30
- });
31
- test('parses numeric strings with prefixes etc', function () {
32
- expect((0, _parseNumber.default)('kr 1 234')).toBe(1234);
33
- expect((0, _parseNumber.default)('1 tusenlapp og 234 kroner')).toBe(1234);
34
- });
35
- });