UNPKG

1.16 kBJavaScriptView Raw
1(function() {
2 var Tuple;
3
4 module.exports = Tuple = (function() {
5 Tuple.isHash = function(data) {
6 if (!data || data instanceof Array || typeof data !== "object") {
7 return false;
8 }
9 return true;
10 };
11
12 Tuple.DEFAULT = {
13 expire: 300
14 };
15
16 function Tuple(data) {
17 this.data = data;
18 this.__defineSetter__('expire', function(sec) {
19 return this.expire_at = Math.floor(Date.now() / 1000) + sec;
20 });
21 this.expire = 300;
22 }
23
24 Tuple.prototype.match = function(tuple) {
25 var data, k, v, _ref;
26 if (!Tuple.isHash(tuple)) {
27 return false;
28 }
29 data = tuple instanceof Tuple ? tuple.data : tuple;
30 _ref = this.data;
31 for (k in _ref) {
32 v = _ref[k];
33 if (typeof v === 'object') {
34 if (typeof data[k] !== 'object') {
35 return false;
36 }
37 if (JSON.stringify(v) !== JSON.stringify(data[k])) {
38 return false;
39 }
40 } else {
41 if (v !== data[k]) {
42 return false;
43 }
44 }
45 }
46 return true;
47 };
48
49 return Tuple;
50
51 })();
52
53}).call(this);