kebabCase property

JsonCraftFormatter get kebabCase

Implementation

static JsonCraftFormatter get kebabCase => JsonCraftFormatter(
      name: 'kebabCase',
      formatter: (value, param, getValue) {
        // Primeiro converte espaços e underscores para hífen
        String result = value.replaceAll(RegExp(r'[\s_]+'), '-');

        // Depois adiciona hífen antes de letras maiúsculas
        result = result.replaceAllMapped(RegExp(r'([a-z])([A-Z])'), (match) {
          return '${match.group(1)}-${match.group(2)}';
        });

        return result
            .toLowerCase()
            .replaceAll(RegExp(r'^-+'), '')
            .replaceAll(RegExp(r'-+'), '-');
      },
    );