pjc-fields 0.0.61 → 0.0.63
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 +151 -1
- package/fesm2022/pjc-fields.mjs.map +1 -1
- package/package.json +1 -1
- package/types/pjc-fields.d.ts +20 -2
package/fesm2022/pjc-fields.mjs
CHANGED
|
@@ -2788,6 +2788,156 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
2788
2788
|
args: [{ selector: 'lib-pjc-fields', imports: [], template: ` <p>pjc-fields works!</p> ` }]
|
|
2789
2789
|
}] });
|
|
2790
2790
|
|
|
2791
|
+
const unidadesM = ['', 'um', 'dois', 'três', 'quatro', 'cinco', 'seis', 'sete', 'oito', 'nove'];
|
|
2792
|
+
const unidadesF = ['', 'uma', 'duas', 'três', 'quatro', 'cinco', 'seis', 'sete', 'oito', 'nove'];
|
|
2793
|
+
const dezenasEspeciais = [
|
|
2794
|
+
'dez',
|
|
2795
|
+
'onze',
|
|
2796
|
+
'doze',
|
|
2797
|
+
'treze',
|
|
2798
|
+
'quatorze',
|
|
2799
|
+
'quinze',
|
|
2800
|
+
'dezesseis',
|
|
2801
|
+
'dezessete',
|
|
2802
|
+
'dezoito',
|
|
2803
|
+
'dezenove',
|
|
2804
|
+
];
|
|
2805
|
+
const dezenas = [
|
|
2806
|
+
'',
|
|
2807
|
+
'',
|
|
2808
|
+
'vinte',
|
|
2809
|
+
'trinta',
|
|
2810
|
+
'quarenta',
|
|
2811
|
+
'cinquenta',
|
|
2812
|
+
'sessenta',
|
|
2813
|
+
'setenta',
|
|
2814
|
+
'oitenta',
|
|
2815
|
+
'noventa',
|
|
2816
|
+
];
|
|
2817
|
+
const centenasM = [
|
|
2818
|
+
'',
|
|
2819
|
+
'cento',
|
|
2820
|
+
'duzentos',
|
|
2821
|
+
'trezentos',
|
|
2822
|
+
'quatrocentos',
|
|
2823
|
+
'quinhentos',
|
|
2824
|
+
'seiscentos',
|
|
2825
|
+
'setecentos',
|
|
2826
|
+
'oitocentos',
|
|
2827
|
+
'novecentos',
|
|
2828
|
+
];
|
|
2829
|
+
const centenasF = [
|
|
2830
|
+
'',
|
|
2831
|
+
'cento',
|
|
2832
|
+
'duzentas',
|
|
2833
|
+
'trezentas',
|
|
2834
|
+
'quatrocentas',
|
|
2835
|
+
'quinhentas',
|
|
2836
|
+
'seiscentas',
|
|
2837
|
+
'setecentas',
|
|
2838
|
+
'oitocentas',
|
|
2839
|
+
'novecentas',
|
|
2840
|
+
];
|
|
2841
|
+
const configUnidades = {
|
|
2842
|
+
// Nota: "Grama" (peso) é substantivo masculino ("dois gramas").
|
|
2843
|
+
grama: { singular: 'grama', plural: 'gramas', feminino: false },
|
|
2844
|
+
quilograma: { singular: 'quilograma', plural: 'quilogramas', feminino: false },
|
|
2845
|
+
metrocubico: { singular: 'metro cúbico', plural: 'metros cúbicos', feminino: false },
|
|
2846
|
+
unidade: { singular: 'unidade', plural: 'unidades', feminino: true },
|
|
2847
|
+
miligrama: { singular: 'miligrama', plural: 'miligramas', feminino: false },
|
|
2848
|
+
litro: { singular: 'litro', plural: 'litros', feminino: false },
|
|
2849
|
+
mililitro: { singular: 'mililitro', plural: 'mililitros', feminino: false },
|
|
2850
|
+
centigrama: { singular: 'centigrama', plural: 'centigramas', feminino: false },
|
|
2851
|
+
};
|
|
2852
|
+
class PjcUtils {
|
|
2853
|
+
/**
|
|
2854
|
+
* Converte um número inteiro para extenso.
|
|
2855
|
+
*/
|
|
2856
|
+
static numeroPorExtenso(numero, isFeminino = false) {
|
|
2857
|
+
if (numero === 0)
|
|
2858
|
+
return 'zero';
|
|
2859
|
+
const partes = [];
|
|
2860
|
+
let temp = Math.floor(Math.abs(numero));
|
|
2861
|
+
while (temp > 0) {
|
|
2862
|
+
partes.push(temp % 1000);
|
|
2863
|
+
temp = Math.floor(temp / 1000);
|
|
2864
|
+
}
|
|
2865
|
+
const grandezasSingular = ['', 'mil', 'milhão', 'bilhão'];
|
|
2866
|
+
const grandezasPlural = ['', 'mil', 'milhões', 'bilhões'];
|
|
2867
|
+
const resultado = [];
|
|
2868
|
+
for (let i = 0; i < partes.length; i++) {
|
|
2869
|
+
const valor = partes[i];
|
|
2870
|
+
if (valor === 0)
|
|
2871
|
+
continue;
|
|
2872
|
+
if (i === 1 && valor === 1) {
|
|
2873
|
+
resultado.unshift('mil');
|
|
2874
|
+
}
|
|
2875
|
+
else {
|
|
2876
|
+
const strGrupo = PjcUtils.traduzirGrupo(valor, isFeminino);
|
|
2877
|
+
const grandeza = valor === 1 ? grandezasSingular[i] : grandezasPlural[i];
|
|
2878
|
+
resultado.unshift(grandeza ? `${strGrupo} ${grandeza}` : strGrupo);
|
|
2879
|
+
}
|
|
2880
|
+
}
|
|
2881
|
+
// Junta as casas maiores com vírgula e a última com "e"
|
|
2882
|
+
return resultado
|
|
2883
|
+
.join(', ')
|
|
2884
|
+
.replace(/,([^,]*)$/, ' e$1')
|
|
2885
|
+
.trim();
|
|
2886
|
+
}
|
|
2887
|
+
static traduzirGrupo(n, isFeminino) {
|
|
2888
|
+
if (n === 100)
|
|
2889
|
+
return 'cem';
|
|
2890
|
+
const u = isFeminino ? unidadesF : unidadesM;
|
|
2891
|
+
const c = isFeminino ? centenasF : centenasM;
|
|
2892
|
+
const centena = Math.floor(n / 100);
|
|
2893
|
+
const dezena = Math.floor((n % 100) / 10);
|
|
2894
|
+
const unidade = n % 10;
|
|
2895
|
+
const partes = [];
|
|
2896
|
+
if (centena > 0)
|
|
2897
|
+
partes.push(c[centena]);
|
|
2898
|
+
partes.push(PjcUtils.traduzirDezenaUnidade(dezena, unidade, u));
|
|
2899
|
+
return partes.filter(Boolean).join(' e ');
|
|
2900
|
+
}
|
|
2901
|
+
static traduzirDezenaUnidade(dezena, unidade, u) {
|
|
2902
|
+
if (dezena === 0 && unidade === 0)
|
|
2903
|
+
return '';
|
|
2904
|
+
if (dezena === 1)
|
|
2905
|
+
return dezenasEspeciais[unidade];
|
|
2906
|
+
const partes = [];
|
|
2907
|
+
if (dezena > 1)
|
|
2908
|
+
partes.push(dezenas[dezena]);
|
|
2909
|
+
if (unidade > 0)
|
|
2910
|
+
partes.push(u[unidade]);
|
|
2911
|
+
return partes.join(' e ');
|
|
2912
|
+
}
|
|
2913
|
+
/**
|
|
2914
|
+
* Converte valor monetário para extenso.
|
|
2915
|
+
*/
|
|
2916
|
+
static valorMonetarioPorExtenso(valor, currencyName = 'real', currencyNamePlural = 'reais', centavoSingular = 'centavo', centavoPlural = 'centavos') {
|
|
2917
|
+
const inteiros = Math.floor(valor);
|
|
2918
|
+
const centavos = Math.round((valor - inteiros) * 100);
|
|
2919
|
+
const partes = [];
|
|
2920
|
+
if (inteiros > 0) {
|
|
2921
|
+
const moeda = inteiros === 1 ? currencyName : currencyNamePlural;
|
|
2922
|
+
partes.push(`${PjcUtils.numeroPorExtenso(inteiros)} ${moeda}`);
|
|
2923
|
+
}
|
|
2924
|
+
if (centavos > 0) {
|
|
2925
|
+
const cent = centavos === 1 ? centavoSingular : centavoPlural;
|
|
2926
|
+
partes.push(`${PjcUtils.numeroPorExtenso(centavos)} ${cent}`);
|
|
2927
|
+
}
|
|
2928
|
+
return partes.join(' e ') || `zero ${currencyNamePlural}`;
|
|
2929
|
+
}
|
|
2930
|
+
/**
|
|
2931
|
+
* Converte unidade de medida para extenso, respeitando gênero.
|
|
2932
|
+
*/
|
|
2933
|
+
static unidadeMedidaPorExtenso(valor, unidade) {
|
|
2934
|
+
const config = configUnidades[unidade];
|
|
2935
|
+
const textoNumero = PjcUtils.numeroPorExtenso(valor, config.feminino);
|
|
2936
|
+
const textoUnidade = valor === 1 ? config.singular : config.plural;
|
|
2937
|
+
return `${textoNumero} ${textoUnidade}`;
|
|
2938
|
+
}
|
|
2939
|
+
}
|
|
2940
|
+
|
|
2791
2941
|
/*
|
|
2792
2942
|
* Public API Surface of pjc-fields
|
|
2793
2943
|
*/
|
|
@@ -2796,5 +2946,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
2796
2946
|
* Generated bundle index. Do not edit.
|
|
2797
2947
|
*/
|
|
2798
2948
|
|
|
2799
|
-
export { ESTADOS, PJC_CIDADE_SERVICE, PJC_ENUM_SERVICE, PjcCepFieldComponent, PjcChassiFieldComponent, PjcChassiInputDirective, PjcCidadeFieldComponent, PjcCidadeService, PjcCnhFieldComponent, PjcCnpjFieldComponent, PjcCpfCnpjFieldComponent, PjcCpfFieldComponent, PjcDataFieldComponent, PjcDataHoraFieldComponent, PjcDetalhesComponent, PjcEmailFieldComponent, PjcEnumFieldComponent, PjcEnumService, PjcErroValidacaoComponent, PjcFields, PjcHoraFieldComponent, PjcImeiFieldComponent, PjcIntegerFieldComponent, PjcMoedaFieldComponent, PjcNumeroCartaoFieldComponent, PjcPasswordFieldComponent, PjcPlacaFieldComponent, PjcRenavamFieldComponent, PjcTelefoneFieldComponent, PjcTipoPessoaFieldComponent, PjcUfFieldComponent, PjcUppercaseFieldComponent, PjcValidators, TIPOS_PESSOA };
|
|
2949
|
+
export { ESTADOS, PJC_CIDADE_SERVICE, PJC_ENUM_SERVICE, PjcCepFieldComponent, PjcChassiFieldComponent, PjcChassiInputDirective, PjcCidadeFieldComponent, PjcCidadeService, PjcCnhFieldComponent, PjcCnpjFieldComponent, PjcCpfCnpjFieldComponent, PjcCpfFieldComponent, PjcDataFieldComponent, PjcDataHoraFieldComponent, PjcDetalhesComponent, PjcEmailFieldComponent, PjcEnumFieldComponent, PjcEnumService, PjcErroValidacaoComponent, PjcFields, PjcHoraFieldComponent, PjcImeiFieldComponent, PjcIntegerFieldComponent, PjcMoedaFieldComponent, PjcNumeroCartaoFieldComponent, PjcPasswordFieldComponent, PjcPlacaFieldComponent, PjcRenavamFieldComponent, PjcTelefoneFieldComponent, PjcTipoPessoaFieldComponent, PjcUfFieldComponent, PjcUppercaseFieldComponent, PjcUtils, PjcValidators, TIPOS_PESSOA };
|
|
2800
2950
|
//# sourceMappingURL=pjc-fields.mjs.map
|