@fremtind/jkl-formatters-util
Version:
Formatters for common data formats in Jøkul
40 lines (39 loc) • 1.66 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var formatKortnummer_exports = {};
__export(formatKortnummer_exports, {
KORTNUMMER_REGEX: () => KORTNUMMER_REGEX,
formatKortnummer: () => formatKortnummer
});
module.exports = __toCommonJS(formatKortnummer_exports);
var import_jkl_constants_util = require("@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(import_jkl_constants_util.unicode.NON_BREAKING_SPACE);
}
//# sourceMappingURL=formatKortnummer.js.map