|
Revision 13022, 1.1 kB
(checked in by murky-satyr, 5 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><!-- |
|---|
| 7 | function $(id){ return document.getElementById(id) } |
|---|
| 8 | function txt2html(s){ return s.replace(/ /g, ' ').replace(/\r?\n/g, '<br />') } |
|---|
| 9 | function print(o){ $('out').innerHTML = |
|---|
| 10 | txt2html(o.sup ? o : uneval(o).replace(/,/g, '\n')) } |
|---|
| 11 | function run(evt, elm){ return !evt.shiftKey || evt.keyCode != 13 || |
|---|
| 12 | (print(eval('try{'+ elm.value +'} catch(e){ e }')), !!elm.focus()) } |
|---|
| 13 | onload = function(){ test(function(e){ print('test -> '+ e) }); $('debug').focus() } |
|---|
| 14 | --></script> |
|---|
| 15 | <style> |
|---|
| 16 | body { background-color: #000; color: #ddd } |
|---|
| 17 | b, 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> |
|---|