Text Transformation Utility
by Josh Carroll
HTML
<script src="http://code.angularjs.org/1.2.0-rc.3/angular.min.js"></script>
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css">
<script src="http://code.angularjs.org/1.2.0-rc.3/angular-route.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/2.4.1/lodash.js"></script>
<div data-ng-controller="transformCtrl as ctrl">
<form role="form">
<div class="form-group">
<label for="transforms">Input</label>
<select id="transforms" class="form-control" rows="6" data-ng-model="ctrl.selectedTransformation" data-ng-options="t.name for t in ctrl.transformations">
<option value="">-- choose transform --</option>
</select>
</div>
<div class="form-group" data-ng-repeat="option in ctrl.selectedTransformation.options">
<label>{{option.name}}</label>
<textarea class="form-control" data-ng-model="option.val" rows="2"></textarea>
</div>
<div class="form-group">
<label for="tbInput">Input</label>
<textarea id="tbInput" class="form-control" rows="6" data-ng-model="ctrl.input"></textarea>
</div>
<div class="form-group" data-ng-class="{'has-error':ctrl.hasError()}">
<label for="tbOutput">Output</label>
<textarea id="tbOutput" class="form-control" rows="6" data-ng-model="ctrl.output"></textarea>
</div>
<div class="alert alert-danger" data-ng-show="ctrl.hasError()">{{ctrl.error}}</div>
<button type="button" class="btn btn-default" data-ng-click="ctrl.transform()">Submit</button>
</form>
</div>
JavaScript
var Controllers;
(function (Controllers) {
var TransformCtrl = function (utilService) {
this.input = "";
this.output = "";
this.error = undefined;
this.utilService = utilService;
this.selectedTransformation = null;
this.transformations = [{
name: 'To TypeScript Properties',
transformFunctions: [
this.splitWhiteSpace,
this.filterBenchmark,
this.camelCase,
this.surroundWith,
this.joinNewline]
}, {
name: 'To C# Schema Definition',
transformFunctions: [
this.splitWhiteSpace,
this.filterBenchmark,
this.createFormatter("public static readonly String {item} = \"{item}\";"),
this.joinNewline]
}, {
name: 'To C# Properties',
transformFunctions: [
this.splitWhiteSpace,
this.filterBenchmark,
this.createFormatter("public Object {item} { get; set; }"),
this.joinNewline]
}, {
name: 'To C# Reader Assignment Statements',
transformFunctions: [
this.splitWhiteSpace,
this.filterBenchmark,
this.createFormatter("this.{item} = sqlDataReader.GetAs<String>(TopAndBottomFiveSchema.{item});"),
this.joinNewline]
}, {
name: "JSON String To TypeScript Properties",
transformFunctions: [
this.toJSON,
this.objectPropertiesToList,
this.alphabetize,
this.createFormatter("{item}: string;"),
this.joinNewline]
}, {
name: "CSV Names to JS object",
transformFunctions: [
this.splitComma,
this.camelCase,
this.createFormatter("this.{item} = fields[{index}];"),
this.joinNewline]
}, {
name: "Expand Template",
options: {
...