forked from prettydiff/prettydiff
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprettydiff.js
1704 lines (1679 loc) · 132 KB
/
prettydiff.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*prettydiff.com api.topcoms: true, api.insize: 4, api.inchar: " ", api.vertical: true */
/*global __dirname, ace, csspretty, csvpretty, define, diffview, exports, global, jspretty, markuppretty, process, require, safeSort */
/*jslint for: true*/
/*
Execute in a NodeJS app:
npm install prettydiff (local install)
var prettydiff = require("prettydiff"),
args = {
source: "asdf",
diff : "asdd",
lang : "text"
},
output = prettydiff.api(args);
Execute on command line with NodeJS:
npm install prettydiff -g (global install)
prettydiff source:"c:\mydirectory\myfile.js" readmethod:"file" diff:"c:\myotherfile.js"
Execute with WSH:
cscript prettydiff.wsf /source:"myFile.xml" /mode:"beautify"
Execute from JavaScript:
var args = {
source: "asdf",
diff : "asdd",
lang : "text"
},
output = prettydiff(args);
******* license start *******
@source: http://prettydiff.com/prettydiff.js
@documentation - English: http://prettydiff.com/documentation.php
@licstart The following is the entire license notice for Pretty Diff.
This code may not be used or redistributed unless the following
conditions are met:
* Prettydiff created by Austin Cheney originally on 3 Mar 2009.
http://prettydiff.com/
* The use of diffview.js and prettydiff.js must contain the following
copyright:
Copyright (c) 2007, Snowtide Informatics Systems, Inc.
All rights reserved.
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the
distribution.
- Neither the name of the Snowtide Informatics Systems nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written
permission.
- used as diffview function
http://prettydiff.com/lib/diffview.js
* The code mentioned above has significantly expanded documentation in
each of the respective function's external JS file as linked from the
documentation page:
http://prettydiff.com/documentation.php
* In addition to the previously stated requirements any use of any
component, aside from directly using the full files in their entirety,
must restate the license mentioned at the top of each concerned file.
If each and all these conditions are met use, extension, alteration,
and redistribution of Pretty Diff and its required assets is unlimited
and free without author permission.
@licend The above is the entire license notice for Pretty Diff.
******* license end *******
Join the Pretty Diff mailing list at:
https://groups.google.com/d/forum/pretty-diff
Special thanks to:
* Harry Whitfield for the numerous test cases provided against
JSPretty. http://g6auc.me.uk/
* Andreas Greuel for contributing samples to test diffview.js
https://plus.google.com/105958105635636993368/posts
*/
if (typeof require === "function" && typeof ace !== "object") {
(function glib_prettydiff() {
"use strict";
var localPath = (typeof process === "object" && process.cwd() === "/" && typeof __dirname === "string")
? __dirname
: ".";
if (global.csspretty === undefined) {
global.csspretty = require(localPath + "/lib/csspretty.js").api;
}
if (global.csvpretty === undefined) {
global.csvpretty = require(localPath + "/lib/csvpretty.js").api;
}
if (global.diffview === undefined) {
global.diffview = require(localPath + "/lib/diffview.js").api;
}
if (global.jspretty === undefined) {
global.jspretty = require(localPath + "/lib/jspretty.js").api;
}
if (global.markuppretty === undefined) {
global.markuppretty = require(localPath + "/lib/markuppretty.js").api;
}
if (global.safeSort === undefined) {
global.safeSort = require(localPath + "/lib/safeSort.js").api;
}
}());
} else {
global.csspretty = csspretty;
global.csvpretty = csvpretty;
global.diffview = diffview;
global.jspretty = jspretty;
global.markuppretty = markuppretty;
global.safeSort = safeSort;
}
var prettydiff = function prettydiff_(api) {
"use strict";
var startTime = (typeof Date.now === "function")
? Date.now()
: (function prettydiff__dateShim() {
var dateItem = new Date;
return Date.parse(dateItem);
}()),
core = function core_(api) {
var spacetest = (/^\s+$/g),
apioutput = "",
apidiffout = "",
builder = {},
setlangmode = function core__langkey_setlangmode(input) {
if (input === "css" || input === "less" || input === "scss") {
return "css";
}
if (input.indexOf("html") > -1 || input === "html" || input === "ejs" || input === "html_ruby" || input === "handlebars" || input === "swig" || input === "twig" || input === "php" || input === "dustjs") {
return "html";
}
if (input === "markup" || input === "jsp" || input === "xml" || input === "xhtml") {
return "markup";
}
if (input === "javascript" || input === "json" || input === "jsx") {
return "javascript";
}
if (input === "text") {
return "text";
}
if (input === "csv") {
return "csv";
}
if (input === "tss" || input === "titanium") {
return "tss";
}
return "javascript";
},
nameproper = function core__langkey_nameproper(input) {
if (input === "javascript") {
return "JavaScript";
}
if (input === "text") {
return "Plain Text";
}
if (input === "jsx") {
return "React JSX";
}
if (input === "scss") {
return "SCSS (Sass)";
}
if (input === "ejs") {
return "EJS Template";
}
if (input === "handlebars") {
return "Handlebars Template";
}
if (input === "html_ruby") {
return "ERB (Ruby) Template";
}
if (input === "tss" || input === "titanium") {
return "Titanium Stylesheets";
}
if (input === "typescript") {
return "TypeScript (not supported yet)";
}
if (input === "twig") {
return "HTML TWIG Template";
}
if (input === "jsp") {
return "JSTL (JSP)";
}
if (input === "java") {
return "Java (not supported yet)";
}
return input.toUpperCase();
},
options = {
//determines api source as necessary to make a decision about whether to supply
//externally needed JS functions to reports
accessibility : (api.accessibility === true || api.accessibility === "true"),
api : (api.api === undefined || api.api.length === 0)
? ""
: api.api,
//braceline - should a new line pad the interior of blocks (curly braces) in
//JavaScript
braceline : (api.braceline === true || api.braceline === "true"),
//bracepadding - should curly braces be padded with a space in JavaScript?
bracepadding : (api.bracepadding === true || api.bracepadding === "true"),
//indent - should JSPretty format JavaScript in the normal KNR style or push
//curly braces onto a separate line like the "allman" style
braces : (api.braces === "allman")
? "allman"
: "knr",
//comments - if comments should receive indentation or not
comments : (api.comments === "noindent")
? "noindent"
: ((api.comments === "nocomment")
? "nocomment"
: "indent"),
//commline - If in markup a newline should be forced above comments
commline : (api.commline === true || api.commline === "true"),
//conditional - should IE conditional comments be preserved during markup
//minification
conditional : (api.conditional === true || api.conditional === "true"),
//content - should content be normalized during a diff operation
content : (api.content === true || api.content === "true"),
//context - should the diff report only include the differences, if so then
//buffered by how many lines of code
context : (api.context === "" || (/^(\s+)$/).test(api.context) || isNaN(api.context))
? ""
: Number(api.context),
//correct - should JSPretty make some corrections for sloppy JS
correct : (api.correct === true || api.correct === "true"),
//cssinsertlines = if a new line should be forced between each css block
cssinsertlines: (api.cssinsertlines === true || api.cssinsertlines === "true"),
//csvchar - what character should be used as a separator
csvchar : (typeof api.csvchar === "string" && api.csvchar.length > 0)
? api.csvchar
: ",",
//diff - source code to compare with
diff : (typeof api.diff === "string" && api.diff.length > 0 && (/^(\s+)$/).test(api.diff) === false)
? api.diff
: "",
//diffcli - if operating from Node.js and set to true diff output will be
//printed to stdout just like git diff
diffcli : (api.diffcli === true || api.diffcli === "true"),
//diffcomments - should comments be included in the diff operation
diffcomments : (api.diffcomments === true || api.diffcomments === "true"),
//difflabel - a text label to describe the diff code
difflabel : (typeof api.difflabel === "string" && api.difflabel.length > 0)
? api.difflabel
: "new",
//diffview - should the diff report be a single column showing both sources
//simultaneously "inline" or showing the sources in separate columns
//"sidebyside"
diffview : (api.diffview === "inline")
? "inline"
: "sidebyside",
//dustjs - support for this specific templating scheme
dustjs : (api.dustjs === true || api.dustjs === "true"),
//elseline - for the 'else' keyword onto a new line in JavaScript
elseline : (api.elseline === true || api.elseline === "true"),
//endcomma - if a trailing comma should be injected at the end of arrays and
//object literals in JavaScript
endcomma : (api.endcomma === true || api.endcomma === "true"),
//force_indent - should markup beautification always force indentation even if
//disruptive
force_indent : (api.force_indent === true || api.force_indent === "true"),
//html - should markup be presumed to be HTML with all the aloppiness HTML
//allows
html : (api.html === true || api.html === "true" || (typeof api.html === "string" && api.html === "html-yes")),
//inchar - what character should be used to create a single identation
inchar : (typeof api.inchar === "string" && api.inchar.length > 0)
? api.inchar
: " ",
//inlevel - should indentation in JSPretty be buffered with additional
//indentation? Useful when supplying code to sites accepting markdown
inlevel : (isNaN(api.inlevel) || Number(api.inlevel) < 1)
? 0
: Number(api.inlevel),
//insize - how many characters from api.inchar should constitute a single
//indentation
insize : (isNaN(api.insize))
? 4
: Number(api.insize),
//jsscope - do you want to enable the jsscope feature of JSPretty? This feature
//will output formatted HTML instead of text code showing which variables are
//declared at which functional depth
jsscope : (api.jsscope === true || api.jsscope === "true")
? "report"
: (api.jsscope !== "html" && api.jsscope !== "report")
? "none"
: api.jsscope,
//lang - which programming language will we be analyzing
lang : (typeof api.lang === "string" && api.lang !== "auto")
? setlangmode(api.lang.toLowerCase())
: "auto",
//langdefault - what language should lang value "auto" resort to when it cannot
//determine the language
langdefault : (typeof api.langdefault === "string")
? setlangmode(api.langdefault.toLowerCase())
: "text",
//methodchain - if JavaScript method chains should be strung onto a single line
//instead of indented
methodchain : (api.methodchain === true || api.methodchain === "true"),
//miniwrap - when language is JavaScript and mode is 'minify' if option 'jwrap'
//should be applied to all code
miniwrap : (api.miniwrap === true || api.miniwrap === "true"),
//mode - is this a minify, beautify, or diff operation
mode : (typeof api.mode === "string" && (api.mode === "minify" || api.mode === "beautify" || api.mode === "parse"))
? api.mode
: "diff",
//noleadzero - in CSS removes and prevents a run of 0s from appearing
//immediately before a value's decimal.
noleadzero : (api.noleadzero === true || api.noleadzero === "true"),
//objsort will alphabetize object keys in JavaScript
objsort : (api.objsort === "all"),
//preserve - should empty lines be preserved in beautify operations of JSPretty?
preserve : (api.preserve === "all"),
//quote - should all single quote characters be converted to double quote
//characters during a diff operation to reduce the number of false positive
//comparisons
quote : (api.quote === true || api.quote === "true"),
//quoteConvert - convert " to ' (or ' to ") of string literals or markup
//attributes
quoteConvert : (api.quoteConvert === "single" || api.quoteConvert === "double")
? api.quoteConvert
: "none",
//semicolon - should trailing semicolons be removed during a diff operation to
//reduce the number of false positive comparisons
semicolon : (api.semicolon === true || api.semicolon === "true"),
//source - the source code in minify and beautify operations or "base" code in
//operations
source : (typeof api.source === "string" && api.source.length > 0 && (/^(\s+)$/).test(api.source) === false)
? api.source
: "",
//sourcelabel - a text label to describe the api.source code for the diff report
sourcelabel : (typeof api.sourcelabel === "string" && api.sourcelabel.length > 0)
? api.sourcelabel
: "base",
//space - should JSPretty include a space between a function keyword and the
//next adjacent opening parenthesis character in beautification operations
space : (api.space !== false && api.space !== "false"),
//spaceclose - If markup self-closing tags should end with " />" instead of "/>"
spaceclose : (api.spaceclose === true || api.spaceclose === "true"),
//style - should JavaScript and CSS code receive indentation if embedded inline
//in markup
style : (api.style === "noindent")
? "noindent"
: "indent",
//styleguide - preset of beautification options to bring a JavaScript sample
//closer to conformance of a given style guide
styleguide : (typeof api.styleguide === "string")
? api.styleguide
: "",
//tagmerge - Allows combining immediately adjacent start and end tags of the
//same name into a single self-closing tag: <a href="home"></a> into
//<a//href="home"/>
tagmerge : (api.tagmerge === true || api.tagmerge === "true"),
//sort markup child nodes alphabetically
tagsort : (api.tagsort === true || api.tagsort === "true"),
//textpreserve - Force the markup beautifier to retain text (white space and
//all) exactly as provided.
textpreserve : (api.textpreserve === true || api.textpreserve === "true"),
//titanium - TSS document support via option, because this is a uniquely
//modified form of JSON
titanium : (api.titanium === true || api.titanium === "true"),
//topcoms - should comments at the top of a JavaScript or CSS source be
//preserved during minify operations
topcoms : (api.topcoms === true || api.topcoms === "true"),
//varword - should consecutive variables be merged into a comma separated list
//or the opposite
varword : (api.varword === "each" || api.varword === "list")
? api.varword
: "none",
//vertical - whether or not to vertically align lists of assigns in CSS and
//JavaScript
vertical : (api.vertical === "all"),
//wrap - in markup beautification should text content wrap after the first
//complete word up to a certain character length
wrap : (isNaN(api.wrap) === true)
? 80
: Number(api.wrap)
},
autoval = [],
autostring = "",
auto = function core__auto(a) {
var b = [],
c = 0,
d = 0,
join = "",
flaga = false,
flagb = false,
output = function core__langkey_auto_output(langname) {
if (langname === "unknown") {
return [options.langdefault, setlangmode(options.langdefault), "unknown"];
}
if (langname === "xhtml") {
return ["xml", "html", "XHTML"];
}
if (langname === "tss") {
return ["tss", "tss", "Titanium Stylesheets"];
}
return [langname, setlangmode(langname), nameproper(langname)];
};
if (a === null) {
return;
}
if (a === undefined || (/^(\s*#(?!(!\/)))/).test(a) === true || (/\n\s*(\.|@)mixin\(?(\s*)/).test(a) === true) {
if ((/\$[a-zA-Z]/).test(a) === true || (/\{\s*(\w|\.|\$|#)+\s*\{/).test(a) === true) {
return output("scss");
}
if ((/@[a-zA-Z]/).test(a) === true || (/\{\s*(\w|\.|@|#)+\s*\{/).test(a) === true) {
return output("less");
}
return output("css");
}
b = a.replace(/\[[a-zA-Z][\w\-]*\=("|')?[a-zA-Z][\w\-]*("|')?\]/g, "")
.split("");
c = b.length;
if ((/^([\s\w\-]*<)/).test(a) === false && (/(>[\s\w\-]*)$/).test(a) === false) {
for (d = 1; d < c; d += 1) {
if (flaga === false) {
if (b[d] === "*" && b[d - 1] === "/") {
b[d - 1] = "";
flaga = true;
} else if (flagb === false && b[d] === "f" && d < c - 6 && b[d + 1] === "i" && b[d + 2] === "l" && b[d + 3] === "t" && b[d + 4] === "e" && b[d + 5] === "r" && b[d + 6] === ":") {
flagb = true;
}
} else if (flaga === true && b[d] === "*" && d !== c - 1 && b[d + 1] === "/") {
flaga = false;
b[d] = "";
b[d + 1] = "";
} else if (flagb === true && b[d] === ";") {
flagb = false;
b[d] = "";
}
if (flaga === true || flagb === true) {
b[d] = "";
}
}
join = b.join("");
if ((/^(\s*(\{|\[))/).test(a) === true && (/((\]|\})\s*)$/).test(a) && a.indexOf(",") !== -1) {
return output("json");
}
if ((/((\}?(\(\))?\)*;?\s*)|([a-z0-9]("|')?\)*);?(\s*\})*)$/i).test(a) === true && ((/(var\s+(\w|\$)+[a-zA-Z0-9]*)/).test(a) === true || (/console\.log\(/).test(a) === true || (/document\.get/).test(a) === true || (/((\=|(\$\())\s*function)|(\s*function\s+(\w*\s+)?\()/).test(a) === true || a.indexOf("{") === -1 || (/^(\s*if\s+\()/).test(a) === true)) {
if (a.indexOf("(") > -1 || a.indexOf("=") > -1 || (a.indexOf(";") > -1 && a.indexOf("{") > -1)) {
if ((/:\s*((number)|(string))/).test(a) === true && (/((public)|(private))\s+/).test(a) === true) {
return output("typescript");
}
return output("javascript");
}
return output("unknown");
}
if (a.indexOf("{") !== -1 && (/^(\s*[\{\$\.#@a-z0-9])|^(\s*\/(\*|\/))|^(\s*\*\s*\{)/i).test(a) === true && (/^(\s*if\s*\()/).test(a) === false && (/\=\s*(\{|\[|\()/).test(join) === false && (((/(\+|-|\=|\?)\=/).test(join) === false || (/\/\/\s*\=+/).test(join) === true) || ((/\=+('|")?\)/).test(a) === true && (/;\s*base64/).test(a) === true)) && (/function(\s+\w+)*\s*\(/).test(join) === false) {
if ((/:\s*((number)|(string))/).test(a) === true && (/((public)|(private))\s+/).test(a) === true) {
return output("typescript");
}
if ((/((public)|(private))\s+(((static)?\s+(v|V)oid)|(class)|(final))/).test(a) === true) {
return output("java");
}
if ((/<[a-zA-Z]/).test(a) === true && (/<\/[a-zA-Z]/).test(a) === true && ((/\s?\{%/).test(a) === true || (/\{(\{|#)(?!(\{|#|\=))/).test(a) === true)) {
return output("twig");
}
if ((/^\s*($|@)/).test(a) === false && ((/:\s*(\{|\(|\[)/).test(a) === true || (/^(\s*return;?\s*\{)/).test(a) === true) && (/(\};?\s*)$/).test(a) === true) {
return output("javascript");
}
if ((/\{\{#/).test(a) === true && (/\{\{\//).test(a) === true && (/<\w/).test(a) === true) {
return output("handlebars");
}
if ((/\{\s*(\w|\.|@|#)+\s*\{/).test(a) === true) {
return output("less");
}
if ((/\$(\w|-)/).test(a) === true) {
return output("scss");
}
if ((/(;|\{|:)\s*@\w/).test(a) === true) {
return output("less");
}
return output("css");
}
if ((/"\s*:\s*\{/).test(a) === true) {
return output("tss");
}
return output("unknown");
}
if ((((/(>[\w\s:]*)?<(\/|!)?[\w\s:\-\[]+/).test(a) === true || (/^(\s*<\?xml)/).test(a) === true) && ((/^([\s\w]*<)/).test(a) === true || (/(>[\s\w]*)$/).test(a) === true)) || ((/^(\s*<s((cript)|(tyle)))/i).test(a) === true && (/(<\/s((cript)|(tyle))>\s*)$/i).test(a) === true)) {
if (((/\s*<!doctype\ html>/i).test(a) === true && (/\s*<html/i).test(a) === true) || ((/^(\s*<!DOCTYPE\s+((html)|(HTML))\s+PUBLIC\s+)/).test(a) === true && (/XHTML\s+1\.1/).test(a) === false && (/XHTML\s+1\.0\s+(S|s)((trict)|(TRICT))/).test(a) === false)) {
if ((/<%\s*\}/).test(a) === true) {
return output("ejs");
}
if ((/<%\s*end/).test(a) === true) {
return output("html_ruby");
}
if ((/\{\{(#|\/|\{)/).test(a) === true) {
return output("handlebars");
}
if ((/\{\{end\}\}/).test(a) === true) {
//place holder for Go lang templates
return output("html");
}
if ((/\s?\{%/).test(a) === true && (/\{(\{|#)(?!(\{|#|\=))/).test(a) === true) {
return output("twig");
}
if ((/<\?/).test(a) === true) {
return output("php");
}
if ((/<jsp:include\s/).test(a) === true || (/<c:((set)|(if))\s/).test(a) === true) {
return output("jsp");
}
if ((/\{(#|\?|\^|@|<|\+|~)/).test(a) === true && (/\{\//).test(a) === true) {
return output("dustjs");
}
return output("html");
}
if ((/<jsp:include\s/).test(a) === true || (/<c:((set)|(if))\s/).test(a) === true) {
return output("jsp");
}
if ((/<%\s*\}/).test(a) === true) {
return output("ejs");
}
if ((/<%\s*end/).test(a) === true) {
return output("html_ruby");
}
if ((/\{\{(#|\/|\{)/).test(a) === true) {
return output("handlebars");
}
if ((/\{\{end\}\}/).test(a) === true) {
//place holder for Go lang templates
return output("xml");
}
if ((/\s?\{%/).test(a) === true && (/\{\{(?!(\{|#|\=))/).test(a) === true) {
return output("twig");
}
if ((/<\?(?!(xml))/).test(a) === true) {
return output("php");
}
if ((/\{(#|\?|\^|@|<|\+|~)/).test(a) === true && (/\{\//).test(a) === true) {
return output("dustjs");
}
if ((/<jsp:include\s/).test(a) === true || (/<c:((set)|(if))\s/).test(a) === true) {
return output("jsp");
}
return output("xml");
}
return output("unknown");
},
proctime = function core__proctime() {
var minuteString = "",
hourString = "",
minutes = 0,
hours = 0,
elapsed = (typeof Date.now === "function")
? ((Date.now() - startTime) / 1000)
: (function core__proctime_dateShim() {
var dateitem = new Date;
return Date.parse(dateitem);
}()),
secondString = elapsed.toFixed(3),
plural = function core__proctime_plural(x, y) {
var a = "";
if (x !== 1) {
a = x + y + "s ";
} else {
a = x + y + " ";
}
return a;
},
minute = function core__proctime_minute() {
minutes = parseInt((elapsed / 60), 10);
minuteString = plural(minutes, " minute");
minutes = elapsed - (minutes * 60);
secondString = (minutes === 1)
? "1 second"
: minutes.toFixed(3) + " seconds";
};
if (elapsed >= 60 && elapsed < 3600) {
minute();
} else if (elapsed >= 3600) {
hours = parseInt((elapsed / 3600), 10);
hourString = hours.toString();
elapsed = elapsed - (hours * 3600);
hourString = plural(hours, " hour");
minute();
} else {
secondString = plural(secondString, " second");
}
return "<p><strong>Execution time:</strong> <em>" + hourString + minuteString + secondString + "</em></p>";
},
pdcomment = function core__pdcomment() {
var comment = "",
a = 0,
b = options.source.length,
c = options.source
.indexOf("/*prettydiff.com") + 16,
difftest = false,
build = [],
comma = -1,
g = 0,
sourceChar = [],
quote = "",
sind = options.source
.indexOf("/*prettydiff.com"),
dind = options.diff
.indexOf("/*prettydiff.com");
if ((options.source.charAt(c - 17) === "\"" && options.source.charAt(c) === "\"") || (sind < 0 && dind < 0)) {
return;
}
if (sind > -1 && (/^(\s*\{\s*"token"\s*:\s*\[)/).test(options.source) === true && (/\],\s*"types"\s*:\s*\[/).test(options.source) === true) {
return;
}
if (sind < 0 && dind > -1 && (/^(\s*\{\s*"token"\s*:\s*\[)/).test(options.diff) === true && (/\],\s*"types"\s*:\s*\[/).test(options.diff) === true) {
return;
}
if (c === 15 && typeof options.diff === "string") {
c = options.diff
.indexOf("/*prettydiff.com") + 16;
difftest = true;
} else if (c === 15) {
return;
}
for (c = c; c < b; c += 1) {
if (difftest === false) {
if (options.source.charAt(c) === "*" && options.source.charAt(c + 1) === "/") {
break;
}
sourceChar.push(options.source.charAt(c));
} else {
if (options.diff.charAt(c) === "*" && options.diff.charAt(c + 1) === "/") {
break;
}
sourceChar.push(options.diff.charAt(c));
}
}
comment = sourceChar.join("")
.toLowerCase();
b = comment.length;
for (c = 0; c < b; c += 1) {
if ((typeof comment.charAt(c - 1) !== "string" || comment.charAt(c - 1) !== "\\") && (comment.charAt(c) === "\"" || comment.charAt(c) === "'")) {
if (quote === "") {
quote = comment.charAt(c);
} else {
quote = "";
}
}
if (quote === "") {
if (comment.charAt(c) === ",") {
g = comma + 1;
comma = c;
build.push(comment.substring(g, comma).replace(/^(\s*)/, "").replace(/(\s*)$/, ""));
}
}
}
g = comma + 1;
comma = comment.length;
build.push(comment.substring(g, comma).replace(/^(\s*)/, "").replace(/(\s*)$/, ""));
quote = "";
b = build.length;
sourceChar = [];
for (c = 0; c < b; c += 1) {
a = build[c].length;
for (g = 0; g < a; g += 1) {
if (build[c].indexOf(":") === -1) {
build[c] = "";
break;
}
sourceChar = [];
if ((typeof build[c].charAt(g - 1) !== "string" || build[c].charAt(g - 1) !== "\\") && (build[c].charAt(g) === "\"" || build[c].charAt(g) === "'")) {
if (quote === "") {
quote = build[c].charAt(g);
} else {
quote = "";
}
}
if (quote === "") {
if (build[c].charAt(g) === ":") {
sourceChar.push(build[c].substring(0, g).replace(/(\s*)$/, ""));
sourceChar.push(build[c].substring(g + 1).replace(/^(\s*)/, ""));
if (sourceChar[1].charAt(0) === sourceChar[1].charAt(sourceChar[1].length - 1) && sourceChar[1].charAt(sourceChar[1].length - 2) !== "\\" && (sourceChar[1].charAt(0) === "\"" || sourceChar[1].charAt(0) === "'")) {
sourceChar[1] = sourceChar[1].substring(1, sourceChar[1].length - 1);
}
build[c] = sourceChar;
break;
}
}
}
}
for (c = 0; c < b; c += 1) {
if (typeof build[c][1] === "string") {
build[c][0] = build[c][0].replace("api.", "");
if (build[c][0] === "braces" || build[c][0] === "indent") {
if (build[c][1] === "knr") {
options.braces = "knr";
} else if (build[c][1] === "allman") {
options.braces = "allman";
}
} else if (build[c][0] === "comments") {
if (build[c][1] === "indent") {
options.comments = "indent";
} else if (build[c][1] === "noindent") {
options.comments = "noindent";
}
} else if (build[c][0] === "diffview") {
if (build[c][1] === "sidebyside") {
options.diffview = "sidebyside";
} else if (build[c][1] === "inline") {
options.diffview = "inline";
}
} else if (build[c][0] === "lang" || build[c][0] === "langdefault") {
options[build[c][0]] = setlangmode(build[c][1]);
} else if (build[c][0] === "mode") {
if (build[c][1] === "beautify") {
options.mode = "beautify";
} else if (build[c][1] === "minify") {
options.mode = "minify";
} else if (build[c][1] === "diff") {
options.mode = "diff";
} else if (build[c][1] === "parse") {
options.mode = "parse";
}
} else if (build[c][0] === "quoteConvert") {
if (build[c][1] === "single") {
options.quoteConvert = "single";
} else if (build[c][1] === "double") {
options.quoteConvert = "double";
} else if (build[c][1] === "none") {
options.quoteConvert = "none";
}
} else if (build[c][0] === "style") {
if (build[c][1] === "indent") {
options.style = "indent";
} else if (build[c][1] === "noindent") {
options.style = "noindent";
}
} else if (build[c][0] === "varword") {
if (build[c][1] === "each") {
options.varword = "each";
} else if (build[c][1] === "list") {
options.varword = "list";
} else if (build[c][1] === "none") {
options.varword = "none";
}
} else if (options[build[c][0]] !== undefined) {
if (build[c][1] === "true") {
options[build[c][0]] = true;
} else if (build[c][1] === "false") {
options[build[c][0]] = false;
} else if (isNaN(build[c][1]) === false) {
options[build[c][0]] = Number(build[c][1]);
} else {
options[build[c][0]] = build[c][1];
}
}
}
}
};
pdcomment();
if (api.preserve === true || api.preserve === "true") {
options.preserve = true;
}
if (api.alphasort === true || api.alphasort === "true" || api.objsort === true || api.objsort === "true") {
options.objsort = true;
}
if (api.indent === "allman") {
options.braces = "allman";
}
if (api.vertical === true || api.vertical === "true") {
options.vertical = true;
}
if (options.source === "") {
return ["Error: Source sample is missing.", ""];
}
if (options.mode === "diff") {
if (options.diff === "Diff sample is missing.") {
return ["Error: Diff sample is missing.", ""];
}
if (options.lang === "csv") {
options.lang = "text";
}
}
if (options.lang === "auto") {
autoval = auto(options.source);
options.lang = autoval[1];
if (autoval[2] === "unknown") {
autostring = "<p>Code type set to <strong>auto</strong>, but language could not be determined." +
" Language defaulted to <em>" + autoval[0] + "</em>.</p>";
} else {
autostring = "<p>Code type set to <strong>auto</strong>. Presumed language is <em>" + autoval[2] + "</em>.</p>";
}
} else if (options.api === "dom") {
autoval = [
options.lang, options.lang, options.lang
];
autostring = "<p>Code type is set to <strong>" + options.lang + "</strong>.</p>";
} else {
options.lang = setlangmode(options.lang);
autostring = "<p>Code type is set to <strong>" + options.lang + "</strong>.</p>";
}
if (autoval[0] === "dustjs") {
options.dustjs = true;
}
if (options.lang === "html") {
options.html = true;
options.lang = "markup";
} else if (options.lang === "tss" || options.lang === "titanium") {
options.titanium = true;
options.lang = "javscript";
}
if (options.lang === "css") {
if (api.objsort === "css" || api.objsort === "cssonly") {
options.objsort = true;
}
if (api.preserve === "css" || api.preserve === "cssonly") {
options.preserve = true;
}
if (api.vertical === "css" || api.vertical === "cssonly") {
options.vertical = true;
}
}
if (options.lang === "js") {
if (api.objsort === "js" || api.objsort === "jsonly") {
options.objsort = true;
}
if (api.preserve === "js" || api.preserve === "jsonly") {
options.preserve = true;
}
if (api.vertical === "js" || api.vertical === "jsonly") {
options.vertical = true;
}
}
if (options.mode === "minify") {
if (options.lang === "css") {
apioutput = global.csspretty(options);
} else if (options.lang === "csv") {
apioutput = global.csvpretty(options);
} else if (options.lang === "markup") {
apioutput = global.markuppretty(options);
} else if (options.lang === "text") {
apioutput = options.source;
apidiffout = "";
} else {
apioutput = global.jspretty(options);
}
return (function core__minifyReport() {
var sizediff = function core__minifyReport_score() {
var a = 0,
lines = 0,
source = options.source,
sizeOld = source.length,
windowsSize = 0,
sizeNew = apioutput.length,
sizeDifference = sizeOld - sizeNew,
windowsDifference = 0,
percent = ((sizeDifference / sizeOld) * 100),
percentUnix = percent.toFixed(2) + "%",
percentWindows = "",
output = [];
for (a = 0; a < sizeOld; a += 1) {
if (source.charAt(a) === "\n") {
lines += 1;
}
}
windowsSize = sizeOld + lines;
windowsDifference = windowsSize - sizeNew;
percent = ((windowsDifference / windowsSize) * 100);
percentWindows = percent.toFixed(2) + "%";
if (global.report.indexOf("<p id='jserror'>") === 0) {
output.push(global.report);
} else if (global.report !== "") {
output.push("<p><strong class='duplicate'>Duplicate id attribute values detected:</strong> " + global.report + "</p>");
}
output.push("<div class='doc'><table class='analysis' summary='Minification efficiency report" +
"'><caption>Minification efficiency report</caption><thead><tr><th colspan='2'>Ou" +
"tput Size</th><th colspan='2'>Number of Lines From Input</th></tr></thead><tbody" +
"><tr><td colspan='2'>");
output.push(sizeNew);
output.push("</td><td colspan='2'>");
output.push(lines + 1);
output.push("</td></tr><tr><th>Operating System</th><th>Input Size</th><th>Size Difference</t" +
"h><th>Percentage of Decrease</th></tr><tr><th>Unix/Linux</th><td>");
output.push(sizeOld);
output.push("</td><td>");
output.push(sizeDifference);
output.push("</td><td>");
output.push(percentUnix);
output.push("</td></tr><tr><th>Windows</th><td>");
output.push(windowsSize);
output.push("</td><td>");
output.push(windowsDifference);
output.push("</td><td>");
output.push(percentWindows);
output.push("</td></tr></tbody></table></div>");
return output.join("");
};
if (global.jsxstatus === true) {
autoval = [
"jsx", "javascript", "React JSX"
];
autostring = "<p>Code type set to <strong>auto</strong>. Presumed language is <em>React JSX</e" +
"m>.</p>";
}
return [
apioutput, autostring + proctime() + sizediff()
];
}());
}
if (options.mode === "parse") {
if (options.lang === "css") {
apioutput = global.csspretty(options);
} else if (options.lang === "csv") {
apioutput = global.csvpretty(options);
} else if (options.lang === "markup") {
apioutput = global.markuppretty(options);
autostring = autostring + global.report;
} else if (options.lang === "text") {
apioutput = options.source;
apidiffout = "";
} else {
apioutput = global.jspretty(options);
}
if (apidiffout === false) {
apidiffout = "";
}
if (global.jsxstatus === true) {
autostring = "<p>Code type is presumed to be <em>React JSX</em>.</p>";
}
if (apioutput.token !== undefined) {
autostring = autostring + "<p>Total tokens: <strong>" + apioutput.token.length + "</strong></p>";
}
return [
apioutput, autostring + proctime()
];
}
if (options.mode === "beautify") {
if (options.lang === "css") {
apioutput = global.csspretty(options);
apidiffout = global.report;
} else if (options.lang === "csv") {
apioutput = global.csvpretty(options);
apidiffout = global.report;
} else if (options.lang === "markup") {
if (api.vertical === "jsonly") {
options.vertical = "jsonly";
}
apioutput = global.markuppretty(options);
apidiffout = global.report;
if (options.inchar !== "\t") {
apioutput = apioutput.replace(/\n[\t]*\u0020\/>/g, "");
}
} else if (options.lang === "text") {
apioutput = options.source;
apidiffout = "";
} else {
if (api.vertical === "jsonly") {
options.vertical = "jsonly";
}
apioutput = global.jspretty(options);
apidiffout = global.report;
}
if (apidiffout === false) {
apidiffout = "";
}
if (global.jsxstatus === true) {
autostring = "<p>Code type is presumed to be <em>React JSX</em>.</p>";
}
if (options.api === "" && options.jsscope !== "none" && options.lang === "javascript") {
builder.head = "<?xml version='1.0' encoding='UTF-8' ?><!DOCTYPE html PUBLIC '-//W3C//DTD XHTML " +
"1.1//EN' 'http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd'><html xmlns='http://www." +
"w3.org/1999/xhtml' xml:lang='en'><head><title>Pretty Diff - The difference tool<" +
"/title><meta name='robots' content='index, follow'/> <meta name='DC.title' conte" +
"nt='Pretty Diff - The difference tool'/> <link rel='canonical' href='http://pret" +
"tydiff.com/' type='application/xhtml+xml'/><meta http-equiv='Content-Type' conte" +
"nt='application/xhtml+xml;charset=UTF-8'/><meta http-equiv='Content-Style-Type' " +
"content='text/css'/><style type='text/css'>";
builder.cssCore = "body{font-family:'Arial';font-size:10px;overflow-y:scroll;}#samples #dcolorSchem" +
"e{position:relative;z-index:1000}#apireturn textarea{font-size:1.2em;height:50em" +
";width:100%}button{border-radius:.9em;display:block;font-weight:bold;width:100%}" +
"div .button{text-align:center}div button{display:inline-block;font-weight:bold;m" +
"argin:1em 0;padding:1em 2em}button:hover{cursor:pointer}#introduction{clear:both" +
";margin:0 0 0 5.6em;position:relative;top:-2.75em}#introduction ul{clear:both;he" +
"ight:3em;margin:0 0 0 -5.5em;overflow:hidden;width:100em}#introduction li{clear:" +
"none;display:block;float:left;font-size:1.4em;margin:0 4.95em -1em 0}#introducti" +
"on li li{font-size:1em;margin-left:2em}#introduction .information,#webtool #intr" +
"oduction h2{left:-90em;position:absolute;top:0;width:10em}#introduction h2{float" +
":none}#displayOps{float:right;font-size:1.5em;font-weight:bold;margin-right:1em;" +
"width:22.5em}#displayOps.default{position:static}#displayOps.maximized{margin-bo" +
"ttom:-2em;position:relative}#displayOps li{clear:none;display:block;float:left;l" +
"ist-style:none;margin:2em 0 0;text-align:right;width:9em}h1{float:left;font-size" +
":2em;margin:0 .5em .5em 0}#hideOptions{margin-left:5em;padding:0}#title_text{bor" +
"der-style:solid;border-width:.05em;display:block;float:left;font-size:1em;margin" +
"-left:.55em;padding:.1em}h1 svg,h1 img{border-style:solid;border-width:.05em;flo" +
"at:left;height:2em;width:2em}h1 span{font-size:.5em}h2,h3{background:#fff;border" +
"-style:solid;border-width:.075em;display:inline-block;font-size:1.8em;font-weigh" +