-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
91 lines (55 loc) · 1.53 KB
/
Copy pathindex.js
File metadata and controls
91 lines (55 loc) · 1.53 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
var hasOwnProperty = Object.prototype.hasOwnProperty
var hash = module.exports = function (/* Object */ data) {
this._data = data || {}
}
var escapeKey = hash.escapeKey = function (key) {
key = ''+key
// Check if key starts with "__"
// http://jsperf.com/check-if-string-starts-with
if (key.length > 2 && key.charCodeAt(0) == 95 && key.charCodeAt(1) == 95)
return key + '%'
return key
}
var unescapeKey = hash.unescapeKey = function (key) {
key = ''+key
var length = key.length
if (length > 2 && key.charCodeAt(0) == 95 && key.charCodeAt(1) == 95)
return key.substr(0, length - 1)
return key
}
hash.prototype.has = function (key) {
return hasOwnProperty.call(this._data, escapeKey(key))
}
hash.prototype.get = function (key) {
key = escapeKey(key)
return hasOwnProperty.call(this._data, key)
? this._data[key]
: undefined
}
hash.prototype.set = function (key, value) {
this._data[escapeKey(key)] = value
}
hash.prototype.del = function (key) {
delete this._data[escapeKey(key)]
}
hash.prototype.forEach = function (/* Function */ iterator, thisArg) {
var data = this._data,
key
for (var _key in data) {
if (!hasOwnProperty.call(data, _key))
continue
iterator.call(thisArg, data[_key], unescapeKey(_key))
}
}
hash.prototype.keys = function () {
var keys = []
this.forEach(function (value, key) {
keys.push(key)
})
return keys
}
hash.prototype.getData = function () {
return this._data
}
hash.prototype.valueOf = hash.prototype.getData
hash.prototype.toJSON = hash.prototype.getData