"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.lowercaseKeys = exports.removeDiacritics = exports.serializeError = exports.sanitizeHtml = exports.calcAge = exports.sanitizeOptions = exports.levenshtein = void 0;
const diacritics_1 = __importDefault(require("diacritics"));
const fast_levenshtein_1 = __importDefault(require("fast-levenshtein"));
exports.levenshtein = fast_levenshtein_1.default;
const moment_1 = __importDefault(require("moment"));
const sanitize_html_1 = __importDefault(require("sanitize-html"));
exports.sanitizeOptions = {
    allowedTags: [
        'address',
        'article',
        'aside',
        'footer',
        'header',
        'hgroup',
        'nav',
        'section',
        'h1',
        'h2',
        'h3',
        'h4',
        'h5',
        'h6',
        'blockquote',
        'dd',
        'dir',
        'div',
        'dl',
        'dt',
        'figcaption',
        'figure',
        'hr',
        'li',
        'main',
        'ol',
        'p',
        'pre',
        'ul',
        'a',
        'abbr',
        'b',
        'bdi',
        'bdo',
        'br',
        'cite',
        'code',
        'data',
        'dfn',
        'em',
        'i',
        'kbd',
        'mark',
        'q',
        'rb',
        'rp',
        'rt',
        'rtc',
        'ruby',
        's',
        'samp',
        'small',
        'span',
        'strong',
        'sub',
        'sup',
        'time',
        'tt',
        'u',
        'var',
        'wbr',
        'img',
        'caption',
        'col',
        'colgroup',
        'table',
        'tbody',
        'td',
        'tfoot',
        'th',
        'thead',
        'tr',
        'label',
    ],
    allowedAttributes: {
        '*': ['colspan', 'rowspan', 'align'],
        a: ['href'],
        img: ['src'],
    },
};
function calcAge(dateOfBirth, presentMoment = new Date()) {
    const to = moment_1.default.utc(dateOfBirth);
    const from = moment_1.default.utc(presentMoment);
    return from.diff(to, 'years');
}
exports.calcAge = calcAge;
function sanitizeHtml(html, options = exports.sanitizeOptions) {
    return (0, sanitize_html_1.default)(html, options);
}
exports.sanitizeHtml = sanitizeHtml;
function serializeError(err) {
    return {
        name: err.name,
        code: err.code,
        message: err.message,
        details: err.details,
    };
}
exports.serializeError = serializeError;
function removeDiacritics(str) {
    return diacritics_1.default.remove(str);
}
exports.removeDiacritics = removeDiacritics;
function lowercaseKeys(object) {
    return JSON.parse(JSON.stringify(object, (key, val) => {
        if (val && typeof val === 'object') {
            const newObj = {};
            for (const [k, v] of Object.entries(val)) {
                newObj[k.toLowerCase()] = v;
            }
            return newObj;
        }
        return val;
    }));
}
exports.lowercaseKeys = lowercaseKeys;
//# sourceMappingURL=other.js.map