pjc-fields 0.0.63 → 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.
package/fesm2022/pjc-fields.mjs
CHANGED
|
@@ -2929,13 +2929,38 @@ class PjcUtils {
|
|
|
2929
2929
|
}
|
|
2930
2930
|
/**
|
|
2931
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).
|
|
2932
2934
|
*/
|
|
2933
2935
|
static unidadeMedidaPorExtenso(valor, unidade) {
|
|
2934
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
|
+
}
|
|
2935
2942
|
const textoNumero = PjcUtils.numeroPorExtenso(valor, config.feminino);
|
|
2936
2943
|
const textoUnidade = valor === 1 ? config.singular : config.plural;
|
|
2937
2944
|
return `${textoNumero} ${textoUnidade}`;
|
|
2938
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
|
+
}
|
|
2939
2964
|
}
|
|
2940
2965
|
|
|
2941
2966
|
/*
|