import { hasNoItems } from '@angular-ru/cdk/array';
import { isFunctionLike } from '@angular-ru/cdk/function';

function capitalize(value) {
    return value.charAt(0).toUpperCase() + value.slice(1);
}

// noinspection SuspiciousTypeOfGuard
function filter(value, predicate = []) {
    if (Array.isArray(predicate)) {
        return filterWithCharacters(value, predicate);
    }
    if (isFunctionLike(predicate)) {
        return filterWithFunction(value, predicate);
    }
    if (predicate instanceof RegExp) {
        return filterWithRegExp(value, predicate);
    }
    return value;
}
function filterWithCharacters(value, predicate = []) {
    if (hasNoItems(predicate)) {
        return value;
    }
    else {
        return Array.from(value)
            .filter((char) => predicate.includes(char))
            .join('');
    }
}
function filterWithFunction(value, predicate) {
    return Array.from(value)
        .filter((element, index, array) => predicate(element, index, array))
        .join('');
}
function filterWithRegExp(value, predicate) {
    var _a;
    return ((_a = value.match(predicate)) !== null && _a !== void 0 ? _a : []).join('');
}

function generateQuickGuid() {
    const radix = 36;
    const startWith = 2;
    const endWith = 15;
    return (Math.random().toString(radix).substring(startWith, endWith) +
        Math.random().toString(radix).substring(startWith, endWith));
}

function getByteSize(value) {
    return new Blob([value]).size;
}

function getCountSpacesOnString(value) {
    var _a, _b;
    return (_b = (_a = value === null || value === void 0 ? void 0 : value.match(/\s/g)) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0;
}

function getFirstSymbol(value) {
    return value === null || value === void 0 ? void 0 : value.slice(0, 1);
}

function getLastSymbol(value) {
    return value === null || value === void 0 ? void 0 : value.slice(-1);
}

function isString(value) {
    return typeof value === 'string';
}

function removeLastSymbol(value) {
    return value === null || value === void 0 ? void 0 : value.slice(0, -1);
}

function removeNonNumericSymbols(value) {
    var _a;
    return (_a = value === null || value === void 0 ? void 0 : value.replace(/[^\d,.-]/g, '').replace(/^\.|^,/, '')) !== null && _a !== void 0 ? _a : '';
}

function replaceEveryCommaOnDot(value) {
    var _a;
    return (_a = value === null || value === void 0 ? void 0 : value.replace(/,/g, '.')) !== null && _a !== void 0 ? _a : '';
}

function splitOnUniqueValues(value, separator = /[,;]|(\s+)/g) {
    var _a;
    const uniqueValues = new Set();
    const parsedValues = (_a = value === null || value === void 0 ? void 0 : value.split(separator)) !== null && _a !== void 0 ? _a : [];
    for (const item of parsedValues) {
        const prepared = item === null || item === void 0 ? void 0 : item.trim();
        if (prepared) {
            uniqueValues.add(prepared);
        }
    }
    return Array.from(uniqueValues);
}

const SPACE_INDENT = 4;
function stringify(value, spaceIndent = SPACE_INDENT) {
    return String(JSON.stringify(value, null, spaceIndent)).toString();
}

function toStringValue(value, converter) {
    var _a;
    return isFunctionLike(converter) ? converter(value) : (_a = value === null || value === void 0 ? void 0 : value.toString()) !== null && _a !== void 0 ? _a : '';
}

function trim(value) {
    // note: don't use isString for preserve circular dependencies
    return (typeof value === 'string' ? value === null || value === void 0 ? void 0 : value.trim() : value);
}

/**
 * Generated bundle index. Do not edit.
 */

export { capitalize, filter, generateQuickGuid, getByteSize, getCountSpacesOnString, getFirstSymbol, getLastSymbol, isString, removeLastSymbol, removeNonNumericSymbols, replaceEveryCommaOnDot, splitOnUniqueValues, stringify, toStringValue, trim };
//# sourceMappingURL=angular-ru-cdk-string.mjs.map
