1//------------------------------------------------------------------------------------------------------------------------- 2// format â formateo de moneda, números y fechas (es-AR) 3// Autor: Acosta Simón MartÃn â [email protected] 4// 5// POR QUà EXISTE 6// Antes de la Fase 4 habÃa 32 llamadas sueltas a toLocaleString('es-AR') en las 7// vistas, con 8 combinaciones distintas de opciones. El mismo importe se veÃa 8// con 0, 1 o 2 decimales según la pantalla. Acá la decisión se toma una vez. 9// 10// Se sirve en /assets/js/lib/format.js y expone window.fmt. 11// No depende de nada: se puede copiar a otro proyecto tal cual. 12//------------------------------------------------------------------------------------------------------------------------- 13(function (global) { 14 'use strict'; 15 16 var LOCALE = 'es-AR'; 17 var TZ = 'America/Argentina/Buenos_Aires'; 18 19 function num(v) { 20 var n = Number(v); 21 return isFinite(n) ? n : 0; 22 } 23 24 var fmt = { 25 /** $ 1.234 â importes de pantalla, sin centavos (el caso más común). */ 26 money: function (v) { 27 return '$ ' + Math.round(num(v)).toLocaleString(LOCALE); 28 }, 29 30 /** $ 1.234,56 â cuando los centavos importan (facturación, cuotas). */ 31 moneyExacto: function (v) { 32 return '$ ' + num(v).toLocaleString(LOCALE, { minimumFractionDigits: 2, maximumFractionDigits: 2 }); 33 }, 34 35 /** 1.234,5 â número suelto con los decimales que se pidan (default 0). */ 36 num: function (v, decimales) { 37 var d = decimales == null ? 0 : decimales; 38 return num(v).toLocaleString(LOCALE, { minimumFractionDigits: d, maximumFractionDigits: d }); 39 }, 40 41 /** 12,5% */ 42 pct: function (v, decimales) { 43 return fmt.num(v, decimales == null ? 1 : decimales) + '%'; 44 }, 45 46 /** 21/08/2026 */ 47 fecha: function (v) { 48 if (!v) return ''; 49 return new Date(v).toLocaleDateString(LOCALE, { timeZone: TZ, day: '2-digit', month: '2-digit', year: 'numeric' }); 50 }, 51 52 /** 21 ago, 14:30 */ 53 fechaCorta: function (v) { 54 if (!v) return ''; 55 return new Date(v).toLocaleString(LOCALE, { timeZone: TZ, day: '2-digit', month: 'short', hour: '2-digit', minute: '2-digit' }); 56 }, 57 58 /** viernes, 21 de agosto, 14:30 */ 59 fechaLarga: function (v) { 60 if (!v) return ''; 61 return new Date(v).toLocaleString(LOCALE, { timeZone: TZ, weekday: 'long', day: '2-digit', month: 'long', hour: '2-digit', minute: '2-digit' }); 62 }, 63 64 /** Escapa texto que va a innerHTML. Está acá porque se repetÃa en cada vista. */ 65 esc: function (s) { 66 return String(s == null ? '' : s).replace(/[&<>"']/g, function (c) { 67 return { '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c]; 68 }); 69 }, 70 }; 71 72 global.fmt = fmt; 73})(window);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.