@jvsoft/utils 0.0.13-alpha.5 → 0.0.13-alpha.6
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/jvsoft-utils-src-functions.mjs +60 -1
- package/fesm2022/jvsoft-utils-src-functions.mjs.map +1 -1
- package/fesm2022/jvsoft-utils.mjs +60 -1
- package/fesm2022/jvsoft-utils.mjs.map +1 -1
- package/functions/base64.d.ts +24 -0
- package/package.json +9 -16
- package/src/functions/base64.d.ts +24 -0
|
@@ -519,6 +519,65 @@ function b64Encode(val) {
|
|
|
519
519
|
function b64Decode(val) {
|
|
520
520
|
return Buffer.from(val, 'base64').toString('binary');
|
|
521
521
|
}
|
|
522
|
+
/**
|
|
523
|
+
* Codificar string a Base64 (UTF-8 seguro)
|
|
524
|
+
*/
|
|
525
|
+
function encodeBase64String(str) {
|
|
526
|
+
const encoder = new TextEncoder();
|
|
527
|
+
const bytes = encoder.encode(str);
|
|
528
|
+
let binary = '';
|
|
529
|
+
bytes.forEach(b => binary += String.fromCharCode(b));
|
|
530
|
+
return btoa(binary);
|
|
531
|
+
}
|
|
532
|
+
/**
|
|
533
|
+
* Decodificar Base64 a string (UTF-8 seguro)
|
|
534
|
+
*/
|
|
535
|
+
function decodeBase64String(b64) {
|
|
536
|
+
const binary = atob(b64);
|
|
537
|
+
const bytes = new Uint8Array(binary.length);
|
|
538
|
+
for (let i = 0; i < binary.length; i++) {
|
|
539
|
+
bytes[i] = binary.charCodeAt(i);
|
|
540
|
+
}
|
|
541
|
+
const decoder = new TextDecoder();
|
|
542
|
+
return decoder.decode(bytes);
|
|
543
|
+
}
|
|
544
|
+
/**
|
|
545
|
+
* Codificar un objeto a base64 (UTF-8 seguro)
|
|
546
|
+
*/
|
|
547
|
+
function encodeBase64Object(obj) {
|
|
548
|
+
return encodeBase64String(JSON.stringify(obj));
|
|
549
|
+
}
|
|
550
|
+
/**
|
|
551
|
+
* Decodificar un base64 y obtener el objeto original
|
|
552
|
+
*/
|
|
553
|
+
function decodeBase64Object(b64) {
|
|
554
|
+
return JSON.parse(decodeBase64String(b64));
|
|
555
|
+
}
|
|
556
|
+
/**
|
|
557
|
+
* Codificar archivo a Base64 (retorna solo el contenido, sin "data:...")
|
|
558
|
+
*/
|
|
559
|
+
function encodeBase64File(file) {
|
|
560
|
+
return new Promise((resolve, reject) => {
|
|
561
|
+
const reader = new FileReader();
|
|
562
|
+
reader.onload = () => {
|
|
563
|
+
const result = reader.result;
|
|
564
|
+
resolve(result.split(',')[1]); // quita el prefijo "data:...;base64,"
|
|
565
|
+
};
|
|
566
|
+
reader.onerror = reject;
|
|
567
|
+
reader.readAsDataURL(file);
|
|
568
|
+
});
|
|
569
|
+
}
|
|
570
|
+
/**
|
|
571
|
+
* Decodificar Base64 a Blob (para reconstruir archivos en Angular)
|
|
572
|
+
*/
|
|
573
|
+
function decodeBase64ToBlob(b64, mimeType = 'application/octet-stream') {
|
|
574
|
+
const byteChars = atob(b64);
|
|
575
|
+
const byteNumbers = new Array(byteChars.length);
|
|
576
|
+
for (let i = 0; i < byteChars.length; i++) {
|
|
577
|
+
byteNumbers[i] = byteChars.charCodeAt(i);
|
|
578
|
+
}
|
|
579
|
+
return new Blob([new Uint8Array(byteNumbers)], { type: mimeType });
|
|
580
|
+
}
|
|
522
581
|
|
|
523
582
|
function getBrowserName() {
|
|
524
583
|
const agent = window.navigator.userAgent.toLowerCase();
|
|
@@ -1804,5 +1863,5 @@ function zeroFill(value, digitos, ...args) {
|
|
|
1804
1863
|
* Generated bundle index. Do not edit.
|
|
1805
1864
|
*/
|
|
1806
1865
|
|
|
1807
|
-
export { DataEnListaPipe, DataModel, DateDiffStringPipe, FiltroPipe, FormControlIsRequiredPipe, JsonParsePipe, NoSanitizePipe, TipoValorFuncionPipe, ZeroFillPipe, b64Decode, b64Encode, buscarPorCampo, changeSelect, changeSelectApi, changeSelectData, changeSelectDataApi, changeSelectReformateado, convertirBytes, dataEnLista, dateDiffString, deepClone, deepMerge, delLocalStorage, desencriptar, downLoadFileStream, eliminarColumnaPorIndex, eliminarDuplicados, eliminarElementos, encriptar, esNumero, establecerQuitarRequired, extraerDominio, formControlIsRequired, formatearFecha, formatearFechaCadena, formatearFechaFormato, generateRandomString, getBrowserName, getCambiarPwd, getDataArchivoFromPath, getFormValidationErrors, getLocalStorage, getUniqueValues, getUniqueValuesByProperty, groupBy, inicializarVariablesSessionStorage, isEmail, jwtToken, jwtTokenData, jwtTokenExpiracion, jwtTokenExpiracionFaltante, localStorageKeys, markAsTouchedWithoutEmitEvent, maskEmail, mensajeAlerta, mensajeConfirmacion, mensajeTimer, mensajeToast, mensajesDeError, mensajesErrorFormControl, mostrarValorEnBusqueda, nestGroupsBy, numberToWords, objectPropertiesBoolean, objectPropertiesToType, obtenerHostDesdeUrl, obtenerMimeType, obtenerUltimoOrden, ordenarArray, ordenarPorPropiedad, ordenarPorPropiedades, roundToDecimal, sanitizarNombreArchivo, seleccionarTextoInput, setCambiarPwd, setControlDesdeLista, setJwtTokenData, setLocalStorage, sumarObjetos, sumarPropiedades, tipoValorFuncion, toFormData, transformarFechasPorNombreDeCampo, verificarRUC, zeroFill };
|
|
1866
|
+
export { DataEnListaPipe, DataModel, DateDiffStringPipe, FiltroPipe, FormControlIsRequiredPipe, JsonParsePipe, NoSanitizePipe, TipoValorFuncionPipe, ZeroFillPipe, b64Decode, b64Encode, buscarPorCampo, changeSelect, changeSelectApi, changeSelectData, changeSelectDataApi, changeSelectReformateado, convertirBytes, dataEnLista, dateDiffString, decodeBase64Object, decodeBase64String, decodeBase64ToBlob, deepClone, deepMerge, delLocalStorage, desencriptar, downLoadFileStream, eliminarColumnaPorIndex, eliminarDuplicados, eliminarElementos, encodeBase64File, encodeBase64Object, encodeBase64String, encriptar, esNumero, establecerQuitarRequired, extraerDominio, formControlIsRequired, formatearFecha, formatearFechaCadena, formatearFechaFormato, generateRandomString, getBrowserName, getCambiarPwd, getDataArchivoFromPath, getFormValidationErrors, getLocalStorage, getUniqueValues, getUniqueValuesByProperty, groupBy, inicializarVariablesSessionStorage, isEmail, jwtToken, jwtTokenData, jwtTokenExpiracion, jwtTokenExpiracionFaltante, localStorageKeys, markAsTouchedWithoutEmitEvent, maskEmail, mensajeAlerta, mensajeConfirmacion, mensajeTimer, mensajeToast, mensajesDeError, mensajesErrorFormControl, mostrarValorEnBusqueda, nestGroupsBy, numberToWords, objectPropertiesBoolean, objectPropertiesToType, obtenerHostDesdeUrl, obtenerMimeType, obtenerUltimoOrden, ordenarArray, ordenarPorPropiedad, ordenarPorPropiedades, roundToDecimal, sanitizarNombreArchivo, seleccionarTextoInput, setCambiarPwd, setControlDesdeLista, setJwtTokenData, setLocalStorage, sumarObjetos, sumarPropiedades, tipoValorFuncion, toFormData, transformarFechasPorNombreDeCampo, verificarRUC, zeroFill };
|
|
1808
1867
|
//# sourceMappingURL=jvsoft-utils.mjs.map
|