@dnb/eufemia
Version:
DNB Eufemia Design System UI Library
30 lines • 971 B
JavaScript
import { IS_WIN } from "../../../shared/helpers.js";
import { ABSENT_VALUE_FORMAT, isAbsent } from "./constants.js";
import { formatWith } from "./formatCore.js";
const formatNationalIdentityNumberParts = (number, locale = null) => {
if (isAbsent(number)) {
return {
number: ABSENT_VALUE_FORMAT,
aria: ABSENT_VALUE_FORMAT
};
}
const num = String(number).replace(/[^0-9]/g, '');
let display = num;
let aria = null;
switch (locale) {
default:
{
display = num.split(/([0-9]{6})/).filter(s => s).join(' ');
aria = display.split(/([0-9]{2})([0-9]{2})([0-9]{2}) ([0-9]{1})([0-9]{1})([0-9]{1})([0-9]{1})([0-9]{1})/).filter(s => s).join(IS_WIN ? '. ' : ' ');
}
}
if (aria === null) {
aria = display;
}
return {
number: display,
aria
};
};
export const formatNationalIdentityNumber = formatWith('nin', formatNationalIdentityNumberParts);
//# sourceMappingURL=formatNationalIdentityNumber.js.map