Repository navigation
Expand file tree
/
Copy pathnewforms.js
More file actions
8298 lines (7523 loc) · 236 KB
/
Copy pathnewforms.js
File metadata and controls
8298 lines (7523 loc) · 236 KB
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
/**
* newforms 0.4.2 - https://github.com/insin/newforms
* MIT Licensed
*/
;(function() {
var _require = window.require
, modules = {}
function require(name) {
return modules[name]
}
require.noConflict = function() {
if (window.require === require) {
window.require = _require
}
}
require.define = function(rs, fn) {
var module = {}
, exports = {}
module.exports = exports
fn(module, exports, require)
if (Object.prototype.toString.call(rs) == '[object Array]') {
for (var i = 0, l = rs.length; i < l; i++) {
modules[rs[i]] = module.exports
}
}
else {
modules[rs] = module.exports
}
}
require.define(["isomorph/is","./is"], function(module, exports, require) {
var toString = Object.prototype.toString
// Type checks
function isArray(o) {
return toString.call(o) == '[object Array]'
}
function isBoolean(o) {
return toString.call(o) == '[object Boolean]'
}
function isDate(o) {
return toString.call(o) == '[object Date]'
}
function isError(o) {
return toString.call(o) == '[object Error]'
}
function isFunction(o) {
return toString.call(o) == '[object Function]'
}
function isNumber(o) {
return toString.call(o) == '[object Number]'
}
function isObject(o) {
return toString.call(o) == '[object Object]'
}
function isRegExp(o) {
return toString.call(o) == '[object RegExp]'
}
function isString(o) {
return toString.call(o) == '[object String]'
}
// Content checks
function isEmpty(o) {
for (var prop in o) {
return false
}
return true
}
module.exports = {
Array: isArray
, Boolean: isBoolean
, Date: isDate
, Empty: isEmpty
, Error: isError
, Function: isFunction
, NaN: isNaN
, Number: isNumber
, Object: isObject
, RegExp: isRegExp
, String: isString
}
})
require.define("isomorph/format", function(module, exports, require) {
var is = require('./is')
, slice = Array.prototype.slice
, formatRegExp = /%[%s]/g
, formatObjRegExp = /({{?)(\w+)}/g
/**
* Replaces %s placeholders in a string with positional arguments.
*/
function format(s) {
return formatArr(s, slice.call(arguments, 1))
}
/**
* Replaces %s placeholders in a string with array contents.
*/
function formatArr(s, a) {
var i = 0
return s.replace(formatRegExp, function(m) { return m == '%%' ? '%' : a[i++] })
}
/**
* Replaces {propertyName} placeholders in a string with object properties.
*/
function formatObj(s, o) {
return s.replace(formatObjRegExp, function(m, b, p) { return b.length == 2 ? m.slice(1) : o[p] })
}
var units = 'kMGTPEZY'
, stripDecimals = /\.00$|0$/
/**
* Formats bytes as a file size with the appropriately scaled units.
*/
function fileSize(bytes, threshold) {
threshold = Math.min(threshold || 768, 1024)
var i = -1
, unit = 'bytes'
, size = bytes
while (size > threshold && i < units.length) {
size = size / 1024
i++
}
if (i > -1) {
unit = units.charAt(i) + 'B'
}
return size.toFixed(2).replace(stripDecimals, '') + ' ' + unit
}
module.exports = {
format: format
, formatArr: formatArr
, formatObj: formatObj
, fileSize: fileSize
}
})
require.define("isomorph/object", function(module, exports, require) {
/**
* Callbound version of Object.prototype.hasOwnProperty(), ready to be called
* with an object and property name.
*/
var hasOwn = (function() {
var hasOwnProperty = Object.prototype.hasOwnProperty
return function(obj, prop) { return hasOwnProperty.call(obj, prop) }
})()
/**
* Copies own properties from any given objects to a destination object.
*/
function extend(dest) {
for (var i = 1, l = arguments.length, src; i < l; i++) {
src = arguments[i]
if (src) {
for (var prop in src) {
if (hasOwn(src, prop)) {
dest[prop] = src[prop]
}
}
}
}
return dest
}
/**
* Makes a constructor inherit another constructor's prototype without
* having to actually use the constructor.
*/
function inherits(childConstructor, parentConstructor) {
var F = function() {}
F.prototype = parentConstructor.prototype
childConstructor.prototype = new F()
childConstructor.prototype.constructor = childConstructor
return childConstructor
}
/**
* Creates an Array of [property, value] pairs from an Object.
*/
function items(obj) {
var items = []
for (var prop in obj) {
if (hasOwn(obj, prop)) {
items.push([prop, obj[prop]])
}
}
return items
}
/**
* Creates an Object from an Array of [property, value] pairs.
*/
function fromItems(items) {
var obj = {}
for (var i = 0, l = items.length, item; i < l; i++) {
item = items[i]
obj[item[0]] = item[1]
}
return obj
}
/**
* Creates a lookup Object from an Array, coercing each item to a String.
*/
function lookup(arr) {
var obj = {}
for (var i = 0, l = arr.length; i < l; i++) {
obj[''+arr[i]] = true
}
return obj
}
/**
* If the given object has the given property, returns its value, otherwise
* returns the given default value.
*/
function get(obj, prop, defaultValue) {
return (hasOwn(obj, prop) ? obj[prop] : defaultValue)
}
module.exports = {
hasOwn: hasOwn
, extend: extend
, inherits: inherits
, items: items
, fromItems: fromItems
, lookup: lookup
, get: get
}
})
require.define("isomorph/array", function(module, exports, require) {
var is = require('./is')
var splice = Array.prototype.splice
/**
* Flattens an Array in-place, replacing any Arrays it contains with their
* contents, and flattening their contents in turn.
*/
function flatten(arr) {
for (var i = 0, l = arr.length, current; i < l; i++) {
current = arr[i]
if (is.Array(current)) {
// Make sure we loop to the Array's new length
l += current.length - 1
// Replace the current item with its contents
splice.apply(arr, [i, 1].concat(current))
// Stay on the current index so we continue looping at the first
// element of the array we just spliced in or removed.
i--
}
}
// We flattened in-place, but return for chaining
return arr
}
module.exports = {
flatten: flatten
}
})
require.define("isomorph/copy", function(module, exports, require) {
var is = require('./is')
/* This file is part of OWL JavaScript Utilities.
OWL JavaScript Utilities is free software: you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public License
as published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
OWL JavaScript Utilities is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with OWL JavaScript Utilities. If not, see
<http://www.gnu.org/licenses/>.
*/
// Re-usable constructor function used by clone()
function Clone() {}
// Clone objects, skip other types
function clone(target) {
if (typeof target == 'object') {
Clone.prototype = target
return new Clone()
}
else {
return target
}
}
// Shallow Copy
function copy(target) {
if (typeof target != 'object') {
// Non-objects have value semantics, so target is already a copy
return target
}
else {
var value = target.valueOf()
if (target != value) {
// the object is a standard object wrapper for a native type, say String.
// we can make a copy by instantiating a new object around the value.
return new target.constructor(value)
}
else {
// We have a normal object. If possible, we'll clone the original's
// prototype (not the original) to get an empty object with the same
// prototype chain as the original. If just copy the instance properties.
// Otherwise, we have to copy the whole thing, property-by-property.
if (target instanceof target.constructor && target.constructor !== Object) {
var c = clone(target.constructor.prototype)
// Give the copy all the instance properties of target. It has the same
// prototype as target, so inherited properties are already there.
for (var property in target) {
if (target.hasOwnProperty(property)) {
c[property] = target[property]
}
}
}
else {
var c = {}
for (var property in target) {
c[property] = target[property]
}
}
return c
}
}
}
// Deep Copy
var deepCopiers = []
function DeepCopier(config) {
for (var key in config) {
this[key] = config[key]
}
}
DeepCopier.prototype = {
constructor: DeepCopier
// Determines if this DeepCopier can handle the given object.
, canCopy: function(source) { return false }
// Starts the deep copying process by creating the copy object. You can
// initialize any properties you want, but you can't call recursively into the
// DeepCopyAlgorithm.
, create: function(source) {}
// Completes the deep copy of the source object by populating any properties
// that need to be recursively deep copied. You can do this by using the
// provided deepCopyAlgorithm instance's deepCopy() method. This will handle
// cyclic references for objects already deepCopied, including the source
// object itself. The "result" passed in is the object returned from create().
, populate: function(deepCopyAlgorithm, source, result) {}
}
function DeepCopyAlgorithm() {
// copiedObjects keeps track of objects already copied by this deepCopy
// operation, so we can correctly handle cyclic references.
this.copiedObjects = []
var thisPass = this
this.recursiveDeepCopy = function(source) {
return thisPass.deepCopy(source)
}
this.depth = 0
}
DeepCopyAlgorithm.prototype = {
constructor: DeepCopyAlgorithm
, maxDepth: 256
// Add an object to the cache. No attempt is made to filter duplicates; we
// always check getCachedResult() before calling it.
, cacheResult: function(source, result) {
this.copiedObjects.push([source, result])
}
// Returns the cached copy of a given object, or undefined if it's an object
// we haven't seen before.
, getCachedResult: function(source) {
var copiedObjects = this.copiedObjects
var length = copiedObjects.length
for ( var i=0; i<length; i++ ) {
if ( copiedObjects[i][0] === source ) {
return copiedObjects[i][1]
}
}
return undefined
}
// deepCopy handles the simple cases itself: non-objects and object's we've
// seen before. For complex cases, it first identifies an appropriate
// DeepCopier, then calls applyDeepCopier() to delegate the details of copying
// the object to that DeepCopier.
, deepCopy: function(source) {
// null is a special case: it's the only value of type 'object' without
// properties.
if (source === null) return null
// All non-objects use value semantics and don't need explict copying
if (typeof source != 'object') return source
var cachedResult = this.getCachedResult(source)
// We've already seen this object during this deep copy operation so can
// immediately return the result. This preserves the cyclic reference
// structure and protects us from infinite recursion.
if (cachedResult) return cachedResult
// Objects may need special handling depending on their class. There is a
// class of handlers call "DeepCopiers" that know how to copy certain
// objects. There is also a final, generic deep copier that can handle any
// object.
for (var i=0; i<deepCopiers.length; i++) {
var deepCopier = deepCopiers[i]
if (deepCopier.canCopy(source)) {
return this.applyDeepCopier(deepCopier, source)
}
}
// The generic copier can handle anything, so we should never reach this
// line.
throw new Error('no DeepCopier is able to copy ' + source)
}
// Once we've identified which DeepCopier to use, we need to call it in a
// very particular order: create, cache, populate.This is the key to detecting
// cycles. We also keep track of recursion depth when calling the potentially
// recursive populate(): this is a fail-fast to prevent an infinite loop from
// consuming all available memory and crashing or slowing down the browser.
, applyDeepCopier: function(deepCopier, source) {
// Start by creating a stub object that represents the copy.
var result = deepCopier.create(source)
// We now know the deep copy of source should always be result, so if we
// encounter source again during this deep copy we can immediately use
// result instead of descending into it recursively.
this.cacheResult(source, result)
// Only DeepCopier.populate() can recursively deep copy. o, to keep track
// of recursion depth, we increment this shared counter before calling it,
// and decrement it afterwards.
this.depth++
if (this.depth > this.maxDepth) {
throw new Error("Exceeded max recursion depth in deep copy.")
}
// It's now safe to let the deepCopier recursively deep copy its properties
deepCopier.populate(this.recursiveDeepCopy, source, result)
this.depth--
return result
}
}
// Entry point for deep copy.
// source is the object to be deep copied.
// maxDepth is an optional recursion limit. Defaults to 256.
function deepCopy(source, maxDepth) {
var deepCopyAlgorithm = new DeepCopyAlgorithm()
if (maxDepth) {
deepCopyAlgorithm.maxDepth = maxDepth
}
return deepCopyAlgorithm.deepCopy(source)
}
// Publicly expose the DeepCopier class
deepCopy.DeepCopier = DeepCopier
// Publicly expose the list of deepCopiers
deepCopy.deepCopiers = deepCopiers
// Make deepCopy() extensible by allowing others to register their own custom
// DeepCopiers.
deepCopy.register = function(deepCopier) {
if (!(deepCopier instanceof DeepCopier)) {
deepCopier = new DeepCopier(deepCopier)
}
deepCopiers.unshift(deepCopier)
}
// Generic Object copier
// The ultimate fallback DeepCopier, which tries to handle the generic case.
// This should work for base Objects and many user-defined classes.
deepCopy.register({
canCopy: function(source) { return true }
, create: function(source) {
if (source instanceof source.constructor) {
return clone(source.constructor.prototype)
}
else {
return {}
}
}
, populate: function(deepCopy, source, result) {
for (var key in source) {
if (source.hasOwnProperty(key)) {
result[key] = deepCopy(source[key])
}
}
return result
}
})
// Array copier
deepCopy.register({
canCopy: function(source) {
return is.Array(source)
}
, create: function(source) {
return new source.constructor()
}
, populate: function(deepCopy, source, result) {
for (var i = 0; i < source.length; i++) {
result.push(deepCopy(source[i]))
}
return result
}
})
// Date copier
deepCopy.register({
canCopy: function(source) {
return is.Date(source)
}
, create: function(source) {
return new Date(source)
}
})
// RegExp copier
deepCopy.register({
canCopy: function(source) {
return is.RegExp(source)
}
, create: function(source) {
return source
}
})
module.exports = {
DeepCopyAlgorithm: DeepCopyAlgorithm
, copy: copy
, clone: clone
, deepCopy: deepCopy
}
})
require.define("isomorph/time", function(module, exports, require) {
var is = require('./is')
/**
* Pads a number with a leading zero if necessary.
*/
function pad(number) {
return (number < 10 ? '0' + number : number)
}
/**
* Returns the index of item in list, or -1 if it's not in list.
*/
function indexOf(item, list) {
for (var i = 0, l = list.length; i < l; i++) {
if (item === list[i]) {
return i
}
}
return -1
}
/**
* Maps directive codes to regular expression patterns which will capture the
* data the directive corresponds to, or in the case of locale-dependent
* directives, a function which takes a locale and generates a regular
* expression pattern.
*/
var parserDirectives = {
// Locale's abbreviated month name
'b': function(l) { return '(' + l.b.join('|') + ')' }
// Locale's full month name
, 'B': function(l) { return '(' + l.B.join('|') + ')' }
// Locale's equivalent of either AM or PM.
, 'p': function(l) { return '(' + l.AM + '|' + l.PM + ')' }
, 'd': '(\\d\\d?)' // Day of the month as a decimal number [01,31]
, 'H': '(\\d\\d?)' // Hour (24-hour clock) as a decimal number [00,23]
, 'I': '(\\d\\d?)' // Hour (12-hour clock) as a decimal number [01,12]
, 'm': '(\\d\\d?)' // Month as a decimal number [01,12]
, 'M': '(\\d\\d?)' // Minute as a decimal number [00,59]
, 'S': '(\\d\\d?)' // Second as a decimal number [00,59]
, 'y': '(\\d\\d?)' // Year without century as a decimal number [00,99]
, 'Y': '(\\d{4})' // Year with century as a decimal number
, '%': '%' // A literal '%' character
}
/**
* Maps directive codes to functions which take the date to be formatted and
* locale details (if required), returning an appropriate formatted value.
*/
var formatterDirectives = {
'a': function(d, l) { return l.a[d.getDay()] }
, 'A': function(d, l) { return l.A[d.getDay()] }
, 'b': function(d, l) { return l.b[d.getMonth()] }
, 'B': function(d, l) { return l.B[d.getMonth()] }
, 'd': function(d) { return pad(d.getDate(), 2) }
, 'H': function(d) { return pad(d.getHours(), 2) }
, 'M': function(d) { return pad(d.getMinutes(), 2) }
, 'm': function(d) { return pad(d.getMonth() + 1, 2) }
, 'S': function(d) { return pad(d.getSeconds(), 2) }
, 'w': function(d) { return d.getDay() }
, 'Y': function(d) { return d.getFullYear() }
, '%': function(d) { return '%' }
}
/** Test for hanging percentage symbols. */
var strftimeFormatCheck = /[^%]%$/
/**
* A partial implementation of strptime which parses time details from a string,
* based on a format string.
* @param {String} format
* @param {Object} locale
*/
function TimeParser(format, locale) {
this.format = format
this.locale = locale
var cachedPattern = TimeParser._cache[locale.name + '|' + format]
if (cachedPattern !== undefined) {
this.re = cachedPattern[0]
this.matchOrder = cachedPattern[1]
}
else {
this.compilePattern()
}
}
/**
* Caches RegExps and match orders generated per locale/format string combo.
*/
TimeParser._cache = {}
TimeParser.prototype.compilePattern = function() {
// Normalise whitespace before further processing
var format = this.format.split(/(?:\s|\t|\n)+/).join(' ')
, pattern = []
, matchOrder = []
, c
, directive
for (var i = 0, l = format.length; i < l; i++) {
c = format.charAt(i)
if (c != '%') {
if (c === ' ') {
pattern.push(' +')
}
else {
pattern.push(c)
}
continue
}
if (i == l - 1) {
throw new Error('strptime format ends with raw %')
}
c = format.charAt(++i)
directive = parserDirectives[c]
if (directive === undefined) {
throw new Error('strptime format contains an unknown directive: %' + c)
}
else if (is.Function(directive)) {
pattern.push(directive(this.locale))
}
else {
pattern.push(directive)
}
if (c != '%') {
matchOrder.push(c)
}
}
this.re = new RegExp('^' + pattern.join('') + '$')
this.matchOrder = matchOrder
TimeParser._cache[this.locale.name + '|' + this.format] = [this.re, matchOrder]
}
/**
* Attempts to extract date and time details from the given input.
* @param {string} input
* @return {Array.<number>}
*/
TimeParser.prototype.parse = function(input) {
var matches = this.re.exec(input)
if (matches === null) {
throw new Error('Time data did not match format: data=' + input +
', format=' + this.format)
}
// Default values for when more accurate values cannot be inferred
var time = [1900, 1, 1, 0, 0, 0]
// Matched time data, keyed by directive code
, data = {}
for (var i = 1, l = matches.length; i < l; i++) {
data[this.matchOrder[i - 1]] = matches[i]
}
// Extract year
if (data.hasOwnProperty('Y')) {
time[0] = parseInt(data.Y, 10)
}
else if (data.hasOwnProperty('y')) {
var year = parseInt(data.y, 10)
if (year < 68) {
year = 2000 + year
}
else if (year < 100) {
year = 1900 + year
}
time[0] = year
}
// Extract month
if (data.hasOwnProperty('m')) {
var month = parseInt(data.m, 10)
if (month < 1 || month > 12) {
throw new Error('Month is out of range: ' + month)
}
time[1] = month
}
else if (data.hasOwnProperty('B')) {
time[1] = indexOf(data.B, this.locale.B) + 1
}
else if (data.hasOwnProperty('b')) {
time[1] = indexOf(data.b, this.locale.b) + 1
}
// Extract day of month
if (data.hasOwnProperty('d')) {
var day = parseInt(data.d, 10)
if (day < 1 || day > 31) {
throw new Error('Day is out of range: ' + day)
}
time[2] = day
}
// Extract hour
if (data.hasOwnProperty('H')) {
var hour = parseInt(data.H, 10)
if (hour > 23) {
throw new Error('Hour is out of range: ' + hour)
}
time[3] = hour
}
else if (data.hasOwnProperty('I')) {
var hour = parseInt(data.I, 10)
if (hour < 1 || hour > 12) {
throw new Error('Hour is out of range: ' + hour)
}
// If we don't get any more information, we'll assume this time is
// a.m. - 12 a.m. is midnight.
if (hour == 12) {
hour = 0
}
time[3] = hour
if (data.hasOwnProperty('p')) {
if (data.p == this.locale.PM) {
// We've already handled the midnight special case, so it's
// safe to bump the time by 12 hours without further checks.
time[3] = time[3] + 12
}
}
}
// Extract minute
if (data.hasOwnProperty('M')) {
var minute = parseInt(data.M, 10)
if (minute > 59) {
throw new Error('Minute is out of range: ' + minute)
}
time[4] = minute
}
// Extract seconds
if (data.hasOwnProperty('S')) {
var second = parseInt(data.S, 10)
if (second > 59) {
throw new Error('Second is out of range: ' + second)
}
time[5] = second
}
// Validate day of month
var day = time[2], month = time[1], year = time[0]
if (((month == 4 || month == 6 || month == 9 || month == 11) &&
day > 30) ||
(month == 2 && day > ((year % 4 == 0 && year % 100 != 0 ||
year % 400 == 0) ? 29 : 28))) {
throw new Error('Day is out of range: ' + day)
}
return time
}
var time = {
/** Default locale name. */
defaultLocale: 'en'
/** Locale details. */
, locales: {
en: {
name: 'en'
, a: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']
, A: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday',
'Friday', 'Saturday']
, AM: 'AM'
, b: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep',
'Oct', 'Nov', 'Dec']
, B: ['January', 'February', 'March', 'April', 'May', 'June', 'July',
'August', 'September', 'October', 'November', 'December']
, PM: 'PM'
}
}
}
/**
* Retrieves the locale with the given code.
* @param {string} code
* @return {Object}
*/
var getLocale = time.getLocale = function(code) {
if (code) {
if (time.locales.hasOwnProperty(code)) {
return time.locales[code]
}
else if (code.length > 2) {
// If we appear to have more than a language code, try the
// language code on its own.
var languageCode = code.substring(0, 2)
if (time.locales.hasOwnProperty(languageCode)) {
return time.locales[languageCode]
}
}
}
return time.locales[time.defaultLocale]
}
/**
* Parses time details from a string, based on a format string.
* @param {string} input
* @param {string} format
* @param {string=} locale
* @return {Array.<number>}
*/
var strptime = time.strptime = function(input, format, locale) {
return new TimeParser(format, getLocale(locale)).parse(input)
}
/**
* Convenience wrapper around time.strptime which returns a JavaScript Date.
* @param {string} input
* @param {string} format
* @param {string=} locale
* @return {date}
*/
time.strpdate = function(input, format, locale) {
var t = strptime(input, format, locale)
return new Date(t[0], t[1] - 1, t[2], t[3], t[4], t[5])
}
/**
* A partial implementation of <code>strftime</code>, which formats a date
* according to a format string. An Error will be thrown if an invalid
* format string is given.
* @param {date} date
* @param {string} format
* @param {string=} locale
* @return {string}
*/
time.strftime = function(date, format, locale) {
if (strftimeFormatCheck.test(format)) {
throw new Error('strftime format ends with raw %')
}
locale = getLocale(locale)
return format.replace(/(%.)/g, function(s, f) {
var code = f.charAt(1)
if (typeof formatterDirectives[code] == 'undefined') {
throw new Error('strftime format contains an unknown directive: ' + f)
}
return formatterDirectives[code](date, locale)
})
}
module.exports = time
})
require.define("isomorph/url", function(module, exports, require) {
// parseUri 1.2.2
// (c) Steven Levithan <stevenlevithan.com>
// MIT License
function parseUri (str) {
var o = parseUri.options
, m = o.parser[o.strictMode ? "strict" : "loose"].exec(str)
, uri = {}
, i = 14
while (i--) uri[o.key[i]] = m[i] || ""
uri[o.q.name] = {};
uri[o.key[12]].replace(o.q.parser, function ($0, $1, $2) {
if ($1) uri[o.q.name][$1] = $2
})
return uri
}
parseUri.options = {
strictMode: false
, key: ['source','protocol','authority','userInfo','user','password','host','port','relative','path','directory','file','query','anchor']
, q: {
name: 'queryKey'
, parser: /(?:^|&)([^&=]*)=?([^&]*)/g
}
, parser: {
strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/
, loose: /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/
}
}
// makeURI 1.2.2 - create a URI from an object specification; compatible with
// parseURI (http://blog.stevenlevithan.com/archives/parseuri)
// (c) Niall Smart <niallsmart.com>
// MIT License
function makeUri(u) {
var uri = ''
if (u.protocol) {
uri += u.protocol + '://'
}
if (u.user) {
uri += u.user
}
if (u.password) {
uri += ':' + u.password
}
if (u.user || u.password) {
uri += '@'
}
if (u.host) {
uri += u.host
}
if (u.port) {
uri += ':' + u.port
}
if (u.path) {
uri += u.path
}
var qk = u.queryKey
var qs = []
for (var k in qk) {
if (!qk.hasOwnProperty(k)) {
continue
}
var v = encodeURIComponent(qk[k])
k = encodeURIComponent(k)
if (v) {
qs.push(k + '=' + v)
}