Kleine Helper: GUID, HASH, parseConfig, format und group
jComponent fügt einige Helper hinzu, die dir das Laden einer Utility-Bibliothek ersparen:
GUID(length)liefert eine zufällige ID;HASH(value)liefert einen numerischen Hash eines beliebigen Werts'key:value;key2:value2'.parseConfig()parst einen Konfigurationsstring in ein Objekt und wandelt Zahlen und Booleans um'{0} is {1}'.format('a', 'b')ersetzt{index}-Platzhalternumber.format(decimals, thousandsSeparator, decimalSeparator)unddate.format('yyyy-MM-dd')formatieren Zahlen und Datumswertearray.group('field')gruppiert Objekte nach einem Feld in[{ name, items }]PARSE(json)parst JSON und wandelt Datums-Strings inDate-Objekte um;date.add('1 day')verschiebt ein Datum
<!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> Probiere es in deinem Browser aus
Bearbeite das Beispiel und führe es aus. Es läuft in einem isolierten Frame in deinem Browser; nichts wird an unseren Server gesendet.
Vorschau