pjc-fields 0.0.65 → 0.0.66
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 +29 -0
- package/fesm2022/pjc-fields.mjs.map +1 -1
- package/package.json +1 -1
- package/types/pjc-fields.d.ts +13 -0
package/fesm2022/pjc-fields.mjs
CHANGED
|
@@ -2992,6 +2992,35 @@ class PjcUtils {
|
|
|
2992
2992
|
const ultimo = partes.pop();
|
|
2993
2993
|
return `${partes.join(', ')} e ${ultimo}`;
|
|
2994
2994
|
}
|
|
2995
|
+
/**
|
|
2996
|
+
* Converte múltiplas unidades de volume para extenso em uma única string.
|
|
2997
|
+
* Todos os parâmetros são opcionais. Os valores informados são convertidos
|
|
2998
|
+
* para extenso e concatenados com vírgulas e "e" antes do último item.
|
|
2999
|
+
*
|
|
3000
|
+
* Exemplo:
|
|
3001
|
+
* PjcUtils.volumePorExtenso({ litro: 2, mililitro: 500 })
|
|
3002
|
+
* // => "dois litros e quinhentos mililitros"
|
|
3003
|
+
*/
|
|
3004
|
+
static volumePorExtenso(params) {
|
|
3005
|
+
const mapeamento = [
|
|
3006
|
+
{ chave: 'litro', unidade: 'litro' },
|
|
3007
|
+
{ chave: 'mililitro', unidade: 'mililitro' },
|
|
3008
|
+
];
|
|
3009
|
+
const partes = [];
|
|
3010
|
+
for (const { chave, unidade } of mapeamento) {
|
|
3011
|
+
const valor = params[chave];
|
|
3012
|
+
if (valor != null && valor > 0) {
|
|
3013
|
+
partes.push(PjcUtils.unidadeMedidaPorExtenso(valor, unidade));
|
|
3014
|
+
}
|
|
3015
|
+
}
|
|
3016
|
+
if (partes.length === 0)
|
|
3017
|
+
return '';
|
|
3018
|
+
if (partes.length === 1)
|
|
3019
|
+
return partes[0];
|
|
3020
|
+
// Junta com vírgulas e "e" antes do último item
|
|
3021
|
+
const ultimo = partes.pop();
|
|
3022
|
+
return `${partes.join(', ')} e ${ultimo}`;
|
|
3023
|
+
}
|
|
2995
3024
|
}
|
|
2996
3025
|
|
|
2997
3026
|
/*
|