pjc-fields 0.0.62 → 0.0.64

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2841,7 +2841,8 @@ const centenasF = [
2841
2841
  const configUnidades = {
2842
2842
  // Nota: "Grama" (peso) é substantivo masculino ("dois gramas").
2843
2843
  grama: { singular: 'grama', plural: 'gramas', feminino: false },
2844
- kilo: { singular: 'quilo', plural: 'quilos', feminino: false },
2844
+ quilograma: { singular: 'quilograma', plural: 'quilogramas', feminino: false },
2845
+ metrocubico: { singular: 'metro cúbico', plural: 'metros cúbicos', feminino: false },
2845
2846
  unidade: { singular: 'unidade', plural: 'unidades', feminino: true },
2846
2847
  miligrama: { singular: 'miligrama', plural: 'miligramas', feminino: false },
2847
2848
  litro: { singular: 'litro', plural: 'litros', feminino: false },
@@ -2928,13 +2929,38 @@ class PjcUtils {
2928
2929
  }
2929
2930
  /**
2930
2931
  * Converte unidade de medida para extenso, respeitando gênero.
2932
+ * Para quilograma e litro, a parte decimal é convertida para a subunidade
2933
+ * correspondente (grama e mililitro, respectivamente).
2931
2934
  */
2932
2935
  static unidadeMedidaPorExtenso(valor, unidade) {
2933
2936
  const config = configUnidades[unidade];
2937
+ if (unidade === 'quilograma' || unidade === 'litro') {
2938
+ const resultado = PjcUtils.unidadeComSubunidade(valor, unidade, config);
2939
+ if (resultado)
2940
+ return resultado;
2941
+ }
2934
2942
  const textoNumero = PjcUtils.numeroPorExtenso(valor, config.feminino);
2935
2943
  const textoUnidade = valor === 1 ? config.singular : config.plural;
2936
2944
  return `${textoNumero} ${textoUnidade}`;
2937
2945
  }
2946
+ static unidadeComSubunidade(valor, unidade, config) {
2947
+ const inteiros = Math.floor(valor);
2948
+ const decimal = Math.round((valor - inteiros) * 1000);
2949
+ if (decimal === 0)
2950
+ return null;
2951
+ const partes = [];
2952
+ if (inteiros > 0) {
2953
+ const textoInteiros = PjcUtils.numeroPorExtenso(inteiros, config.feminino);
2954
+ const textoUnidade = inteiros === 1 ? config.singular : config.plural;
2955
+ partes.push(`${textoInteiros} ${textoUnidade}`);
2956
+ }
2957
+ const subUnidade = unidade === 'quilograma' ? 'grama' : 'mililitro';
2958
+ const subConfig = configUnidades[subUnidade];
2959
+ const textoDecimal = PjcUtils.numeroPorExtenso(decimal, subConfig.feminino);
2960
+ const textoSubUnidade = decimal === 1 ? subConfig.singular : subConfig.plural;
2961
+ partes.push(`${textoDecimal} ${textoSubUnidade}`);
2962
+ return partes.join(' e ');
2963
+ }
2938
2964
  }
2939
2965
 
2940
2966
  /*