forked from shaunxcode/jsedn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jsedn.js
1798 lines (1522 loc) · 42.4 KB
/
jsedn.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
;(function(){
/**
* Require the given path.
*
* @param {String} path
* @return {Object} exports
* @api public
*/
function require(p, parent, orig){
var path = require.resolve(p)
, mod = require.modules[path];
// lookup failed
if (null == path) {
orig = orig || p;
parent = parent || 'root';
throw new Error('failed to require "' + orig + '" from "' + parent + '"');
}
// perform real require()
// by invoking the module's
// registered function
if (!mod.exports) {
mod.exports = {};
mod.client = mod.component = true;
mod.call(this, mod, mod.exports, require.relative(path));
}
return mod.exports;
}
/**
* Registered modules.
*/
require.modules = {};
/**
* Registered aliases.
*/
require.aliases = {};
/**
* Resolve `path`.
*
* Lookup:
*
* - PATH/index.js
* - PATH.js
* - PATH
*
* @param {String} path
* @return {String} path or null
* @api private
*/
require.resolve = function(path){
var orig = path
, reg = path + '.js'
, regJSON = path + '.json'
, index = path + '/index.js'
, indexJSON = path + '/index.json';
return require.modules[reg] && reg
|| require.modules[regJSON] && regJSON
|| require.modules[index] && index
|| require.modules[indexJSON] && indexJSON
|| require.modules[orig] && orig
|| require.aliases[index];
};
/**
* Normalize `path` relative to the current path.
*
* @param {String} curr
* @param {String} path
* @return {String}
* @api private
*/
require.normalize = function(curr, path) {
var segs = [];
if ('.' != path.charAt(0)) return path;
curr = curr.split('/');
path = path.split('/');
for (var i = 0; i < path.length; ++i) {
if ('..' == path[i]) {
curr.pop();
} else if ('.' != path[i] && '' != path[i]) {
segs.push(path[i]);
}
}
return curr.concat(segs).join('/');
};
/**
* Register module at `path` with callback `fn`.
*
* @param {String} path
* @param {Function} fn
* @api private
*/
require.register = function(path, fn){
require.modules[path] = fn;
};
/**
* Alias a module definition.
*
* @param {String} from
* @param {String} to
* @api private
*/
require.alias = function(from, to){
var fn = require.modules[from];
if (!fn) throw new Error('failed to alias "' + from + '", it does not exist');
require.aliases[to] = from;
};
/**
* Return a require function relative to the `parent` path.
*
* @param {String} parent
* @return {Function}
* @api private
*/
require.relative = function(parent) {
var p = require.normalize(parent, '..');
/**
* lastIndexOf helper.
*/
function lastIndexOf(arr, obj){
var i = arr.length;
while (i--) {
if (arr[i] === obj) return i;
}
return -1;
}
/**
* The relative require() itself.
*/
function fn(path){
var orig = path;
path = fn.resolve(path);
return require(path, parent, orig);
}
/**
* Resolve relative to the parent.
*/
fn.resolve = function(path){
// resolve deps by returning
// the dep in the nearest "deps"
// directory
if ('.' != path.charAt(0)) {
var segs = parent.split('/');
var i = lastIndexOf(segs, 'deps') + 1;
if (!i) i = 0;
path = segs.slice(0, i + 1).join('/') + '/deps/' + path;
return path;
}
return require.normalize(p, path);
};
/**
* Check if module is defined at `path`.
*/
fn.exists = function(path){
return !! require.modules[fn.resolve(path)];
};
return fn;
};require.register("jkroso-type/index.js", function(module, exports, require){
/**
* refs
*/
var toString = Object.prototype.toString;
/**
* Return the type of `val`.
*
* @param {Mixed} val
* @return {String}
* @api public
*/
module.exports = function(v){
// .toString() is slow so try avoid it
return typeof v === 'object'
? types[toString.call(v)]
: typeof v
};
var types = {
'[object Function]': 'function',
'[object RegExp]': 'regexp',
'[object Arguments]': 'arguments',
'[object Array]': 'array',
'[object String]': 'string',
'[object Null]': 'null',
'[object Undefined]': 'undefined',
'[object Number]': 'number',
'[object Boolean]': 'boolean',
'[object Object]': 'object',
'[object Text]': 'textnode',
'[object Uint8Array]': '8bit-array',
'[object Uint16Array]': '16bit-array',
'[object Uint32Array]': '32bit-array',
'[object Uint8ClampedArray]': '8bit-array',
'[object Error]': 'error'
}
if (typeof window != 'undefined') {
for (var el in window) if (/^HTML\w+Element$/.test(el)) {
types['[object '+el+']'] = 'element'
}
}
module.exports.types = types
});
require.register("jkroso-equals/index.js", function(module, exports, require){
var type = require('type')
/**
* assert all values are equal
*
* @param {Any} [...]
* @return {Boolean}
*/
module.exports = function(){
var i = arguments.length - 1
while (i > 0) {
if (!compare(arguments[i], arguments[--i])) return false
}
return true
}
// (any, any, [array]) -> boolean
function compare(a, b, memos){
// All identical values are equivalent
if (a === b) return true
var fnA = types[type(a)]
if (fnA !== types[type(b)]) return false
return fnA ? fnA(a, b, memos) : false
}
var types = {}
// (Number) -> boolean
types.number = function(a){
// NaN check
return a !== a
}
// (function, function, array) -> boolean
types['function'] = function(a, b, memos){
return a.toString() === b.toString()
// Functions can act as objects
&& types.object(a, b, memos)
&& compare(a.prototype, b.prototype)
}
// (date, date) -> boolean
types.date = function(a, b){
return +a === +b
}
// (regexp, regexp) -> boolean
types.regexp = function(a, b){
return a.toString() === b.toString()
}
// (DOMElement, DOMElement) -> boolean
types.element = function(a, b){
return a.outerHTML === b.outerHTML
}
// (textnode, textnode) -> boolean
types.textnode = function(a, b){
return a.textContent === b.textContent
}
// decorate `fn` to prevent it re-checking objects
// (function) -> function
function memoGaurd(fn){
return function(a, b, memos){
if (!memos) return fn(a, b, [])
var i = memos.length, memo
while (memo = memos[--i]) {
if (memo[0] === a && memo[1] === b) return true
}
return fn(a, b, memos)
}
}
types['arguments'] =
types.array = memoGaurd(compareArrays)
// (array, array, array) -> boolean
function compareArrays(a, b, memos){
var i = a.length
if (i !== b.length) return false
memos.push([a, b])
while (i--) {
if (!compare(a[i], b[i], memos)) return false
}
return true
}
types.object = memoGaurd(compareObjects)
// (object, object, array) -> boolean
function compareObjects(a, b, memos) {
var ka = getEnumerableProperties(a)
var kb = getEnumerableProperties(b)
var i = ka.length
// same number of properties
if (i !== kb.length) return false
// although not necessarily the same order
ka.sort()
kb.sort()
// cheap key test
while (i--) if (ka[i] !== kb[i]) return false
// remember
memos.push([a, b])
// iterate again this time doing a thorough check
i = ka.length
while (i--) {
var key = ka[i]
if (!compare(a[key], b[key], memos)) return false
}
return true
}
// (object) -> array
function getEnumerableProperties (object) {
var result = []
for (var k in object) if (k !== 'constructor') {
result.push(k)
}
return result
}
// expose compare
module.exports.compare = compare
});
require.register("component-type/index.js", function(module, exports, require){
/**
* toString ref.
*/
var toString = Object.prototype.toString;
/**
* Return the type of `val`.
*
* @param {Mixed} val
* @return {String}
* @api public
*/
module.exports = function(val){
switch (toString.call(val)) {
case '[object Function]': return 'function';
case '[object RegExp]': return 'regexp';
case '[object Arguments]': return 'arguments';
case '[object Array]': return 'array';
case '[object String]': return 'string';
}
if (val === null) return 'null';
if (val === undefined) return 'undefined';
if (val && val.nodeType === 1) return 'element';
if (val === Object(val)) return 'object';
return typeof val;
};
});
require.register("jsedn/index.js", function(module, exports, require){
module.exports = require("./lib/reader.js");
});
require.register("jsedn/lib/atoms.js", function(module, exports, require){
// Generated by CoffeeScript 1.6.1
(function() {
var BigInt, Char, Discard, Keyword, Prim, StringObj, Symbol, bigInt, char, charMap, kw, memo, sym, type,
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; },
__slice = [].slice;
type = require("./type");
memo = require("./memo");
Prim = (function() {
function Prim(val) {
var x;
if (type(val) === "array") {
this.val = (function() {
var _i, _len, _results;
_results = [];
for (_i = 0, _len = val.length; _i < _len; _i++) {
x = val[_i];
if (!(x instanceof Discard)) {
_results.push(x);
}
}
return _results;
})();
} else {
this.val = val;
}
}
Prim.prototype.value = function() {
return this.val;
};
Prim.prototype.toString = function() {
return JSON.stringify(this.val);
};
return Prim;
})();
BigInt = (function(_super) {
__extends(BigInt, _super);
function BigInt() {
return BigInt.__super__.constructor.apply(this, arguments);
}
BigInt.prototype.ednEncode = function() {
return this.val;
};
BigInt.prototype.jsEncode = function() {
return this.val;
};
BigInt.prototype.jsonEncode = function() {
return {
BigInt: this.val
};
};
return BigInt;
})(Prim);
StringObj = (function(_super) {
__extends(StringObj, _super);
function StringObj() {
return StringObj.__super__.constructor.apply(this, arguments);
}
StringObj.prototype.toString = function() {
return this.val;
};
StringObj.prototype.is = function(test) {
return this.val === test;
};
return StringObj;
})(Prim);
charMap = {
newline: "\n",
"return": "\r",
space: " ",
tab: "\t",
formfeed: "\f"
};
Char = (function(_super) {
__extends(Char, _super);
Char.prototype.ednEncode = function() {
return "\\" + this.val;
};
Char.prototype.jsEncode = function() {
return charMap[this.val] || this.val;
};
Char.prototype.jsonEncode = function() {
return {
Char: this.val
};
};
function Char(val) {
if (charMap[val] || val.length === 1) {
this.val = val;
} else {
throw "Char may only be newline, return, space, tab, formfeed or a single character - you gave [" + val + "]";
}
}
return Char;
})(StringObj);
Discard = (function() {
function Discard() {}
return Discard;
})();
Symbol = (function(_super) {
__extends(Symbol, _super);
Symbol.prototype.validRegex = /[0-9A-Za-z.*+!\-_?$%&=:#/]+/;
Symbol.prototype.invalidFirstChars = [":", "#", "/"];
Symbol.prototype.valid = function(word) {
var _ref, _ref1, _ref2;
if (((_ref = word.match(this.validRegex)) != null ? _ref[0] : void 0) !== word) {
throw "provided an invalid symbol " + word;
}
if (word.length === 1 && word[0] !== "/") {
if (_ref1 = word[0], __indexOf.call(this.invalidFirstChars, _ref1) >= 0) {
throw "Invalid first character in symbol " + word[0];
}
}
if (((_ref2 = word[0]) === "-" || _ref2 === "+" || _ref2 === ".") && (word[1] != null) && word[1].match(/[0-9]/)) {
throw "If first char is " + word[0] + " the second char can not be numeric. You had " + word[1];
}
if (word[0].match(/[0-9]/)) {
throw "first character may not be numeric. You provided " + word[0];
}
return true;
};
function Symbol() {
var args, parts;
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
switch (args.length) {
case 1:
if (args[0] === "/") {
this.ns = null;
this.name = "/";
} else {
parts = args[0].split("/");
if (parts.length === 1) {
this.ns = null;
this.name = parts[0];
if (this.name === ":") {
throw "can not have a symbol of only :";
}
} else if (parts.length === 2) {
this.ns = parts[0];
if (this.ns === "") {
throw "can not have a slash at start of symbol";
}
if (this.ns === ":") {
throw "can not have a namespace of :";
}
this.name = parts[1];
if (this.name.length === 0) {
throw "symbol may not end with a slash.";
}
} else {
throw "Can not have more than 1 forward slash in a symbol";
}
}
break;
case 2:
this.ns = args[0];
this.name = args[1];
}
if (this.name.length === 0) {
throw "Symbol can not be empty";
}
this.val = "" + (this.ns ? "" + this.ns + "/" : "") + this.name;
this.valid(this.val);
}
Symbol.prototype.toString = function() {
return this.val;
};
Symbol.prototype.ednEncode = function() {
return this.val;
};
Symbol.prototype.jsEncode = function() {
return this.val;
};
Symbol.prototype.jsonEncode = function() {
return {
Symbol: this.val
};
};
return Symbol;
})(Prim);
Keyword = (function(_super) {
__extends(Keyword, _super);
Keyword.prototype.invalidFirstChars = ["#", "/"];
function Keyword() {
Keyword.__super__.constructor.apply(this, arguments);
if (this.val[0] !== ":") {
throw "keyword must start with a :";
}
if ((this.val[1] != null) === "/") {
throw "keyword can not have a slash with out a namespace";
}
}
Keyword.prototype.jsonEncode = function() {
return {
Keyword: this.val
};
};
return Keyword;
})(Symbol);
char = memo(Char);
kw = memo(Keyword);
sym = memo(Symbol);
bigInt = memo(BigInt);
module.exports = {
Prim: Prim,
Symbol: Symbol,
Keyword: Keyword,
StringObj: StringObj,
Char: Char,
Discard: Discard,
BigInt: BigInt,
char: char,
kw: kw,
sym: sym,
bigInt: bigInt
};
}).call(this);
});
require.register("jsedn/lib/atPath.js", function(module, exports, require){
// Generated by CoffeeScript 1.6.1
(function() {
var kw;
kw = require("./atoms").kw;
module.exports = function(obj, path) {
var part, value, _i, _len;
path = path.trim().replace(/[ ]{2,}/g, ' ').split(' ');
value = obj;
for (_i = 0, _len = path.length; _i < _len; _i++) {
part = path[_i];
if (part[0] === ":") {
part = kw(part);
}
if (value.exists) {
if (value.exists(part) != null) {
value = value.at(part);
} else {
throw "Could not find " + part;
}
} else {
throw "Not a composite object";
}
}
return value;
};
}).call(this);
});
require.register("jsedn/lib/collections.js", function(module, exports, require){
// Generated by CoffeeScript 1.6.1
(function() {
var Iterable, List, Map, Pair, Prim, Set, Vector, encode, equals, type,
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
type = require("./type");
equals = require("equals");
Prim = require("./atoms").Prim;
encode = require("./encode").encode;
Iterable = (function(_super) {
__extends(Iterable, _super);
function Iterable() {
return Iterable.__super__.constructor.apply(this, arguments);
}
Iterable.prototype.hashId = function() {
return this.ednEncode();
};
Iterable.prototype.ednEncode = function() {
return (this.map(function(i) {
return encode(i);
})).val.join(" ");
};
Iterable.prototype.jsonEncode = function() {
return this.map(function(i) {
if (i.jsonEncode != null) {
return i.jsonEncode();
} else {
return i;
}
});
};
Iterable.prototype.jsEncode = function() {
return (this.map(function(i) {
if ((i != null ? i.jsEncode : void 0) != null) {
return i.jsEncode();
} else {
return i;
}
})).val;
};
Iterable.prototype.exists = function(index) {
return this.val[index] != null;
};
Iterable.prototype.each = function(iter) {
var i, _i, _len, _ref, _results;
_ref = this.val;
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
i = _ref[_i];
_results.push(iter(i));
}
return _results;
};
Iterable.prototype.map = function(iter) {
return this.each(iter);
};
Iterable.prototype.walk = function(iter) {
return this.map(function(i) {
if ((i.walk != null) && type(i.walk) === "function") {
return i.walk(iter);
} else {
return iter(i);
}
});
};
Iterable.prototype.at = function(index) {
if (this.exists(index)) {
return this.val[index];
}
};
Iterable.prototype.set = function(index, val) {
this.val[index] = val;
return this;
};
return Iterable;
})(Prim);
List = (function(_super) {
__extends(List, _super);
function List() {
return List.__super__.constructor.apply(this, arguments);
}
List.prototype.ednEncode = function() {
return "(" + (List.__super__.ednEncode.call(this)) + ")";
};
List.prototype.jsonEncode = function() {
return {
List: List.__super__.jsonEncode.call(this)
};
};
List.prototype.map = function(iter) {
return new List(this.each(iter));
};
return List;
})(Iterable);
Vector = (function(_super) {
__extends(Vector, _super);
function Vector() {
return Vector.__super__.constructor.apply(this, arguments);
}
Vector.prototype.ednEncode = function() {
return "[" + (Vector.__super__.ednEncode.call(this)) + "]";
};
Vector.prototype.jsonEncode = function() {
return {
Vector: Vector.__super__.jsonEncode.call(this)
};
};
Vector.prototype.map = function(iter) {
return new Vector(this.each(iter));
};
return Vector;
})(Iterable);
Set = (function(_super) {
__extends(Set, _super);
Set.prototype.ednEncode = function() {
return "\#{" + (Set.__super__.ednEncode.call(this)) + "}";
};
Set.prototype.jsonEncode = function() {
return {
Set: Set.__super__.jsonEncode.call(this)
};
};
function Set(val) {
var item, _i, _len;
Set.__super__.constructor.call(this);
this.val = [];
for (_i = 0, _len = val.length; _i < _len; _i++) {
item = val[_i];
if (__indexOf.call(this.val, item) >= 0) {
throw "set not distinct";
} else {
this.val.push(item);
}
}
}
Set.prototype.map = function(iter) {
return new Set(this.each(iter));
};
return Set;
})(Iterable);
Pair = (function() {
function Pair(key, val) {
this.key = key;
this.val = val;
}
return Pair;
})();
Map = (function() {
Map.prototype.hashId = function() {
return this.ednEncode();
};
Map.prototype.ednEncode = function() {
var i;
return "{" + (((function() {
var _i, _len, _ref, _results;
_ref = this.value();
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
i = _ref[_i];
_results.push(encode(i));
}
return _results;
}).call(this)).join(" ")) + "}";
};
Map.prototype.jsonEncode = function() {
var i;
return {
Map: (function() {
var _i, _len, _ref, _results;
_ref = this.value();
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
i = _ref[_i];
_results.push(i.jsonEncode != null ? i.jsonEncode() : i);
}
return _results;
}).call(this)
};
};
Map.prototype.jsEncode = function() {
var hashId, i, k, result, _i, _len, _ref, _ref1;
result = {};
_ref = this.keys;
for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) {
k = _ref[i];
hashId = (k != null ? k.hashId : void 0) != null ? k.hashId() : k;
result[hashId] = ((_ref1 = this.vals[i]) != null ? _ref1.jsEncode : void 0) != null ? this.vals[i].jsEncode() : this.vals[i];
}
return result;
};
function Map(val) {
var i, v, _i, _len, _ref;
this.val = val != null ? val : [];
if (this.val.length && this.val.length % 2 !== 0) {
throw "Map accepts an array with an even number of items. You provided " + this.val.length + " items";
}
this.keys = [];
this.vals = [];
_ref = this.val;
for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) {
v = _ref[i];
if (i % 2 === 0) {
this.keys.push(v);
} else {
this.vals.push(v);
}
}
this.val = false;
}
Map.prototype.value = function() {
var i, result, v, _i, _len, _ref;
result = [];
_ref = this.keys;
for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) {
v = _ref[i];
result.push(v);
if (this.vals[i] !== void 0) {
result.push(this.vals[i]);
}
}