import mime from 'mime';
// eslint-disable-next-line no-control-regex
export const removeEmptyChars = (value) => value.replace(/\u0000/g, '');
export const padEmptyChars = (value, chars) => value.padEnd(chars, '\u0000');
export const tryOr = (callback, defaultValue) => {
    try {
        return callback();
    }
    catch (error) {
        return defaultValue;
    }
};
export const tryOrNull = (cb) => tryOr(cb, null);
export const chunk = (array, chunkSize) => array.reduce((accumulator, item, index) => {
    const chunkIndex = Math.floor(index / chunkSize);
    if (!accumulator[chunkIndex]) {
        accumulator[chunkIndex] = [];
    }
    accumulator[chunkIndex].push(item);
    return accumulator;
}, []);
export const zipMap = (left, right, fn) => left.map((t, index) => { var _a; return fn(t, (_a = right === null || right === void 0 ? void 0 : right[index]) !== null && _a !== void 0 ? _a : null, index); });
export const randomStr = (length = 20, alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789') => {
    let result = '';
    const alphabetLength = alphabet.length;
    for (var i = 0; i < length; i++) {
        result += alphabet.charAt(Math.floor(Math.random() * alphabetLength));
    }
    return result;
};
export const getContentType = (fileName) => mime.getType(fileName);
export const getExtension = (fileName) => {
    const lastDotIndex = fileName.lastIndexOf('.');
    return lastDotIndex < 0 ? null : fileName.slice(lastDotIndex + 1);
};
export const walk = (parent, cb, options) => {
    var _a;
    const recursiveWalk = (child) => walk(child, cb, options);
    if (parent && Array.isArray(parent)) {
        parent.forEach((child, index) => {
            cb(recursiveWalk, child, index, parent);
        });
    }
    else if (parent && typeof parent === 'object') {
        const keys = Object.keys(parent);
        if ((_a = options === null || options === void 0 ? void 0 : options.sortObjectKeys) !== null && _a !== void 0 ? _a : true) {
            keys.sort();
        }
        keys.forEach((key) => {
            const child = parent[key];
            cb(recursiveWalk, child, key, parent);
        });
    }
};
export const removeUndefinedAttributes = (object) => Object.keys(object).reduce((acc, key) => {
    if (object[key] !== undefined) {
        acc[key] = object[key];
    }
    return acc;
}, {});
//# sourceMappingURL=common.js.map