root/lang/javascript/format/format.htm @ 13022

Revision 13022, 1.1 kB (checked in by murky-satyr, 7 years ago)

lang/js/format: init

Line 
1<html><head>
2 <title>String#(?:format|sprintf)</title>
3 <script src="http://svn.coderepos.org/share/lang/javascript/clone/trunk/uneval.js"></script>
4 <script src="./format.js"></script>
5 <script src="./format_test.js"></script>
6 <script><!--
7function $(id){ return document.getElementById(id) }
8function txt2html(s){ return s.replace(/ /g, '&nbsp;').replace(/\r?\n/g, '<br />') }
9function print(o){ $('out').innerHTML =
10  txt2html(o.sup ? o : uneval(o).replace(/,/g, '\n')) }
11function run(evt, elm){ return !evt.shiftKey || evt.keyCode != 13 ||
12  (print(eval('try{'+ elm.value +'} catch(e){ e }')), !!elm.focus()) }
13onload = function(){ test(function(e){ print('test -> '+ e) }); $('debug').focus() }
14 --></script>
15 <style>
16body { background-color: #000; color: #ddd }
17b, textarea { background-color: #666; color: #eee }
18 </style>
19</head><body>
20 <textarea id="debug" onkeypress="return run(event, this)" rows=7 cols=80>
21['%1$.*2$x', // precision is ignored on type `bBoOxX'
22 '%1$.*2$A',
23 'num : %.20f',
24 'prec: %d'].join('\n').format(Math.random(), Math.random()*9|0)
25 </textarea><br />Shift+Enter to eval
26 <pre id="out"></pre>
27</body></html>
Note: See TracBrowser for help on using the browser.