Piccoli helper: GUID, HASH, parseConfig, format e group
jComponent aggiunge alcuni helper che ti evitano di caricare una libreria di utilità:
GUID(length)restituisce un id casuale;HASH(value)restituisce un hash numerico di qualsiasi valore'key:value;key2:value2'.parseConfig()interpreta una stringa di configurazione in un oggetto, convertendo numeri e booleani'{0} is {1}'.format('a', 'b')sostituisce i segnaposto{index}number.format(decimals, thousandsSeparator, decimalSeparator)edate.format('yyyy-MM-dd')formattano numeri e datearray.group('field')raggruppa oggetti per un campo in[{ name, items }]PARSE(json)interpreta JSON e converte le stringhe di data in oggettiDate;date.add('1 day')sposta una data
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>jComponent</title>
<link rel="stylesheet" href="//cdn.componentator.com/spa.min@20.css" />
<script src="//cdn.componentator.com/spa.min@20.js"></script>
</head>
<body>
<p class="out"></p>
<script>
window.sample = {
guid: GUID(12),
samehash: HASH('total') === HASH('total'),
config: 'size:3;active:true;name:Peter'.parseConfig(),
text: '{0} is {1}'.format('Total.js', 'great'),
price: (1234.5).format(2),
date: new Date(2026, 9, 16).format('yyyy-MM-dd'),
groups: [{ type: 'a', n: 1 }, { type: 'b', n: 2 }, { type: 'a', n: 3 }].group('type'),
parsed: PARSE('{"created":"2026-10-16T10:00:00.000Z"}').created instanceof Date,
tomorrow: new Date(2026, 9, 16).add('1 day').getDate()
};
</script>
</body>
</html> Provalo nel tuo browser
Modifica l'esempio ed eseguilo. Gira in un frame isolato del tuo browser; nulla viene inviato al nostro server.
Anteprima