A Pen by Ashish Vishwakarma on CodePen.
Last active
November 25, 2016 19:07
-
-
Save AshV/3f46db308b56611447f1b84a7810cae2 to your computer and use it in GitHub Desktop.
FetchXML to C# & JS Formatter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div align="center"> | |
<h1>FetchXML Formatter Online</h1> | |
<textarea id="src" placeholder="Paste your fetchXML here." wrap="off"></textarea> | |
<textarea id="cs" placeholder="C# formatted code appears here." wrap="off"></textarea> | |
<textarea id="js" placeholder="JavaScript formatted code appears here." wrap="off"></textarea> | |
<br/> <br/> | |
<a href="https://arunpotti.wordpress.com/2014/11/15/fetchxml-formatter-tool/comment-page-1/" target="_blank">Inspired from Arun's CRM Blog</a> | |
<br/> | |
<a href="http://AshishVishwakarma.com/" target="_blank">Powered by AshV</a> | |
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var srcTxt = document.querySelector("#src"); | |
var csTxt = document.querySelector("#cs"); | |
var jsTxt = document.querySelector("#js"); | |
srcTxt.onkeyup = function() { | |
var srcValue = new String(); | |
srcTxt.value.trim().replace(/"/g, "'").split('\n').forEach(function(line) { | |
if (line.length > 0) { | |
if (line[0] == '+') | |
{} | |
else { | |
if (line[0] == '-') { | |
srcValue += line.substring(1, line.length)+"\n"; | |
} else | |
srcValue += line + "\n"; | |
format(srcValue); | |
} | |
} | |
}); | |
}; | |
var format = function(srcValue) { | |
csTxt.value = ('@"' + srcValue.substring(0, srcValue.length - 1) + '"'); | |
var jstxt = new String(); | |
srcValue.split('\n').forEach(function(line) { | |
jstxt += '"' + line + '"+\n'; | |
}); | |
jsTxt.value = jstxt.substring(0, jstxt.length - 6); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
html, | |
body, | |
div { | |
height: 100%; | |
} | |
textarea { | |
height: 70%; | |
width: 30% | |
} | |
h1, | |
a { | |
color: gray; | |
} | |
a { | |
text-decoration: none; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment