diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..a13671c --- /dev/null +++ b/Makefile @@ -0,0 +1,2 @@ +index.js: pretty-data.js + browserify -s pretty-data pretty-data.js > index.js diff --git a/index.js b/index.js new file mode 100644 index 0000000..ecec3e5 --- /dev/null +++ b/index.js @@ -0,0 +1,348 @@ +(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.prettyData = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o\s{0,}<") + .replace(/ or -1) { + str += this.shift[deep]+ar[ix]; + inComment = true; + // end comment or // + if(ar[ix].search(/-->/) > -1 || ar[ix].search(/\]>/) > -1 || ar[ix].search(/!DOCTYPE/) > -1 ) { + inComment = false; + } + } else + // end comment or // + if(ar[ix].search(/-->/) > -1 || ar[ix].search(/\]>/) > -1) { + str += ar[ix]; + inComment = false; + } else + // // + if( /^<\w/.exec(ar[ix-1]) && /^<\/\w/.exec(ar[ix]) && + /^<[\w:\-\.\,]+/.exec(ar[ix-1]) == /^<\/[\w:\-\.\,]+/.exec(ar[ix])[0].replace('/','')) { + str += ar[ix]; + if(!inComment) deep--; + } else + // // + if(ar[ix].search(/<\w/) > -1 && ar[ix].search(/<\//) == -1 && ar[ix].search(/\/>/) == -1 ) { + str = !inComment ? str += this.shift[deep++]+ar[ix] : str += ar[ix]; + } else + // ... // + if(ar[ix].search(/<\w/) > -1 && ar[ix].search(/<\//) > -1) { + str = !inComment ? str += this.shift[deep]+ar[ix] : str += ar[ix]; + } else + // // + if(ar[ix].search(/<\//) > -1) { + str = !inComment ? str += this.shift[--deep]+ar[ix] : str += ar[ix]; + } else + // // + if(ar[ix].search(/\/>/) > -1 ) { + str = !inComment ? str += this.shift[deep]+ar[ix] : str += ar[ix]; + } else + // // + if(ar[ix].search(/<\?/) > -1) { + str += this.shift[deep]+ar[ix]; + } else + // xmlns // + if( ar[ix].search(/xmlns\:/) > -1 || ar[ix].search(/xmlns\=/) > -1) { + str += this.shift[deep]+ar[ix]; + } + + else { + str += ar[ix]; + } + } + + return (str[0] == '\n') ? str.slice(1) : str; +} + +// ----------------------- JSON section ---------------------------------------------------- + +pp.prototype.json = function(text) { + + if ( typeof text === "string" ) { + return JSON.stringify(JSON.parse(text), null, this.step); + } + if ( typeof text === "object" ) { + return JSON.stringify(text, null, this.step); + } + return null; +} + +// ----------------------- CSS section ---------------------------------------------------- + +pp.prototype.css = function(text) { + + var ar = text.replace(/\s{1,}/g,' ') + .replace(/\{/g,"{~::~") + .replace(/\}/g,"~::~}~::~") + .replace(/\;/g,";~::~") + .replace(/\/\*/g,"~::~/*") + .replace(/\*\//g,"*/~::~") + .replace(/~::~\s{0,}~::~/g,"~::~") + .split('~::~'), + len = ar.length, + deep = 0, + str = '', + ix = 0; + + for(ix=0;ix/g,""); + return str.replace(/>\s{0,}<"); +} + +pp.prototype.jsonmin = function(text) { + + return text.replace(/\s{0,}\{\s{0,}/g,"{") + .replace(/\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(/\,\s{0,}\[/g,',[') + .replace(/\,\s{2,}/g,', ') + .replace(/\]\s{0,},\s{0,}\[/g,'],['); +} + +pp.prototype.cssmin = function(text, preserveComments) { + + var str = preserveComments ? text + : text.replace(/\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+\//g,"") ; + return str.replace(/\s{1,}/g,' ') + .replace(/\{\s{1,}/g,"{") + .replace(/\}\s{1,}/g,"}") + .replace(/\;\s{1,}/g,";") + .replace(/\/\*\s{1,}/g,"/*") + .replace(/\*\/\s{1,}/g,"*/"); +} + +pp.prototype.sqlmin = function(text) { + return text.replace(/\s{1,}/g," ").replace(/\s{1,}\(/,"(").replace(/\s{1,}\)/,")"); +} + +// -------------------------------------------------------------------------------------------- + +exports.pd= new pp; + + + +module.exports = new pp; + + + + + + + +},{}]},{},[1])(1) +}); \ No newline at end of file diff --git a/pretty-data.js b/pretty-data.js index 6e53132..01eb5e5 100644 --- a/pretty-data.js +++ b/pretty-data.js @@ -335,7 +335,7 @@ exports.pd= new pp; - +module.exports = new pp;