@sb1/ffe-formatters 4.0.1 → 4.0.2

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.
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.1",
3
+ "version": "4.0.2",
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.1.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": "6d88ed0e37a78315d16e96884112437772a7cc19"
40
+ "gitHead": "59eb2e12625e744f1a116c14a40cf69f1bbecdc6"
43
41
  }
@@ -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
- });