pjc-fields 0.0.64 → 0.0.65
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 +31 -0
- package/fesm2022/pjc-fields.mjs.map +1 -1
- package/package.json +1 -1
- package/types/pjc-fields.d.ts +15 -0
package/fesm2022/pjc-fields.mjs
CHANGED
|
@@ -2961,6 +2961,37 @@ class PjcUtils {
|
|
|
2961
2961
|
partes.push(`${textoDecimal} ${textoSubUnidade}`);
|
|
2962
2962
|
return partes.join(' e ');
|
|
2963
2963
|
}
|
|
2964
|
+
/**
|
|
2965
|
+
* Converte múltiplas unidades de massa para extenso em uma única string.
|
|
2966
|
+
* Todos os parâmetros são opcionais. Os valores informados são convertidos
|
|
2967
|
+
* para extenso e concatenados com vírgulas e "e" antes do último item.
|
|
2968
|
+
*
|
|
2969
|
+
* Exemplo:
|
|
2970
|
+
* PjcUtils.massaPorExtenso({ quilograma: 1, grama: 200, miligrama: 100, centigrama: 500 })
|
|
2971
|
+
* // => "um quilograma, duzentos gramas, cem miligramas e quinhentos centigramas"
|
|
2972
|
+
*/
|
|
2973
|
+
static massaPorExtenso(params) {
|
|
2974
|
+
const mapeamento = [
|
|
2975
|
+
{ chave: 'quilograma', unidade: 'quilograma' },
|
|
2976
|
+
{ chave: 'grama', unidade: 'grama' },
|
|
2977
|
+
{ chave: 'miligrama', unidade: 'miligrama' },
|
|
2978
|
+
{ chave: 'centigrama', unidade: 'centigrama' },
|
|
2979
|
+
];
|
|
2980
|
+
const partes = [];
|
|
2981
|
+
for (const { chave, unidade } of mapeamento) {
|
|
2982
|
+
const valor = params[chave];
|
|
2983
|
+
if (valor != null && valor > 0) {
|
|
2984
|
+
partes.push(PjcUtils.unidadeMedidaPorExtenso(valor, unidade));
|
|
2985
|
+
}
|
|
2986
|
+
}
|
|
2987
|
+
if (partes.length === 0)
|
|
2988
|
+
return '';
|
|
2989
|
+
if (partes.length === 1)
|
|
2990
|
+
return partes[0];
|
|
2991
|
+
// Junta com vírgulas e "e" antes do último item
|
|
2992
|
+
const ultimo = partes.pop();
|
|
2993
|
+
return `${partes.join(', ')} e ${ultimo}`;
|
|
2994
|
+
}
|
|
2964
2995
|
}
|
|
2965
2996
|
|
|
2966
2997
|
/*
|