@geexcode/geex-angular 0.0.38 → 0.0.41

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,553 @@
1
+ // Uses CommonJS, AMD or browser globals to create a module.
2
+ // Based on: https://github.com/umdjs/umd/blob/master/commonjsStrict.js
3
+
4
+ var risonRegex =
5
+ /^\s*(?:\([^()]*:[^()]*\)|!\([^()]*\)|!t|!f|!n|-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE]\d+)?|'(?:[^'!]|!(?:'|!))*'|[A-Za-z0-9_./~-]+)\s*$/;
6
+ (function (root, factory) {
7
+ if (typeof define === 'function' && define.amd) {
8
+ // AMD. Register as an anonymous module.
9
+ define(['exports'], factory);
10
+ } else if (typeof exports === 'object') {
11
+ // CommonJS
12
+ factory(exports);
13
+ } else {
14
+ // Browser globals
15
+ factory((root.rison = {}));
16
+ }
17
+ }(this, function (exports) {
18
+ var rison = exports;
19
+
20
+ //////////////////////////////////////////////////
21
+ //
22
+ // the stringifier is based on
23
+ // http://json.org/json.js as of 2006-04-28 from json.org
24
+ // the parser is based on
25
+ // http://osteele.com/sources/openlaszlo/json
26
+ //
27
+
28
+ if (typeof rison == 'undefined')
29
+ window.rison = {};
30
+
31
+ /**
32
+ * rules for an uri encoder that is more tolerant than encodeURIComponent
33
+ *
34
+ * encodeURIComponent passes ~!*()-_.'
35
+ *
36
+ * we also allow ,:@$/
37
+ *
38
+ */
39
+ rison.uri_ok = { // ok in url paths and in form query args
40
+ '~': true, '!': true, '*': true, '(': true, ')': true,
41
+ '-': true, '_': true, '.': true, ',': true,
42
+ ':': true, '@': true, '$': true,
43
+ "\"": true, '/': true
44
+ };
45
+
46
+ /*
47
+ * we divide the uri-safe glyphs into three sets
48
+ * <rison> - used by rison ' ! : ( ) ,
49
+ * <reserved> - not common in strings, reserved * @ $ & ; =
50
+ *
51
+ * we define <identifier> as anything that's not forbidden
52
+ */
53
+
54
+ /**
55
+ * punctuation characters that are legal inside ids.
56
+ */
57
+ // this var isn't actually used
58
+ //rison.idchar_punctuation = "_-./~";
59
+
60
+ (function () {
61
+ var l = [];
62
+ for (var hi = 0; hi < 16; hi++) {
63
+ for (var lo = 0; lo < 16; lo++) {
64
+ if (hi+lo == 0) continue;
65
+ var c = String.fromCharCode(hi*16 + lo);
66
+ if (! /\w|[-_.\/~]/.test(c))
67
+ l.push('\\u00' + hi.toString(16) + lo.toString(16));
68
+ }
69
+ }
70
+ /**
71
+ * characters that are illegal inside ids.
72
+ * <rison> and <reserved> classes are illegal in ids.
73
+ *
74
+ */
75
+ rison.not_idchar = l.join("")
76
+ //idcrx = new RegExp('[' + rison.not_idchar + ']');
77
+ //console.log('NOT', (idcrx.test(' ')) );
78
+ })();
79
+ //rison.not_idchar = " \t\r\n\"<>[]{}'!=:(),*@$;&";
80
+ rison.not_idchar = " '!:(),*@$";
81
+
82
+
83
+ /**
84
+ * characters that are illegal as the start of an id
85
+ * this is so ids can't look like numbers.
86
+ */
87
+ rison.not_idstart = "-0123456789";
88
+
89
+
90
+ (function () {
91
+ var idrx = '[^' + rison.not_idstart + rison.not_idchar +
92
+ '][^' + rison.not_idchar + ']*';
93
+
94
+ rison.id_ok = new RegExp('^' + idrx + '$');
95
+
96
+ // regexp to find the end of an id when parsing
97
+ // g flag on the regexp is necessary for iterative regexp.exec()
98
+ rison.next_id = new RegExp(idrx, 'g');
99
+ })();
100
+
101
+ /**
102
+ * this is like encodeURIComponent() but quotes fewer characters.
103
+ *
104
+ * @see rison.uri_ok
105
+ *
106
+ * encodeURIComponent passes ~!*()-_.'
107
+ * rison.quote also passes ,:@$/
108
+ * and quotes " " as "+" instead of "%20"
109
+ */
110
+ rison.quote = function(x) {
111
+ if (/^[-A-Za-z0-9~!*()_.",:@$\/]*$/.test(x))
112
+ return x;
113
+
114
+ return encodeURIComponent(x)
115
+ .replace('%2C', ',', 'g')
116
+ .replace('%3A', ':', 'g')
117
+ .replace('%40', '@', 'g')
118
+ .replace('%24', '$', 'g')
119
+ .replace('%2F', '/', 'g')
120
+ .replace('%20', '+', 'g');
121
+ };
122
+
123
+
124
+ //
125
+ // based on json.js 2006-04-28 from json.org
126
+ // license: http://www.json.org/license.html
127
+ //
128
+ // hacked by nix for use in uris.
129
+ //
130
+
131
+ (function () {
132
+ var sq = { // url-ok but quoted in strings
133
+ "\"": true, '!': true
134
+ },
135
+ s = {
136
+ array: function (x) {
137
+ var a = ['!('], b, f, i, l = x.length, v;
138
+ for (i = 0; i < l; i += 1) {
139
+ v = x[i];
140
+ f = s[typeof v];
141
+ if (f) {
142
+ v = f(v);
143
+ if (typeof v == 'string') {
144
+ if (b) {
145
+ a[a.length] = ',';
146
+ }
147
+ a[a.length] = v;
148
+ b = true;
149
+ }
150
+ }
151
+ }
152
+ a[a.length] = ')';
153
+ return a.join("");
154
+ },
155
+ 'boolean': function (x) {
156
+ if (x)
157
+ return '!t';
158
+ return '!f'
159
+ },
160
+ 'null': function (x) {
161
+ return "!n";
162
+ },
163
+ number: function (x) {
164
+ if (!isFinite(x))
165
+ return '!n';
166
+ // strip '+' out of exponent, '-' is ok though
167
+ return String(x).replace(/\+/,"");
168
+ },
169
+ object: function (x) {
170
+ if (x) {
171
+ if (x instanceof Array) {
172
+ return s.array(x);
173
+ }
174
+ if (x instanceof Date) {
175
+ return `!d"${x.toISOString()}"`;
176
+ }
177
+ // WILL: will this work on non-Firefox browsers?
178
+ if (typeof x.__prototype__ === 'object' && typeof x.__prototype__.encode_rison !== 'undefined')
179
+ return x.encode_rison();
180
+
181
+ var a = ['('], b, f, i, v, ki, ks=[];
182
+ for (i in x)
183
+ ks[ks.length] = i;
184
+ ks.sort();
185
+ for (ki = 0; ki < ks.length; ki++) {
186
+ i = ks[ki];
187
+ v = x[i];
188
+ f = s[typeof v];
189
+ if (f) {
190
+ v = f(v);
191
+ if (typeof v == 'string') {
192
+ if (b) {
193
+ a[a.length] = ',';
194
+ }
195
+ a.push(s.string(i), ':', v);
196
+ b = true;
197
+ }
198
+ }
199
+ }
200
+ a[a.length] = ')';
201
+ return a.join("");
202
+ }
203
+ return '!n';
204
+ },
205
+ string: function (x) {
206
+ if (x == "")
207
+ return "\"\"";
208
+
209
+ if (rison.id_ok.test(x))
210
+ return x;
211
+ x = x.replace(/(['!])/g, function(a, b) {
212
+ if (sq[b]) return '!'+b;
213
+ return b;
214
+ });
215
+ return "\"" + x + "\"";
216
+ },
217
+ undefined: function (x) {
218
+ throw new Error("rison can't encode the undefined value");
219
+ }
220
+ };
221
+
222
+
223
+ /**
224
+ * rison-encode a javascript structure
225
+ *
226
+ * implemementation based on Douglas Crockford's json.js:
227
+ * http://json.org/json.js as of 2006-04-28 from json.org
228
+ *
229
+ */
230
+ rison.encode = function (v) {
231
+ return s[typeof v](v);
232
+ };
233
+
234
+ /**
235
+ * rison-encode a javascript object without surrounding parens
236
+ *
237
+ */
238
+ rison.encode_object = function (v) {
239
+ if (typeof v != 'object' || v === null || v instanceof Array)
240
+ throw new Error("rison.encode_object expects an object argument");
241
+ var r = s[typeof v](v);
242
+ return r.substring(1, r.length-1);
243
+ };
244
+
245
+ /**
246
+ * rison-encode a javascript array without surrounding parens
247
+ *
248
+ */
249
+ rison.encode_array = function (v) {
250
+ if (!(v instanceof Array))
251
+ throw new Error("rison.encode_array expects an array argument");
252
+ var r = s[typeof v](v);
253
+ return r.substring(2, r.length-1);
254
+ };
255
+
256
+ /**
257
+ * rison-encode and uri-encode a javascript structure
258
+ *
259
+ */
260
+ rison.encode_uri = function (v) {
261
+ return rison.quote(s[typeof v](v));
262
+ };
263
+
264
+ })();
265
+
266
+
267
+
268
+
269
+ //
270
+ // based on openlaszlo-json and hacked by nix for use in uris.
271
+ //
272
+ // Author: Oliver Steele
273
+ // Copyright: Copyright 2006 Oliver Steele. All rights reserved.
274
+ // Homepage: http://osteele.com/sources/openlaszlo/json
275
+ // License: MIT License.
276
+ // Version: 1.0
277
+
278
+
279
+ /**
280
+ * parse a rison string into a javascript structure.
281
+ *
282
+ * this is the simplest decoder entry point.
283
+ *
284
+ * based on Oliver Steele's OpenLaszlo-JSON
285
+ * http://osteele.com/sources/openlaszlo/json
286
+ */
287
+ rison.decode = function(r) {
288
+ var errcb = function(e) { throw Error('rison decoder error: ' + e); };
289
+ var p = new rison.parser(errcb);
290
+ return p.parse(r);
291
+ };
292
+
293
+ /**
294
+ * decode a GeexRouter query param value.
295
+ * falls back to the raw string when the value is not valid rison
296
+ * (e.g. external OAuth callbacks that bypass GeexRouter encoding).
297
+ */
298
+ rison.decode_query_param = function(r) {
299
+ if (r == null || r === "") {
300
+ return "";
301
+ }
302
+ try {
303
+ var decoded = rison.decode(r);
304
+ return decoded == null ? "" : String(decoded);
305
+ } catch (e) {
306
+ return String(r);
307
+ }
308
+ };
309
+
310
+ /**
311
+ * parse an o-rison string into a javascript structure.
312
+ *
313
+ * this simply adds parentheses around the string before parsing.
314
+ */
315
+ rison.decode_object = function(r) {
316
+ return rison.decode('('+r+')');
317
+ };
318
+
319
+ /**
320
+ * parse an a-rison string into a javascript structure.
321
+ *
322
+ * this simply adds array markup around the string before parsing.
323
+ */
324
+ rison.decode_array = function(r) {
325
+ return rison.decode('!('+r+')');
326
+ };
327
+
328
+
329
+ /**
330
+ * construct a new parser object for reuse.
331
+ *
332
+ * @constructor
333
+ * @class A Rison parser class. You should probably
334
+ * use rison.decode instead.
335
+ * @see rison.decode
336
+ */
337
+ rison.parser = function (errcb) {
338
+ this.errorHandler = errcb;
339
+ };
340
+
341
+ /**
342
+ * a string containing acceptable whitespace characters.
343
+ * by default the rison decoder tolerates no whitespace.
344
+ * to accept whitespace set rison.parser.WHITESPACE = " \t\n\r\f";
345
+ */
346
+ rison.parser.WHITESPACE = "";
347
+
348
+ // expose this as-is?
349
+ rison.parser.prototype.setOptions = function (options) {
350
+ if (options['errorHandler'])
351
+ this.errorHandler = options.errorHandler;
352
+ };
353
+
354
+ /**
355
+ * parse a rison string into a javascript structure.
356
+ */
357
+ rison.parser.prototype.parse = function (str) {
358
+ this.string = str;
359
+ this.index = 0;
360
+ this.message = null;
361
+ var value = this.readValue();
362
+ if (!this.message && this.next())
363
+ value = this.error("unable to parse string as rison: '" + rison.encode(str) + "\"");
364
+ if (this.message && this.errorHandler)
365
+ this.errorHandler(this.message, this.index);
366
+ return value;
367
+ };
368
+
369
+ rison.parser.prototype.error = function (message) {
370
+ if (typeof(console) != 'undefined')
371
+ console.log('rison parser error: ', message);
372
+ this.message = message;
373
+ return undefined;
374
+ }
375
+
376
+ rison.parser.prototype.readValue = function () {
377
+ var c = this.next();
378
+ var fn = c && this.table[c];
379
+
380
+ if (fn)
381
+ return fn.apply(this);
382
+
383
+ // fell through table, parse as an id
384
+
385
+ var s = this.string;
386
+ var i = this.index-1;
387
+
388
+ // Regexp.lastIndex may not work right in IE before 5.5?
389
+ // g flag on the regexp is also necessary
390
+ rison.next_id.lastIndex = i;
391
+ var m = rison.next_id.exec(s);
392
+
393
+ // console.log('matched id', i, r.lastIndex);
394
+
395
+ if (m.length > 0) {
396
+ var id = m[0];
397
+ this.index = i+id.length;
398
+ return id; // a string
399
+ }
400
+
401
+ if (c) return this.error("invalid character: '" + c + "\"");
402
+ return this.error("empty expression");
403
+ }
404
+
405
+ rison.parser.parse_date = function (parser) {
406
+ var c;
407
+ while ((c = parser.next()) != "Z") {
408
+ --parser.index;
409
+ var n = parser.readValue();
410
+ if (typeof n == "undefined") return undefined;
411
+ return new Date(n);
412
+ }
413
+ return undefined;
414
+ };
415
+
416
+ rison.parser.parse_array = function (parser) {
417
+ var ar = [];
418
+ var c;
419
+ while ((c = parser.next()) != ')') {
420
+ if (!c) return parser.error("unmatched '!('");
421
+ if (ar.length) {
422
+ if (c != ',')
423
+ parser.error("missing ','");
424
+ } else if (c == ',') {
425
+ return parser.error("extra ','");
426
+ } else
427
+ --parser.index;
428
+ var n = parser.readValue();
429
+ if (typeof n == "undefined") return undefined;
430
+ ar.push(n);
431
+ }
432
+ return ar;
433
+ };
434
+
435
+ rison.parser.bangs = {
436
+ t: true,
437
+ f: false,
438
+ n: null,
439
+ '(': rison.parser.parse_array,
440
+ d: rison.parser.parse_date
441
+ }
442
+
443
+ rison.parser.prototype.table = {
444
+ '!': function () {
445
+ var s = this.string;
446
+ var c = s.charAt(this.index++);
447
+ if (!c) return this.error('"!" at end of input');
448
+ var x = rison.parser.bangs[c];
449
+ if (typeof(x) == 'function') {
450
+ return x.call(null, this);
451
+ } else if (typeof(x) == 'undefined') {
452
+ return this.error('unknown literal: "!' + c + '"');
453
+ }
454
+ return x;
455
+ },
456
+ '(': function () {
457
+ var o = {};
458
+ var c;
459
+ var count = 0;
460
+ while ((c = this.next()) != ')') {
461
+ if (count) {
462
+ if (c != ',')
463
+ this.error("missing ','");
464
+ } else if (c == ',') {
465
+ return this.error("extra ','");
466
+ } else
467
+ --this.index;
468
+ var k = this.readValue();
469
+ if (typeof k == "undefined") return undefined;
470
+ if (this.next() != ':') return this.error("missing ':'");
471
+ var v = this.readValue();
472
+ if (typeof v == "undefined") return undefined;
473
+ o[k] = v;
474
+ count++;
475
+ }
476
+ return o;
477
+ },
478
+ "\"": function () {
479
+ var s = this.string;
480
+ var i = this.index;
481
+ var start = i;
482
+ var segments = [];
483
+ var c;
484
+ while ((c = s.charAt(i++)) != "\"") {
485
+ //if (i == s.length) return this.error('unmatched "\""');
486
+ if (!c) return this.error('unmatched "\""');
487
+ if (c == '!') {
488
+ if (start < i-1)
489
+ segments.push(s.slice(start, i-1));
490
+ c = s.charAt(i++);
491
+ if ("!'".indexOf(c) >= 0) {
492
+ segments.push(c);
493
+ } else {
494
+ return this.error('invalid string escape: "!'+c+'"');
495
+ }
496
+ start = i;
497
+ }
498
+ }
499
+ if (start < i-1)
500
+ segments.push(s.slice(start, i-1));
501
+ this.index = i;
502
+ return segments.length == 1 ? segments[0] : segments.join("");
503
+ },
504
+ // Also any digit. The statement that follows this table
505
+ // definition fills in the digits.
506
+ '-': function () {
507
+ var s = this.string;
508
+ var i = this.index;
509
+ var start = i-1;
510
+ var state = 'int';
511
+ var permittedSigns = '-';
512
+ var transitions = {
513
+ 'int+.': 'frac',
514
+ 'int+e': 'exp',
515
+ 'frac+e': 'exp'
516
+ };
517
+ do {
518
+ var c = s.charAt(i++);
519
+ if (!c) break;
520
+ if ('0' <= c && c <= '9') continue;
521
+ if (permittedSigns.indexOf(c) >= 0) {
522
+ permittedSigns = "";
523
+ continue;
524
+ }
525
+ state = transitions[state+'+'+c.toLowerCase()];
526
+ if (state == 'exp') permittedSigns = '-';
527
+ } while (state);
528
+ this.index = --i;
529
+ s = s.slice(start, i)
530
+ if (s == '-') return this.error("invalid number");
531
+ return Number(s);
532
+ }
533
+ };
534
+ // copy table['-'] to each of table[i] | i <- '0'..'9':
535
+ (function (table) {
536
+ for (var i = 0; i <= 9; i++)
537
+ table[String(i)] = table['-'];
538
+ })(rison.parser.prototype.table);
539
+
540
+ // return the next non-whitespace character, or undefined
541
+ rison.parser.prototype.next = function () {
542
+ var s = this.string;
543
+ var i = this.index;
544
+ do {
545
+ if (i == s.length) return undefined;
546
+ var c = s.charAt(i++);
547
+ } while (rison.parser.WHITESPACE.indexOf(c) >= 0);
548
+ this.index = i;
549
+ return c;
550
+ };
551
+
552
+ // End of UMD module wrapper
553
+ }));