'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var nunjucksDate = require('nunjucks-date');

const setUpNunjucksFilters = (env) => {
    env.addFilter('addRequiredAttributeToAll', addRequiredAttributeToAll);
    env.addFilter('json', stringifyJson);
    env.addFilter('capitaliseSentence', capitaliseSentence);
    // Namespace our own filters
    env.addFilter('dpr.findError', findError);
    env.addFilter('dpr.spacesToDash', spacesToDash);
    nunjucksDate.setDefaultFormat('DD/MM/YYYY');
    nunjucksDate.install(env, 'dprDate');
};
const findError = (errs, errToFind) => {
    const error = errs?.find((err) => err.href.slice(1) === errToFind)?.text;
    return error ? { text: error } : null;
};
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const stringifyJson = (jsonObj) => {
    return JSON.stringify(jsonObj, null, 2);
};
const capitaliseSentence = (text) => {
    return text.charAt(0).toUpperCase() + text.substring(1).toLowerCase();
};
const addRequiredAttributeToAll = (items) => {
    return items.map((i) => ({
        ...i,
        attributes: {
            required: true,
        },
    }));
};
const spacesToDash = (text) => {
    return text?.replace(/ /g, '-') ?? '';
};

exports.default = setUpNunjucksFilters;
exports.setUpNunjucksFilters = setUpNunjucksFilters;
//# sourceMappingURL=setUpNunjucksFilters.js.map
