// SPDX-License-Identifier: Apache-2.0
import { UnsupportedOperationError } from '../errors/unsupported-operation-error.js';
export class StringEx {
    static EMPTY = '';
    static DASH = '-';
    static UNDERSCORE = '_';
    static PERIOD = '.';
    constructor() {
        throw new UnsupportedOperationError('This class cannot be instantiated');
    }
    static isUppercase(value) {
        return value === value.toUpperCase();
    }
    static isEmpty(value) {
        return !value || value.trim().length === 0;
    }
    static isUnderscored(value) {
        return value.includes(StringEx.UNDERSCORE);
    }
    static isDashed(value) {
        return value.includes(StringEx.DASH);
    }
    static nounCase(value) {
        if (StringEx.isEmpty(value)) {
            return value;
        }
        return value.charAt(0).toUpperCase() + value.slice(1);
    }
    static verbCase(value) {
        if (StringEx.isEmpty(value)) {
            return value;
        }
        return value.charAt(0).toLowerCase() + value.slice(1);
    }
    static kebabToCamelCase(value) {
        if (StringEx.isEmpty(value) || !StringEx.isDashed(value)) {
            return StringEx.verbCase(value);
        }
        const parts = value.split(StringEx.DASH);
        for (let index = 0; index < parts.length; index++) {
            const part = parts[index];
            parts[index] = index === 0 ? StringEx.verbCase(part) : StringEx.nounCase(part);
        }
        return parts.join(StringEx.EMPTY);
    }
    static snakeToCamelCase(value) {
        return StringEx.snakeKebabToXJoinedCase(value, StringEx.EMPTY, StringEx.verbCase, StringEx.nounCase);
    }
    static snakeToDotCase(value) {
        return StringEx.snakeKebabToXJoinedCase(value, StringEx.PERIOD, StringEx.verbCase, StringEx.verbCase);
    }
    static snakeKebabToXJoinedCase(value, separator, firstWordCase, subsequentWordCase) {
        if (StringEx.isEmpty(value) || !StringEx.isUnderscored(value)) {
            return firstWordCase(value);
        }
        const parts = value.split(StringEx.UNDERSCORE);
        for (let index = 0; index < parts.length; index++) {
            const part = parts[index];
            parts[index] = StringEx.kebabToCamelCase(part.toLowerCase());
            parts[index] = index === 0 ? firstWordCase(parts[index]) : subsequentWordCase(parts[index]);
        }
        return parts.join(separator);
    }
    static camelCaseToKebab(key) {
        if (StringEx.isEmpty(key)) {
            return key;
        }
        return key.replaceAll(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
    }
}
//# sourceMappingURL=string-ex.js.map