@fremtind/jkl-formatters-util
Version:
Formatters for common data formats in Jøkul
20 lines (19 loc) • 646 B
JavaScript
import { unicode } from "@fremtind/jkl-constants-util";
const KORTNUMMER_REGEX = {
full: /^(\d{4})(\d{4})(\d{4})(\d{4})$/,
partial: /^(\d{4})(\d{1,4})?(\d{1,4})?(\d{1,4})?$/
};
function formatKortnummer(input, options) {
const strippedInput = input.replace(/[\s-.]/g, "");
const regex = (options == null ? void 0 : options.partial) ? KORTNUMMER_REGEX.partial : KORTNUMMER_REGEX.full;
const match = strippedInput.match(regex);
if (!match) {
return input;
}
return match.slice(1).filter(Boolean).join(unicode.NON_BREAKING_SPACE);
}
export {
KORTNUMMER_REGEX,
formatKortnummer
};
//# sourceMappingURL=formatKortnummer.js.map