@sb1/ffe-formatters 100.12.3 → 101.0.0
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/es/formatAccountNumber.js +7 -7
- package/es/formatCurrency.js +11 -20
- package/es/formatDate.js +7 -7
- package/es/formatDistance.js +4 -5
- package/es/formatFodselsnummer.js +2 -2
- package/es/formatNumber.js +4 -4
- package/es/formatPercentage.js +7 -8
- package/es/internal/parseNumber.js +18 -19
- package/es/internal/unicode.js +1 -1
- package/lib/formatAccountNumber.js +8 -8
- package/lib/formatCurrency.js +14 -23
- package/lib/formatDate.js +7 -7
- package/lib/formatDistance.js +7 -8
- package/lib/formatFodselsnummer.js +3 -3
- package/lib/formatNumber.js +5 -5
- package/lib/formatPercentage.js +8 -9
- package/lib/internal/parseNumber.js +18 -19
- package/package.json +4 -4
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { NON_BREAKING_SPACE } from './internal/unicode';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
for (
|
|
5
|
-
|
|
2
|
+
const foreignAccountNumber = (accountNumber) => {
|
|
3
|
+
let formattedAccountNumber = '';
|
|
4
|
+
for (let i = 0; i < accountNumber.length; i++) {
|
|
5
|
+
const isFourthIteration = (i + 1) % 4 === 0;
|
|
6
6
|
formattedAccountNumber += accountNumber[i].valueOf();
|
|
7
7
|
if (isFourthIteration && i + 1 < accountNumber.length) {
|
|
8
8
|
formattedAccountNumber += NON_BREAKING_SPACE;
|
|
@@ -10,8 +10,8 @@ var foreignAccountNumber = function (accountNumber) {
|
|
|
10
10
|
}
|
|
11
11
|
return formattedAccountNumber;
|
|
12
12
|
};
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
const domesticAccountNumber = (accountNumber) => {
|
|
14
|
+
let formattedAccountNumber = '';
|
|
15
15
|
if (accountNumber.length > 0) {
|
|
16
16
|
formattedAccountNumber += accountNumber.substring(0, 4);
|
|
17
17
|
}
|
|
@@ -25,7 +25,7 @@ var domesticAccountNumber = function (accountNumber) {
|
|
|
25
25
|
}
|
|
26
26
|
return formattedAccountNumber;
|
|
27
27
|
};
|
|
28
|
-
export
|
|
28
|
+
export const formatAccountNumber = (accountNumber) => {
|
|
29
29
|
if (!accountNumber) {
|
|
30
30
|
return accountNumber;
|
|
31
31
|
}
|
package/es/formatCurrency.js
CHANGED
|
@@ -1,29 +1,20 @@
|
|
|
1
|
-
var __assign = (this && this.__assign) || function () {
|
|
2
|
-
__assign = Object.assign || function(t) {
|
|
3
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
-
s = arguments[i];
|
|
5
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
-
t[p] = s[p];
|
|
7
|
-
}
|
|
8
|
-
return t;
|
|
9
|
-
};
|
|
10
|
-
return __assign.apply(this, arguments);
|
|
11
|
-
};
|
|
12
1
|
import { formatNumber } from './formatNumber';
|
|
13
2
|
import { parseNumber } from './internal/parseNumber';
|
|
14
3
|
import { NON_BREAKING_SPACE } from './internal/unicode';
|
|
15
|
-
export
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
4
|
+
export const formatCurrency = (amount, opts) => {
|
|
5
|
+
const { locale } = opts;
|
|
6
|
+
const { prefix = `kr${NON_BREAKING_SPACE}`, postfix = ',–' } = {
|
|
7
|
+
...opts,
|
|
8
|
+
};
|
|
9
|
+
const parsed = parseNumber(amount, locale);
|
|
19
10
|
// A ',-' postfix is not allowed for amounts with øre, see:
|
|
20
11
|
// http://www.sprakradet.no/svardatabase/sporsmal-og-svar/kronebelop-rekkjefolgje-komma-og-strek/
|
|
21
12
|
if (typeof parsed === 'number' && parsed % 1 !== 0) {
|
|
22
|
-
|
|
23
|
-
return
|
|
13
|
+
const decimalPostfix = ![',–', ',-'].includes(postfix) ? postfix : '';
|
|
14
|
+
return `${prefix}${formatNumber(amount, {
|
|
24
15
|
decimals: 2,
|
|
25
|
-
locale
|
|
26
|
-
})
|
|
16
|
+
locale,
|
|
17
|
+
})}${decimalPostfix}`;
|
|
27
18
|
}
|
|
28
|
-
return
|
|
19
|
+
return `${prefix}${formatNumber(amount, { locale })}${postfix}`;
|
|
29
20
|
};
|
package/es/formatDate.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
return
|
|
1
|
+
const ensureTwoDigits = (d) => `00${d}`.slice(-2);
|
|
2
|
+
export const formatDate = (timestamp) => {
|
|
3
|
+
const date = timestamp instanceof Date ? timestamp : new Date(timestamp);
|
|
4
|
+
const dd = ensureTwoDigits(date.getDate());
|
|
5
|
+
const mm = ensureTwoDigits(date.getMonth() + 1);
|
|
6
|
+
const yyyy = date.getFullYear();
|
|
7
|
+
return `${dd}.${mm}.${yyyy}`;
|
|
8
8
|
};
|
package/es/formatDistance.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { formatNumber } from './formatNumber';
|
|
2
2
|
import { parseNumber } from './internal/parseNumber';
|
|
3
3
|
import { NON_BREAKING_SPACE } from './internal/unicode';
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var toFormat = parseNumber(distance, 'nb');
|
|
4
|
+
export const formatDistance = (distance, opts = {}) => {
|
|
5
|
+
const { unit = 'km' } = opts;
|
|
6
|
+
const toFormat = parseNumber(distance, 'nb');
|
|
8
7
|
return toFormat === null
|
|
9
8
|
? ''
|
|
10
|
-
:
|
|
9
|
+
: `${formatNumber(toFormat, { locale: 'nb' })}${NON_BREAKING_SPACE}${unit}`;
|
|
11
10
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { NON_BREAKING_SPACE } from './internal/unicode';
|
|
2
|
-
export
|
|
2
|
+
export const formatFodselsnummer = (ssn) => {
|
|
3
3
|
if (!ssn || ssn.length !== 11) {
|
|
4
4
|
return ssn;
|
|
5
5
|
}
|
|
6
|
-
return
|
|
6
|
+
return `${ssn.substring(0, 6)}${NON_BREAKING_SPACE}${ssn.substring(6, 11)}`;
|
|
7
7
|
};
|
package/es/formatNumber.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { parseNumber } from './internal/parseNumber';
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
export const formatNumber = (number, opts) => {
|
|
3
|
+
const { decimals = 0, locale } = opts;
|
|
4
|
+
const supportedLocale = locale === 'en' ? 'en' : 'nb';
|
|
5
|
+
const toFormat = parseNumber(number, supportedLocale);
|
|
6
6
|
if (typeof toFormat !== 'number') {
|
|
7
7
|
return number;
|
|
8
8
|
}
|
package/es/formatPercentage.js
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import { NON_BREAKING_SPACE } from './internal/unicode';
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}; }
|
|
2
|
+
export const formatPercentage = (amount, opts = {
|
|
3
|
+
minDecimals: 0,
|
|
4
|
+
maxDecimals: 2,
|
|
5
|
+
}) => {
|
|
7
6
|
if (typeof amount !== 'number') {
|
|
8
|
-
return
|
|
7
|
+
return `${amount.replace('.', ',')}${NON_BREAKING_SPACE}%`;
|
|
9
8
|
}
|
|
10
|
-
|
|
9
|
+
const percentage = amount.toLocaleString('nb-NO', {
|
|
11
10
|
minimumFractionDigits: opts.minDecimals,
|
|
12
11
|
maximumFractionDigits: opts.maxDecimals,
|
|
13
12
|
});
|
|
14
|
-
return
|
|
13
|
+
return `${percentage.replace('.', ',')}${NON_BREAKING_SPACE}%`;
|
|
15
14
|
};
|
|
@@ -1,32 +1,31 @@
|
|
|
1
1
|
// https://observablehq.com/@mbostock/localized-number-parsing
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
class NumberParser {
|
|
3
|
+
constructor(locale) {
|
|
4
4
|
var _a, _b;
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
const parts = new Intl.NumberFormat(locale).formatToParts(12345.6);
|
|
6
|
+
const numerals = new Intl.NumberFormat(locale, { useGrouping: false })
|
|
7
7
|
.format(9876543210)
|
|
8
8
|
.split('')
|
|
9
9
|
.reverse();
|
|
10
|
-
|
|
11
|
-
this._group = new RegExp(
|
|
12
|
-
this._decimal = new RegExp(
|
|
13
|
-
this._numeral = new RegExp(
|
|
14
|
-
this._index =
|
|
10
|
+
const index = new Map(numerals.map((d, i) => [d, i]));
|
|
11
|
+
this._group = new RegExp(`[${(_a = parts.find(d => d.type === 'group')) === null || _a === void 0 ? void 0 : _a.value}]`, 'g');
|
|
12
|
+
this._decimal = new RegExp(`[${(_b = parts.find(d => d.type === 'decimal')) === null || _b === void 0 ? void 0 : _b.value}]`);
|
|
13
|
+
this._numeral = new RegExp(`[${numerals.join('')}]`, 'g');
|
|
14
|
+
this._index = d => `${index.get(d)}`;
|
|
15
15
|
}
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
parse(input) {
|
|
17
|
+
const string = input
|
|
18
18
|
.trim()
|
|
19
19
|
.replace(this._group, '')
|
|
20
20
|
.replace(this._decimal, '.')
|
|
21
21
|
.replace(this._numeral, this._index);
|
|
22
22
|
return string ? +string : Number.NaN;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
var parsed = parser.parse("".concat(number).replace(/\s/g, ''));
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
const nbParser = new NumberParser('nb');
|
|
26
|
+
const enParser = new NumberParser('en');
|
|
27
|
+
export const parseNumber = (number, locale) => {
|
|
28
|
+
const parser = locale === 'en' ? enParser : nbParser;
|
|
29
|
+
const parsed = parser.parse(`${number}`.replace(/\s/g, ''));
|
|
31
30
|
return Number.isNaN(parsed) ? null : parsed;
|
|
32
31
|
};
|
package/es/internal/unicode.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export const NON_BREAKING_SPACE = '\u00A0';
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.formatAccountNumber = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
for (
|
|
8
|
-
|
|
4
|
+
const unicode_1 = require("./internal/unicode");
|
|
5
|
+
const foreignAccountNumber = (accountNumber) => {
|
|
6
|
+
let formattedAccountNumber = '';
|
|
7
|
+
for (let i = 0; i < accountNumber.length; i++) {
|
|
8
|
+
const isFourthIteration = (i + 1) % 4 === 0;
|
|
9
9
|
formattedAccountNumber += accountNumber[i].valueOf();
|
|
10
10
|
if (isFourthIteration && i + 1 < accountNumber.length) {
|
|
11
11
|
formattedAccountNumber += unicode_1.NON_BREAKING_SPACE;
|
|
@@ -13,8 +13,8 @@ var foreignAccountNumber = function (accountNumber) {
|
|
|
13
13
|
}
|
|
14
14
|
return formattedAccountNumber;
|
|
15
15
|
};
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
const domesticAccountNumber = (accountNumber) => {
|
|
17
|
+
let formattedAccountNumber = '';
|
|
18
18
|
if (accountNumber.length > 0) {
|
|
19
19
|
formattedAccountNumber += accountNumber.substring(0, 4);
|
|
20
20
|
}
|
|
@@ -28,7 +28,7 @@ var domesticAccountNumber = function (accountNumber) {
|
|
|
28
28
|
}
|
|
29
29
|
return formattedAccountNumber;
|
|
30
30
|
};
|
|
31
|
-
|
|
31
|
+
const formatAccountNumber = (accountNumber) => {
|
|
32
32
|
if (!accountNumber) {
|
|
33
33
|
return accountNumber;
|
|
34
34
|
}
|
package/lib/formatCurrency.js
CHANGED
|
@@ -1,33 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
3
|
exports.formatCurrency = void 0;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
4
|
+
const formatNumber_1 = require("./formatNumber");
|
|
5
|
+
const parseNumber_1 = require("./internal/parseNumber");
|
|
6
|
+
const unicode_1 = require("./internal/unicode");
|
|
7
|
+
const formatCurrency = (amount, opts) => {
|
|
8
|
+
const { locale } = opts;
|
|
9
|
+
const { prefix = `kr${unicode_1.NON_BREAKING_SPACE}`, postfix = ',–' } = {
|
|
10
|
+
...opts,
|
|
11
|
+
};
|
|
12
|
+
const parsed = (0, parseNumber_1.parseNumber)(amount, locale);
|
|
22
13
|
// A ',-' postfix is not allowed for amounts with øre, see:
|
|
23
14
|
// http://www.sprakradet.no/svardatabase/sporsmal-og-svar/kronebelop-rekkjefolgje-komma-og-strek/
|
|
24
15
|
if (typeof parsed === 'number' && parsed % 1 !== 0) {
|
|
25
|
-
|
|
26
|
-
return
|
|
16
|
+
const decimalPostfix = ![',–', ',-'].includes(postfix) ? postfix : '';
|
|
17
|
+
return `${prefix}${(0, formatNumber_1.formatNumber)(amount, {
|
|
27
18
|
decimals: 2,
|
|
28
|
-
locale
|
|
29
|
-
})
|
|
19
|
+
locale,
|
|
20
|
+
})}${decimalPostfix}`;
|
|
30
21
|
}
|
|
31
|
-
return
|
|
22
|
+
return `${prefix}${(0, formatNumber_1.formatNumber)(amount, { locale })}${postfix}`;
|
|
32
23
|
};
|
|
33
24
|
exports.formatCurrency = formatCurrency;
|
package/lib/formatDate.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.formatDate = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
return
|
|
4
|
+
const ensureTwoDigits = (d) => `00${d}`.slice(-2);
|
|
5
|
+
const formatDate = (timestamp) => {
|
|
6
|
+
const date = timestamp instanceof Date ? timestamp : new Date(timestamp);
|
|
7
|
+
const dd = ensureTwoDigits(date.getDate());
|
|
8
|
+
const mm = ensureTwoDigits(date.getMonth() + 1);
|
|
9
|
+
const yyyy = date.getFullYear();
|
|
10
|
+
return `${dd}.${mm}.${yyyy}`;
|
|
11
11
|
};
|
|
12
12
|
exports.formatDate = formatDate;
|
package/lib/formatDistance.js
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.formatDistance = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
var toFormat = (0, parseNumber_1.parseNumber)(distance, 'nb');
|
|
4
|
+
const formatNumber_1 = require("./formatNumber");
|
|
5
|
+
const parseNumber_1 = require("./internal/parseNumber");
|
|
6
|
+
const unicode_1 = require("./internal/unicode");
|
|
7
|
+
const formatDistance = (distance, opts = {}) => {
|
|
8
|
+
const { unit = 'km' } = opts;
|
|
9
|
+
const toFormat = (0, parseNumber_1.parseNumber)(distance, 'nb');
|
|
11
10
|
return toFormat === null
|
|
12
11
|
? ''
|
|
13
|
-
:
|
|
12
|
+
: `${(0, formatNumber_1.formatNumber)(toFormat, { locale: 'nb' })}${unicode_1.NON_BREAKING_SPACE}${unit}`;
|
|
14
13
|
};
|
|
15
14
|
exports.formatDistance = formatDistance;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.formatFodselsnummer = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
const unicode_1 = require("./internal/unicode");
|
|
5
|
+
const formatFodselsnummer = (ssn) => {
|
|
6
6
|
if (!ssn || ssn.length !== 11) {
|
|
7
7
|
return ssn;
|
|
8
8
|
}
|
|
9
|
-
return
|
|
9
|
+
return `${ssn.substring(0, 6)}${unicode_1.NON_BREAKING_SPACE}${ssn.substring(6, 11)}`;
|
|
10
10
|
};
|
|
11
11
|
exports.formatFodselsnummer = formatFodselsnummer;
|
package/lib/formatNumber.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.formatNumber = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
const parseNumber_1 = require("./internal/parseNumber");
|
|
5
|
+
const formatNumber = (number, opts) => {
|
|
6
|
+
const { decimals = 0, locale } = opts;
|
|
7
|
+
const supportedLocale = locale === 'en' ? 'en' : 'nb';
|
|
8
|
+
const toFormat = (0, parseNumber_1.parseNumber)(number, supportedLocale);
|
|
9
9
|
if (typeof toFormat !== 'number') {
|
|
10
10
|
return number;
|
|
11
11
|
}
|
package/lib/formatPercentage.js
CHANGED
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.formatPercentage = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}; }
|
|
4
|
+
const unicode_1 = require("./internal/unicode");
|
|
5
|
+
const formatPercentage = (amount, opts = {
|
|
6
|
+
minDecimals: 0,
|
|
7
|
+
maxDecimals: 2,
|
|
8
|
+
}) => {
|
|
10
9
|
if (typeof amount !== 'number') {
|
|
11
|
-
return
|
|
10
|
+
return `${amount.replace('.', ',')}${unicode_1.NON_BREAKING_SPACE}%`;
|
|
12
11
|
}
|
|
13
|
-
|
|
12
|
+
const percentage = amount.toLocaleString('nb-NO', {
|
|
14
13
|
minimumFractionDigits: opts.minDecimals,
|
|
15
14
|
maximumFractionDigits: opts.maxDecimals,
|
|
16
15
|
});
|
|
17
|
-
return
|
|
16
|
+
return `${percentage.replace('.', ',')}${unicode_1.NON_BREAKING_SPACE}%`;
|
|
18
17
|
};
|
|
19
18
|
exports.formatPercentage = formatPercentage;
|
|
@@ -2,35 +2,34 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseNumber = void 0;
|
|
4
4
|
// https://observablehq.com/@mbostock/localized-number-parsing
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
class NumberParser {
|
|
6
|
+
constructor(locale) {
|
|
7
7
|
var _a, _b;
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
const parts = new Intl.NumberFormat(locale).formatToParts(12345.6);
|
|
9
|
+
const numerals = new Intl.NumberFormat(locale, { useGrouping: false })
|
|
10
10
|
.format(9876543210)
|
|
11
11
|
.split('')
|
|
12
12
|
.reverse();
|
|
13
|
-
|
|
14
|
-
this._group = new RegExp(
|
|
15
|
-
this._decimal = new RegExp(
|
|
16
|
-
this._numeral = new RegExp(
|
|
17
|
-
this._index =
|
|
13
|
+
const index = new Map(numerals.map((d, i) => [d, i]));
|
|
14
|
+
this._group = new RegExp(`[${(_a = parts.find(d => d.type === 'group')) === null || _a === void 0 ? void 0 : _a.value}]`, 'g');
|
|
15
|
+
this._decimal = new RegExp(`[${(_b = parts.find(d => d.type === 'decimal')) === null || _b === void 0 ? void 0 : _b.value}]`);
|
|
16
|
+
this._numeral = new RegExp(`[${numerals.join('')}]`, 'g');
|
|
17
|
+
this._index = d => `${index.get(d)}`;
|
|
18
18
|
}
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
parse(input) {
|
|
20
|
+
const string = input
|
|
21
21
|
.trim()
|
|
22
22
|
.replace(this._group, '')
|
|
23
23
|
.replace(this._decimal, '.')
|
|
24
24
|
.replace(this._numeral, this._index);
|
|
25
25
|
return string ? +string : Number.NaN;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
var parsed = parser.parse("".concat(number).replace(/\s/g, ''));
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
const nbParser = new NumberParser('nb');
|
|
29
|
+
const enParser = new NumberParser('en');
|
|
30
|
+
const parseNumber = (number, locale) => {
|
|
31
|
+
const parser = locale === 'en' ? enParser : nbParser;
|
|
32
|
+
const parsed = parser.parse(`${number}`.replace(/\s/g, ''));
|
|
34
33
|
return Number.isNaN(parsed) ? null : parsed;
|
|
35
34
|
};
|
|
36
35
|
exports.parseNumber = parseNumber;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sb1/ffe-formatters",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "101.0.0",
|
|
4
4
|
"description": "JavaScript general use string formatters",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ffe"
|
|
@@ -27,11 +27,11 @@
|
|
|
27
27
|
"test:watch": "jest --watch"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@sb1/ffe-buildtool": "^
|
|
31
|
-
"eslint": "^
|
|
30
|
+
"@sb1/ffe-buildtool": "^101.0.0",
|
|
31
|
+
"eslint": "^10.2.0"
|
|
32
32
|
},
|
|
33
33
|
"publishConfig": {
|
|
34
34
|
"access": "public"
|
|
35
35
|
},
|
|
36
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "7714019dbb9001551cb5d1c262c58afd609d4fb0"
|
|
37
37
|
}
|