Skip to content

Commit

Permalink
bug in parsing multidimentional array fixed.
Browse files Browse the repository at this point in the history
  • Loading branch information
vkiryukhin committed Mar 8, 2012
1 parent 62d9b50 commit 4d468d2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 25 deletions.
9 changes: 5 additions & 4 deletions html/overview.html
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
<table>
<tr><td>
<div class="h6">Overview</div>
<p>vkBeautify is a small, simple and powerfull javascript plugin to beautify ( pretty print )
or minify text in following formats:<b><ul>
<p>vkBeautify is a small, simple and powerfull javascript plugin to <b>beautify</b> ( pretty print )
or <b>minify</b> text in following formats:<b><ul>
<li>XML</li>
<li>JSON</li>
<li>CSS</li>
<li>SQL</li>
</ul>
</b>
.<br/>
This script is also implemented for <b>nodeJS</b> platform as <b>"pretty-data"</b> module.
This script is also implemented for <b>nodeJS</b> platform as
<b><a href="http://www.eslinstructor.net/pretty-data/" target="_blank">"pretty-data"</a></b> module.
</p>
<p><b>Consider to use it if you:</b></p>
<ul>
Expand All @@ -22,7 +23,7 @@

<p><b>This plugin:</b></p>
<ol style="list-style-type:lower-alpha">
<li>less then 3k minified</li>
<li>less then 5k minified</li>
<li>no configuration is needed</li>
<li>simple to use: it is a single function with one parameter</li>
<li>takes less then <b>5 mSec</b> to process 50K text<br/>
Expand Down
36 changes: 15 additions & 21 deletions vkbeautify.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,25 +107,15 @@ vkbeautify.prototype.xml = function(text) {

vkbeautify.prototype.json = function(text) {

var ar = text.replace(/\s{0,}\{\s{0,}/g,"{")
.replace(/\s{0,}\[$/g,"[")
.replace(/\[\s{0,}/g,"[")
.replace(/\s{0,}\}\s{0,}/g,"}")
.replace(/\s{0,}\]\s{0,}/g,"]")
.replace(/\"\s{0,}\,/g,'",')
.replace(/\,\s{0,}\"/g,',"')
.replace(/\"\s{0,}:/g,'":')
.replace(/:\s{0,}\"/g,':"')
.replace(/:\s{0,}\[/g,':[')

.replace(/\{/g,"~::~{~::~")
.replace(/\[/g,"[~::~")
.replace(/\}/g,"~::~}")
.replace(/\]/g,"~::~]")
.replace(/\"\,/g,'",~::~')
.replace(/\,\"/g,',~::~"')
.replace(/~::~\s{0,}~::~/g,"~::~")
.split('~::~'),
var ar = this.jsonmin(text).replace(/\{/g,"~::~{~::~")
.replace(/\[/g,"[~::~")
.replace(/\}/g,"~::~}")
.replace(/\]/g,"~::~]")
.replace(/\"\,/g,'",~::~')
.replace(/\,\"/g,',~::~"')
.replace(/\]\,/g,'],~::~')
.replace(/~::~\s{0,}~::~/g,"~::~")
.split('~::~'),

len = ar.length,
deep = 0,
Expand Down Expand Up @@ -244,7 +234,7 @@ function split_sql(str, tab) {
.split('~::~');
}

vkbeautify.prototype.sql = function(text, brakeOnComma) {
vkbeautify.prototype.sql = function(text) {

var ar_by_quote = text.replace(/\s{1,}/g," ")
.replace(/\'/ig,"~::~\'")
Expand Down Expand Up @@ -318,7 +308,11 @@ vkbeautify.prototype.jsonmin = function(text) {
.replace(/\"\s{0,}\,/g,'",')
.replace(/\,\s{0,}\"/g,',"')
.replace(/\"\s{0,}:/g,'":')
.replace(/:\s{0,}\"/g,':"');
.replace(/:\s{0,}\"/g,':"')
.replace(/:\s{0,}\[/g,':[')
.replace(/\,\s{0,}\[/g,',[')
.replace(/\,\s{2,}/g,', ')
.replace(/\]\s{0,},\s{0,}\[/g,'],[');
}

vkbeautify.prototype.cssmin = function(text, preserveComments) {
Expand Down

0 comments on commit 4d468d2

Please sign in to comment.