@sb1/ffe-formatters 3.1.5 → 4.0.3

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
 
package/es/formatDate.js CHANGED
@@ -3,16 +3,10 @@ var ensureTwoDigits = function ensureTwoDigits(d) {
3
3
  };
4
4
 
5
5
  export default function formatDate(timestamp) {
6
- var isMoment = timestamp && timestamp._isAMomentObject;
7
-
8
- if (!(Number.isInteger(timestamp) || timestamp instanceof Date || isMoment)) {
6
+ if (!(Number.isInteger(timestamp) || timestamp instanceof Date)) {
9
7
  return null;
10
8
  }
11
9
 
12
- if (isMoment) {
13
- return timestamp.format('DD.MM.YYYY');
14
- }
15
-
16
10
  var date = timestamp instanceof Date ? timestamp : new Date(timestamp);
17
11
  var dd = ensureTwoDigits(date.getDate());
18
12
  var mm = ensureTwoDigits(date.getMonth() + 1);
@@ -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
 
package/lib/formatDate.js CHANGED
@@ -10,16 +10,10 @@ var ensureTwoDigits = function ensureTwoDigits(d) {
10
10
  };
11
11
 
12
12
  function formatDate(timestamp) {
13
- var isMoment = timestamp && timestamp._isAMomentObject;
14
-
15
- if (!(Number.isInteger(timestamp) || timestamp instanceof Date || isMoment)) {
13
+ if (!(Number.isInteger(timestamp) || timestamp instanceof Date)) {
16
14
  return null;
17
15
  }
18
16
 
19
- if (isMoment) {
20
- return timestamp.format('DD.MM.YYYY');
21
- }
22
-
23
17
  var date = timestamp instanceof Date ? timestamp : new Date(timestamp);
24
18
  var dd = ensureTwoDigits(date.getDate());
25
19
  var mm = ensureTwoDigits(date.getMonth() + 1);
@@ -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": "3.1.5",
3
+ "version": "4.0.3",
4
4
  "description": "JavaScript general use string formatters",
5
5
  "keywords": [
6
6
  "ffe"
@@ -9,20 +9,20 @@
9
9
  "author": "SpareBank 1",
10
10
  "files": [
11
11
  "lib",
12
- "es"
12
+ "es",
13
+ "types"
13
14
  ],
14
15
  "main": "lib/index.js",
15
16
  "module": "es/index.js",
17
+ "types": "types/index.d.ts",
16
18
  "sideEffects": false,
17
19
  "repository": {
18
20
  "type": "git",
19
21
  "url": "ssh://git@github.com:SpareBank1/designsystem.git"
20
22
  },
21
23
  "scripts": {
22
- "build": "npm run build:cjs && npm run build:es",
23
- "build:cjs": "babel -d lib/. --root-mode=upward --env-name=cjs --ignore=*.spec.js src/.",
24
- "build:es": "babel -d es/. --root-mode=upward --env-name=es --ignore=*.spec.js src/.",
25
- "lint": "eslint src/.",
24
+ "build": "ffe-buildtool babel",
25
+ "lint": "eslint src",
26
26
  "test": "jest",
27
27
  "test:watch": "jest --watch"
28
28
  },
@@ -30,12 +30,12 @@
30
30
  "underscore.string": "^3.3.4"
31
31
  },
32
32
  "devDependencies": {
33
+ "@sb1/ffe-buildtool": "^0.2.0",
33
34
  "eslint": "^5.9.0",
34
- "jest": "^26.0.0",
35
- "moment": "^2.18.1"
35
+ "jest": "^26.0.0"
36
36
  },
37
37
  "publishConfig": {
38
38
  "access": "public"
39
39
  },
40
- "gitHead": "072f7a0ce24bd7fe80978a54e5a4d7c6216d700a"
40
+ "gitHead": "10669ef6d5ebf454feb4eddb9aa4ca7bc8f439dc"
41
41
  }
@@ -0,0 +1,31 @@
1
+ declare module '@sb1/ffe-formatters' {
2
+ export function formatAccountNumber(accountNumber: string): string;
3
+
4
+ export function formatCurrency(
5
+ amount: number | string,
6
+ opts?: { prefix?: string; postfix?: string },
7
+ ): string;
8
+
9
+ export function formatDate(timestamp: number | Date): string;
10
+
11
+ export function formatDistance(
12
+ distance: number | string,
13
+ opts?: { unit?: string },
14
+ ): string;
15
+
16
+ export function formatNumber(
17
+ number: number | string,
18
+ opts?: {
19
+ decimals?: number;
20
+ thousandSeparator?: string;
21
+ decimalMark?: string;
22
+ },
23
+ ): string;
24
+
25
+ export function formatPercentage(
26
+ amount: number,
27
+ opts?: { minDecimals?: number; maxDecimals?: string },
28
+ ): string;
29
+
30
+ export function formatFodselsnummer(ssn: string): string;
31
+ }
package/CHANGELOG.md DELETED
@@ -1,236 +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
- ## [3.1.5](https://github.com/SpareBank1/designsystem/compare/@sb1/ffe-formatters@3.1.4...@sb1/ffe-formatters@3.1.5) (2021-02-02)
7
-
8
-
9
- ### Bug Fixes
10
-
11
- * packages/ffe-formatters/package.json to reduce vulnerabilities ([8b90ace](https://github.com/SpareBank1/designsystem/commit/8b90ace5def900bd093f75269f116caf4cc04db2))
12
-
13
-
14
-
15
-
16
-
17
- ## [3.1.4](https://github.com/SpareBank1/designsystem/compare/@sb1/ffe-formatters@3.1.3...@sb1/ffe-formatters@3.1.4) (2021-02-02)
18
-
19
-
20
- ### Bug Fixes
21
-
22
- * **ffe-formatters:** reduce vulnerabilities ([d07213f](https://github.com/SpareBank1/designsystem/commit/d07213fd7c223612efcec50818c14330f9726385))
23
-
24
-
25
-
26
-
27
-
28
- ## [3.1.3](https://github.com/SpareBank1/designsystem/compare/@sb1/ffe-formatters@3.1.2...@sb1/ffe-formatters@3.1.3) (2018-12-11)
29
-
30
- ### Bug Fixes
31
-
32
- - Build tree shakeable packages ([fb4a9ea](https://github.com/SpareBank1/designsystem/commit/fb4a9ea))
33
-
34
- ## [3.1.2](https://github.com/SpareBank1/designsystem/compare/@sb1/ffe-formatters@3.1.1...@sb1/ffe-formatters@3.1.2) (2018-12-06)
35
-
36
- ### Bug Fixes
37
-
38
- - **ffe-formatters:** Make sure formatters are transpiled also ([659d143](https://github.com/SpareBank1/designsystem/commit/659d143))
39
-
40
- ## [3.1.1](https://github.com/SpareBank1/designsystem/compare/@sb1/ffe-formatters@3.1.0...@sb1/ffe-formatters@3.1.1) (2018-12-04)
41
-
42
- **Note:** Version bump only for package @sb1/ffe-formatters
43
-
44
- <a name="3.1.0"></a>
45
-
46
- # [3.1.0](https://github.com/SpareBank1/designsystem/compare/@sb1/ffe-formatters@3.0.3...@sb1/ffe-formatters@3.1.0) (2018-10-02)
47
-
48
- ### Features
49
-
50
- - **ffe-formatters:** Add minDecimals option to formatPercentage. ([07cd558](https://github.com/SpareBank1/designsystem/commit/07cd558))
51
-
52
- <a name="3.0.3"></a>
53
-
54
- ## [3.0.3](https://github.com/SpareBank1/designsystem/compare/@sb1/ffe-formatters@3.0.2...@sb1/ffe-formatters@3.0.3) (2018-08-09)
55
-
56
- **Note:** Version bump only for package @sb1/ffe-formatters
57
-
58
- <a name="3.0.2"></a>
59
-
60
- ## [3.0.2](https://github.com/SpareBank1/designsystem/compare/@sb1/ffe-formatters@3.0.0...@sb1/ffe-formatters@3.0.2) (2018-03-07)
61
-
62
- **Note:** Version bump only for package @sb1/ffe-formatters
63
-
64
- <a name="3.0.1"></a>
65
-
66
- ## [3.0.1](https://github.com/SpareBank1/designsystem/compare/@sb1/ffe-formatters@3.0.0...@sb1/ffe-formatters@3.0.1) (2018-03-02)
67
-
68
- **Note:** Version bump only for package @sb1/ffe-formatters
69
-
70
- <a name="3.0.0"></a>
71
-
72
- # 3.0.0 (2018-02-25)
73
-
74
- ### Bug Fixes
75
-
76
- - remove all references to internal system ([ff22340](https://github.com/SpareBank1/designsystem/commit/ff22340))
77
-
78
- ### Chores
79
-
80
- - add [@sb1](https://github.com/sb1)/ scope to all packages ([37efbb4](https://github.com/SpareBank1/designsystem/commit/37efbb4))
81
-
82
- ### BREAKING CHANGES
83
-
84
- - All packages have been renamed to add the @sb1 scope.
85
-
86
- See links [1] and [2] to read more about package scopes.
87
-
88
- Unfortunately this requires you update both your dependencies in
89
- `package.json` and all `import` or `require` statements in your code.
90
- Also, you unfortunately have to upgrade all FFE packages at once due to
91
- dependency between packages. If you are on the latest version prior to
92
- this breaking change the upgrade should be a matter of updating
93
- `package.json` with new package names and versions, and updating your
94
- imports.
95
-
96
- To help find the proper package versions you can either browse to the
97
- packages you need or check out the list of Git tags either on
98
- Github [3] or by cloning the repository and running the `git tag`
99
- command. All package versions get a tag in the format
100
- _package@version_.
101
-
102
- Update your `package.json` with the latest package version and add the
103
- @sb1 scope to the package name:
104
-
105
- ```diff
106
- - "ffe-core": "11.0.2",
107
- + "@sb1/ffe-core": "11.0.2",
108
- ```
109
-
110
- Scoped packages all get put in a subdirectory in `node_modules/`. In our
111
- case packages will be put in the `node_modules/@sb1/` directory. If your
112
- build depends on file paths (for instance for copying fonts) you need to
113
- update that path to include the scope.
114
-
115
- The directory structure also means you have to update your imports, both
116
- in Less and in JavaScript.
117
-
118
- Using `less-plugin-npm-import`:
119
-
120
- ```diff
121
- - @import 'npm://ffe-core/less/ffe';
122
- + @import 'npm://@sb1/ffe-core/less/ffe';
123
- ```
124
-
125
- Using Webpack:
126
-
127
- ```diff
128
- - @import '~ffe-core/less/ffe';
129
- + @import '~@sb1/ffe-core/less/ffe';
130
- ```
131
-
132
- Using plain old paths:
133
-
134
- ```diff
135
- - @import '../path/to/node_modules/ffe-core/less/ffe';
136
- + @import '../path/to/node_modules/@sb1/ffe-core/less/ffe';
137
- ```
138
-
139
- JavaScript `import`:
140
-
141
- ```diff
142
- - import { ActionButton } from 'ffe-buttons-react';
143
- + import { ActionButton } from '@sb1/ffe-buttons-react';
144
- ```
145
-
146
- JavaScript `require`:
147
-
148
- ```diff
149
- - const { ActionButton } = require('ffe-buttons-react').default;
150
- + const { ActionButton } = require('@sb1/ffe-buttons-react').default;
151
- ```
152
-
153
- [1]: https://docs.npmjs.com/misc/scope
154
- [2]: https://docs.npmjs.com/getting-started/scoped-packages
155
- [3]: https://github.com/sparebank1/designsystem/tags
156
-
157
- <a name="2.1.7"></a>
158
-
159
- ## [2.1.7](https://github.com/SpareBank1/designsystem/compare/ffe-formatters@2.1.6...ffe-formatters@2.1.7) (2018-02-23)
160
-
161
- **Note:** Version bump only for package ffe-formatters
162
-
163
- <a name="2.1.6"></a>
164
-
165
- ## [2.1.6](https://github.com/SpareBank1/designsystem/compare/ffe-formatters@2.1.5...ffe-formatters@2.1.6) (2018-02-22)
166
-
167
- **Note:** Version bump only for package ffe-formatters
168
-
169
- <a name="2.1.5"></a>
170
-
171
- ## [2.1.5](https://github.com/SpareBank1/designsystem/compare/ffe-formatters@2.1.4...ffe-formatters@2.1.5) (2018-01-31)
172
-
173
- **Note:** Version bump only for package ffe-formatters
174
-
175
- <a name="2.1.4"></a>
176
-
177
- ## [2.1.4](https://github.com/SpareBank1/designsystem/compare/ffe-formatters@2.1.3...ffe-formatters@2.1.4) (2018-01-22)
178
-
179
- **Note:** Version bump only for package ffe-formatters
180
-
181
- <a name="2.1.3"></a>
182
-
183
- ## [2.1.3](https://github.com/SpareBank1/designsystem/compare/ffe-formatters@2.1.2...ffe-formatters@2.1.3) (2018-01-19)
184
-
185
- **Note:** Version bump only for package ffe-formatters
186
-
187
- <a name="2.1.2"></a>
188
-
189
- ## [2.1.2](https://github.com/SpareBank1/designsystem/compare/ffe-formatters@2.1.1...ffe-formatters@2.1.2) (2018-01-18)
190
-
191
- **Note:** Version bump only for package ffe-formatters
192
-
193
- <a name="2.1.1"></a>
194
-
195
- ## 2.1.1 (2018-01-16)
196
-
197
- **Note:** Version bump only for package ffe-formatters
198
-
199
- # 2.1.0
200
-
201
- - `formatNumber` now accepts additional props to the `opts`-argument. - `thousandSeparator` (defaults to NON_BREAKING_SPACE) - `decimalMark` (defaults to ',')
202
-
203
- ## 2.0.4
204
-
205
- - Bugfix: Fixed a bug where - `formatNumber(0)` returns 0, (expected: '0') - `formatNumber(0, { decimals: 2 })` returns 0, (expected: '0,00')
206
-
207
- ## 2.0.3
208
-
209
- - `formatDistance` no longer returns the empty string if the input is equal to
210
- the result of `formatNumber(input)` (solves part of SFO-6995)
211
-
212
- ## 2.0.2
213
-
214
- - Bugfix: Include correct files in NPM package.
215
-
216
- ## 2.0.1
217
-
218
- - Bugfix: Fix broken export of `formatFodselsnummer` from the main index file.
219
-
220
- # 2.0.0
221
-
222
- **BREAKING:** `formatPercentage` now expects the actual percentage instead of the fraction.
223
- Previously: `formatPercentage(0.123) === 12.3 %`, now: `formatPercentage(0.123) === 0.12 %`.
224
- To migrate, just make sure the value you send in is in the correct order of magnitude.
225
-
226
- # 1.0.0
227
-
228
- Initial version of `ffe-formatters`. Includes the following formatters:
229
-
230
- - formatAccountNumber
231
- - formatCurrency
232
- - formatDate
233
- - formatFodselsnummer
234
- - formatKm
235
- - formatNumber
236
- - 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,16 +0,0 @@
1
- import formatDate from './formatDate';
2
- import moment from 'moment';
3
- describe('format date ', function () {
4
- it('in milliseconds', function () {
5
- expect(formatDate(1514808000000)).toBe('01.01.2018');
6
- });
7
- it('in javascript date format', function () {
8
- expect(formatDate(new Date(2016, 6, 6))).toBe('06.07.2016');
9
- });
10
- it('in moment objects', function () {
11
- expect(formatDate(moment(1514808000000))).toBe('01.01.2018');
12
- });
13
- it('returns null when input is string', function () {
14
- expect(formatDate('06.07.2016')).toBe(null);
15
- });
16
- });
@@ -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,22 +0,0 @@
1
- "use strict";
2
-
3
- var _formatDate = _interopRequireDefault(require("./formatDate"));
4
-
5
- var _moment = _interopRequireDefault(require("moment"));
6
-
7
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
8
-
9
- describe('format date ', function () {
10
- it('in milliseconds', function () {
11
- expect((0, _formatDate.default)(1514808000000)).toBe('01.01.2018');
12
- });
13
- it('in javascript date format', function () {
14
- expect((0, _formatDate.default)(new Date(2016, 6, 6))).toBe('06.07.2016');
15
- });
16
- it('in moment objects', function () {
17
- expect((0, _formatDate.default)((0, _moment.default)(1514808000000))).toBe('01.01.2018');
18
- });
19
- it('returns null when input is string', function () {
20
- expect((0, _formatDate.default)('06.07.2016')).toBe(null);
21
- });
22
- });
@@ -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
- });