stylus-source 0.31.0 → 0.32.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (143) hide show
  1. checksums.yaml +7 -0
  2. data/VERSION +1 -1
  3. data/vendor/lib/nodes/unit.js +1 -1
  4. data/vendor/lib/parser.js +0 -1
  5. data/vendor/lib/renderer.js +2 -0
  6. data/vendor/lib/visitor/compiler.js +6 -0
  7. data/vendor/node_modules/cssom/README.mdown +34 -0
  8. data/vendor/node_modules/cssom/package.json +2 -1
  9. data/vendor/node_modules/debug/History.md +15 -0
  10. data/vendor/node_modules/debug/Readme.md +3 -18
  11. data/vendor/node_modules/debug/component.json +9 -0
  12. data/vendor/node_modules/debug/debug.js +10 -2
  13. data/vendor/node_modules/debug/index.js +5 -2
  14. data/vendor/node_modules/debug/lib/debug.js +5 -6
  15. data/vendor/node_modules/debug/package.json +11 -6
  16. data/vendor/node_modules/mkdirp/package.json +6 -9
  17. data/vendor/node_modules/mkdirp/{README.markdown → readme.markdown} +26 -24
  18. data/vendor/node_modules/mocha/History.md +140 -58
  19. data/vendor/node_modules/mocha/LICENSE +2 -2
  20. data/vendor/node_modules/mocha/Makefile +20 -5
  21. data/vendor/node_modules/mocha/Readme.md +110 -22
  22. data/vendor/node_modules/mocha/_mocha.js +574 -182
  23. data/vendor/node_modules/mocha/bin/_mocha +39 -22
  24. data/vendor/node_modules/mocha/bin/mocha +6 -2
  25. data/vendor/node_modules/mocha/component.json +16 -0
  26. data/vendor/node_modules/mocha/lib/browser/debug.js +1 -2
  27. data/vendor/node_modules/mocha/lib/browser/diff.js +287 -0
  28. data/vendor/node_modules/mocha/lib/browser/tty.js +7 -2
  29. data/vendor/node_modules/mocha/lib/hook.js +0 -1
  30. data/vendor/node_modules/mocha/lib/interfaces/bdd.js +3 -3
  31. data/vendor/node_modules/mocha/lib/interfaces/exports.js +5 -5
  32. data/vendor/node_modules/mocha/lib/interfaces/qunit.js +38 -9
  33. data/vendor/node_modules/mocha/lib/interfaces/tdd.js +15 -2
  34. data/vendor/node_modules/mocha/lib/mocha.js +20 -4
  35. data/vendor/node_modules/mocha/lib/reporters/base.js +57 -37
  36. data/vendor/node_modules/mocha/lib/reporters/html.js +2 -4
  37. data/vendor/node_modules/mocha/lib/reporters/json-stream.js +4 -14
  38. data/vendor/node_modules/mocha/lib/reporters/json.js +9 -19
  39. data/vendor/node_modules/mocha/lib/reporters/markdown.js +0 -1
  40. data/vendor/node_modules/mocha/lib/reporters/min.js +2 -2
  41. data/vendor/node_modules/mocha/lib/reporters/nyan.js +33 -39
  42. data/vendor/node_modules/mocha/lib/reporters/tap.js +12 -2
  43. data/vendor/node_modules/mocha/lib/reporters/templates/coverage.jade +3 -3
  44. data/vendor/node_modules/mocha/lib/reporters/templates/menu.jade +1 -1
  45. data/vendor/node_modules/mocha/lib/reporters/xunit.js +4 -4
  46. data/vendor/node_modules/mocha/lib/runnable.js +7 -9
  47. data/vendor/node_modules/mocha/lib/runner.js +24 -9
  48. data/vendor/node_modules/mocha/lib/template.html +2 -1
  49. data/vendor/node_modules/mocha/lib/utils.js +3 -3
  50. data/vendor/node_modules/mocha/mocha.css +37 -13
  51. data/vendor/node_modules/mocha/mocha.js +661 -253
  52. data/vendor/node_modules/mocha/node_modules/commander/package.json +5 -1
  53. data/vendor/node_modules/mocha/node_modules/diff/package.json +5 -1
  54. data/vendor/node_modules/mocha/node_modules/glob/LICENSE +27 -0
  55. data/vendor/node_modules/mocha/node_modules/glob/README.md +250 -0
  56. data/vendor/node_modules/mocha/node_modules/glob/examples/g.js +9 -0
  57. data/vendor/node_modules/mocha/node_modules/glob/examples/usr-local.js +9 -0
  58. data/vendor/node_modules/mocha/node_modules/glob/glob.js +675 -0
  59. data/vendor/node_modules/mocha/node_modules/glob/node_modules/graceful-fs/LICENSE +27 -0
  60. data/vendor/node_modules/mocha/node_modules/glob/node_modules/graceful-fs/README.md +33 -0
  61. data/vendor/node_modules/mocha/node_modules/glob/node_modules/graceful-fs/graceful-fs.js +442 -0
  62. data/vendor/node_modules/mocha/node_modules/glob/node_modules/graceful-fs/package.json +49 -0
  63. data/vendor/node_modules/mocha/node_modules/glob/node_modules/graceful-fs/test/open.js +46 -0
  64. data/vendor/node_modules/mocha/node_modules/glob/node_modules/graceful-fs/test/ulimit.js +158 -0
  65. data/vendor/node_modules/mocha/node_modules/glob/node_modules/inherits/README.md +51 -0
  66. data/vendor/node_modules/mocha/node_modules/glob/node_modules/inherits/inherits.js +29 -0
  67. data/vendor/node_modules/mocha/node_modules/glob/node_modules/inherits/package.json +26 -0
  68. data/vendor/node_modules/mocha/node_modules/glob/node_modules/minimatch/LICENSE +23 -0
  69. data/vendor/node_modules/mocha/node_modules/glob/node_modules/minimatch/README.md +218 -0
  70. data/vendor/node_modules/mocha/node_modules/glob/node_modules/minimatch/minimatch.js +1079 -0
  71. data/vendor/node_modules/mocha/node_modules/glob/node_modules/minimatch/node_modules/lru-cache/AUTHORS +8 -0
  72. data/vendor/node_modules/mocha/node_modules/glob/node_modules/minimatch/node_modules/lru-cache/LICENSE +23 -0
  73. data/vendor/node_modules/mocha/node_modules/glob/node_modules/minimatch/node_modules/lru-cache/README.md +97 -0
  74. data/vendor/node_modules/mocha/node_modules/glob/node_modules/minimatch/node_modules/lru-cache/lib/lru-cache.js +257 -0
  75. data/vendor/node_modules/mocha/node_modules/glob/node_modules/minimatch/node_modules/lru-cache/package.json +59 -0
  76. data/vendor/node_modules/mocha/node_modules/glob/node_modules/minimatch/node_modules/lru-cache/s.js +25 -0
  77. data/vendor/node_modules/mocha/node_modules/glob/node_modules/minimatch/node_modules/lru-cache/test/basic.js +329 -0
  78. data/vendor/node_modules/mocha/node_modules/glob/node_modules/minimatch/node_modules/lru-cache/test/foreach.js +52 -0
  79. data/vendor/node_modules/mocha/node_modules/glob/node_modules/minimatch/node_modules/lru-cache/test/memory-leak.js +50 -0
  80. data/vendor/node_modules/mocha/node_modules/glob/node_modules/minimatch/node_modules/sigmund/LICENSE +27 -0
  81. data/vendor/node_modules/mocha/node_modules/glob/node_modules/minimatch/node_modules/sigmund/README.md +53 -0
  82. data/vendor/node_modules/mocha/node_modules/glob/node_modules/minimatch/node_modules/sigmund/bench.js +283 -0
  83. data/vendor/node_modules/mocha/node_modules/glob/node_modules/minimatch/node_modules/sigmund/package.json +38 -0
  84. data/vendor/node_modules/mocha/node_modules/glob/node_modules/minimatch/node_modules/sigmund/sigmund.js +39 -0
  85. data/vendor/node_modules/mocha/node_modules/glob/node_modules/minimatch/node_modules/sigmund/test/basic.js +24 -0
  86. data/vendor/node_modules/mocha/node_modules/glob/node_modules/minimatch/package.json +36 -0
  87. data/vendor/node_modules/mocha/node_modules/glob/node_modules/minimatch/test/basic.js +399 -0
  88. data/vendor/node_modules/mocha/node_modules/glob/node_modules/minimatch/test/brace-expand.js +33 -0
  89. data/vendor/node_modules/mocha/node_modules/glob/node_modules/minimatch/test/caching.js +14 -0
  90. data/vendor/node_modules/mocha/node_modules/glob/node_modules/minimatch/test/defaults.js +274 -0
  91. data/vendor/node_modules/mocha/node_modules/glob/package.json +40 -0
  92. data/vendor/node_modules/mocha/node_modules/glob/test/00-setup.js +176 -0
  93. data/vendor/node_modules/mocha/node_modules/glob/test/bash-comparison.js +63 -0
  94. data/vendor/node_modules/mocha/node_modules/glob/test/bash-results.json +350 -0
  95. data/vendor/node_modules/mocha/node_modules/glob/test/cwd-test.js +55 -0
  96. data/vendor/node_modules/mocha/node_modules/glob/test/globstar-match.js +19 -0
  97. data/vendor/node_modules/mocha/node_modules/glob/test/mark.js +74 -0
  98. data/vendor/node_modules/mocha/node_modules/glob/test/nocase-nomagic.js +113 -0
  99. data/vendor/node_modules/mocha/node_modules/glob/test/pause-resume.js +73 -0
  100. data/vendor/node_modules/mocha/node_modules/glob/test/root-nomount.js +39 -0
  101. data/vendor/node_modules/mocha/node_modules/glob/test/root.js +46 -0
  102. data/vendor/node_modules/mocha/node_modules/glob/test/stat.js +32 -0
  103. data/vendor/node_modules/mocha/node_modules/glob/test/zz-cleanup.js +11 -0
  104. data/vendor/node_modules/mocha/node_modules/growl/History.md +5 -0
  105. data/vendor/node_modules/mocha/node_modules/growl/lib/growl.js +2 -0
  106. data/vendor/node_modules/mocha/node_modules/growl/package.json +7 -3
  107. data/vendor/node_modules/mocha/node_modules/jade/node_modules/mkdirp/package.json +5 -1
  108. data/vendor/node_modules/mocha/node_modules/jade/package.json +5 -1
  109. data/vendor/node_modules/mocha/node_modules/ms/package.json +5 -1
  110. data/vendor/node_modules/mocha/package.json +13 -7
  111. data/vendor/node_modules/mocha/test.js +10 -21
  112. data/vendor/node_modules/should/History.md +5 -0
  113. data/vendor/node_modules/should/Readme.md +172 -172
  114. data/vendor/node_modules/should/lib/eql.js +2 -0
  115. data/vendor/node_modules/should/lib/should.js +4 -3
  116. data/vendor/node_modules/should/package.json +8 -4
  117. data/vendor/node_modules/should/test/should.test.js +27 -0
  118. data/vendor/package.json +1 -1
  119. metadata +61 -35
  120. data/vendor/node_modules/debug/Makefile +0 -4
  121. data/vendor/node_modules/debug/debug.component.js +0 -120
  122. data/vendor/node_modules/debug/head.js +0 -1
  123. data/vendor/node_modules/debug/tail.js +0 -4
  124. data/vendor/node_modules/mocha/node_modules/mkdirp/LICENSE +0 -21
  125. data/vendor/node_modules/mocha/node_modules/mkdirp/README.markdown +0 -61
  126. data/vendor/node_modules/mocha/node_modules/mkdirp/examples/pow.js +0 -6
  127. data/vendor/node_modules/mocha/node_modules/mkdirp/examples/pow.js.orig +0 -6
  128. data/vendor/node_modules/mocha/node_modules/mkdirp/examples/pow.js.rej +0 -19
  129. data/vendor/node_modules/mocha/node_modules/mkdirp/index.js +0 -94
  130. data/vendor/node_modules/mocha/node_modules/mkdirp/package.json +0 -33
  131. data/vendor/node_modules/mocha/node_modules/mkdirp/test/chmod.js +0 -38
  132. data/vendor/node_modules/mocha/node_modules/mkdirp/test/clobber.js +0 -37
  133. data/vendor/node_modules/mocha/node_modules/mkdirp/test/mkdirp.js +0 -28
  134. data/vendor/node_modules/mocha/node_modules/mkdirp/test/perm.js +0 -32
  135. data/vendor/node_modules/mocha/node_modules/mkdirp/test/perm_sync.js +0 -39
  136. data/vendor/node_modules/mocha/node_modules/mkdirp/test/race.js +0 -41
  137. data/vendor/node_modules/mocha/node_modules/mkdirp/test/rel.js +0 -32
  138. data/vendor/node_modules/mocha/node_modules/mkdirp/test/return.js +0 -25
  139. data/vendor/node_modules/mocha/node_modules/mkdirp/test/return_sync.js +0 -24
  140. data/vendor/node_modules/mocha/node_modules/mkdirp/test/root.js +0 -18
  141. data/vendor/node_modules/mocha/node_modules/mkdirp/test/sync.js +0 -32
  142. data/vendor/node_modules/mocha/node_modules/mkdirp/test/umask.js +0 -28
  143. data/vendor/node_modules/mocha/node_modules/mkdirp/test/umask_sync.js +0 -32
@@ -0,0 +1,8 @@
1
+ # Authors, sorted by whether or not they are me
2
+ Isaac Z. Schlueter <i@izs.me>
3
+ Carlos Brito Lage <carlos@carloslage.net>
4
+ Marko Mikulicic <marko.mikulicic@isti.cnr.it>
5
+ Trent Mick <trentm@gmail.com>
6
+ Kevin O'Hara <kevinohara80@gmail.com>
7
+ Marco Rogers <marco.rogers@gmail.com>
8
+ Jesse Dailey <jesse.dailey@gmail.com>
@@ -0,0 +1,23 @@
1
+ Copyright 2009, 2010, 2011 Isaac Z. Schlueter.
2
+ All rights reserved.
3
+
4
+ Permission is hereby granted, free of charge, to any person
5
+ obtaining a copy of this software and associated documentation
6
+ files (the "Software"), to deal in the Software without
7
+ restriction, including without limitation the rights to use,
8
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the
10
+ Software is furnished to do so, subject to the following
11
+ conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23
+ OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,97 @@
1
+ # lru cache
2
+
3
+ A cache object that deletes the least-recently-used items.
4
+
5
+ ## Usage:
6
+
7
+ ```javascript
8
+ var LRU = require("lru-cache")
9
+ , options = { max: 500
10
+ , length: function (n) { return n * 2 }
11
+ , dispose: function (key, n) { n.close() }
12
+ , maxAge: 1000 * 60 * 60 }
13
+ , cache = LRU(options)
14
+ , otherCache = LRU(50) // sets just the max size
15
+
16
+ cache.set("key", "value")
17
+ cache.get("key") // "value"
18
+
19
+ cache.reset() // empty the cache
20
+ ```
21
+
22
+ If you put more stuff in it, then items will fall out.
23
+
24
+ If you try to put an oversized thing in it, then it'll fall out right
25
+ away.
26
+
27
+ ## Options
28
+
29
+ * `max` The maximum size of the cache, checked by applying the length
30
+ function to all values in the cache. Not setting this is kind of
31
+ silly, since that's the whole purpose of this lib, but it defaults
32
+ to `Infinity`.
33
+ * `maxAge` Maximum age in ms. Items are not pro-actively pruned out
34
+ as they age, but if you try to get an item that is too old, it'll
35
+ drop it and return undefined instead of giving it to you.
36
+ * `length` Function that is used to calculate the length of stored
37
+ items. If you're storing strings or buffers, then you probably want
38
+ to do something like `function(n){return n.length}`. The default is
39
+ `function(n){return 1}`, which is fine if you want to store `n`
40
+ like-sized things.
41
+ * `dispose` Function that is called on items when they are dropped
42
+ from the cache. This can be handy if you want to close file
43
+ descriptors or do other cleanup tasks when items are no longer
44
+ accessible. Called with `key, value`. It's called *before*
45
+ actually removing the item from the internal cache, so if you want
46
+ to immediately put it back in, you'll have to do that in a
47
+ `nextTick` or `setTimeout` callback or it won't do anything.
48
+ * `stale` By default, if you set a `maxAge`, it'll only actually pull
49
+ stale items out of the cache when you `get(key)`. (That is, it's
50
+ not pre-emptively doing a `setTimeout` or anything.) If you set
51
+ `stale:true`, it'll return the stale value before deleting it. If
52
+ you don't set this, then it'll return `undefined` when you try to
53
+ get a stale entry, as if it had already been deleted.
54
+
55
+ ## API
56
+
57
+ * `set(key, value)`
58
+ * `get(key) => value`
59
+
60
+ Both of these will update the "recently used"-ness of the key.
61
+ They do what you think.
62
+
63
+ * `peek(key)`
64
+
65
+ Returns the key value (or `undefined` if not found) without
66
+ updating the "recently used"-ness of the key.
67
+
68
+ (If you find yourself using this a lot, you *might* be using the
69
+ wrong sort of data structure, but there are some use cases where
70
+ it's handy.)
71
+
72
+ * `del(key)`
73
+
74
+ Deletes a key out of the cache.
75
+
76
+ * `reset()`
77
+
78
+ Clear the cache entirely, throwing away all values.
79
+
80
+ * `has(key)`
81
+
82
+ Check if a key is in the cache, without updating the recent-ness
83
+ or deleting it for being stale.
84
+
85
+ * `forEach(function(value,key,cache), [thisp])`
86
+
87
+ Just like `Array.prototype.forEach`. Iterates over all the keys
88
+ in the cache, in order of recent-ness. (Ie, more recently used
89
+ items are iterated over first.)
90
+
91
+ * `keys()`
92
+
93
+ Return an array of the keys in the cache.
94
+
95
+ * `values()`
96
+
97
+ Return an array of the values in the cache.
@@ -0,0 +1,257 @@
1
+ ;(function () { // closure for web browsers
2
+
3
+ if (typeof module === 'object' && module.exports) {
4
+ module.exports = LRUCache
5
+ } else {
6
+ // just set the global for non-node platforms.
7
+ this.LRUCache = LRUCache
8
+ }
9
+
10
+ function hOP (obj, key) {
11
+ return Object.prototype.hasOwnProperty.call(obj, key)
12
+ }
13
+
14
+ function naiveLength () { return 1 }
15
+
16
+ function LRUCache (options) {
17
+ if (!(this instanceof LRUCache)) {
18
+ return new LRUCache(options)
19
+ }
20
+
21
+ var max
22
+ if (typeof options === 'number') {
23
+ max = options
24
+ options = { max: max }
25
+ }
26
+
27
+ if (!options) options = {}
28
+
29
+ max = options.max
30
+
31
+ var lengthCalculator = options.length || naiveLength
32
+
33
+ if (typeof lengthCalculator !== "function") {
34
+ lengthCalculator = naiveLength
35
+ }
36
+
37
+ if (!max || !(typeof max === "number") || max <= 0 ) {
38
+ // a little bit silly. maybe this should throw?
39
+ max = Infinity
40
+ }
41
+
42
+ var allowStale = options.stale || false
43
+
44
+ var maxAge = options.maxAge || null
45
+
46
+ var dispose = options.dispose
47
+
48
+ var cache = Object.create(null) // hash of items by key
49
+ , lruList = Object.create(null) // list of items in order of use recency
50
+ , mru = 0 // most recently used
51
+ , lru = 0 // least recently used
52
+ , length = 0 // number of items in the list
53
+ , itemCount = 0
54
+
55
+
56
+ // resize the cache when the max changes.
57
+ Object.defineProperty(this, "max",
58
+ { set : function (mL) {
59
+ if (!mL || !(typeof mL === "number") || mL <= 0 ) mL = Infinity
60
+ max = mL
61
+ // if it gets above double max, trim right away.
62
+ // otherwise, do it whenever it's convenient.
63
+ if (length > max) trim()
64
+ }
65
+ , get : function () { return max }
66
+ , enumerable : true
67
+ })
68
+
69
+ // resize the cache when the lengthCalculator changes.
70
+ Object.defineProperty(this, "lengthCalculator",
71
+ { set : function (lC) {
72
+ if (typeof lC !== "function") {
73
+ lengthCalculator = naiveLength
74
+ length = itemCount
75
+ for (var key in cache) {
76
+ cache[key].length = 1
77
+ }
78
+ } else {
79
+ lengthCalculator = lC
80
+ length = 0
81
+ for (var key in cache) {
82
+ cache[key].length = lengthCalculator(cache[key].value)
83
+ length += cache[key].length
84
+ }
85
+ }
86
+
87
+ if (length > max) trim()
88
+ }
89
+ , get : function () { return lengthCalculator }
90
+ , enumerable : true
91
+ })
92
+
93
+ Object.defineProperty(this, "length",
94
+ { get : function () { return length }
95
+ , enumerable : true
96
+ })
97
+
98
+
99
+ Object.defineProperty(this, "itemCount",
100
+ { get : function () { return itemCount }
101
+ , enumerable : true
102
+ })
103
+
104
+ this.forEach = function (fn, thisp) {
105
+ thisp = thisp || this
106
+ var i = 0;
107
+ for (var k = mru - 1; k >= 0 && i < itemCount; k--) if (lruList[k]) {
108
+ i++
109
+ var hit = lruList[k]
110
+ fn.call(thisp, hit.value, hit.key, this)
111
+ }
112
+ }
113
+
114
+ this.keys = function () {
115
+ var keys = new Array(itemCount)
116
+ var i = 0
117
+ for (var k = mru - 1; k >= 0 && i < itemCount; k--) if (lruList[k]) {
118
+ var hit = lruList[k]
119
+ keys[i++] = hit.key
120
+ }
121
+ return keys
122
+ }
123
+
124
+ this.values = function () {
125
+ var values = new Array(itemCount)
126
+ var i = 0
127
+ for (var k = mru - 1; k >= 0 && i < itemCount; k--) if (lruList[k]) {
128
+ var hit = lruList[k]
129
+ values[i++] = hit.value
130
+ }
131
+ return values
132
+ }
133
+
134
+ this.reset = function () {
135
+ if (dispose) {
136
+ for (var k in cache) {
137
+ dispose(k, cache[k].value)
138
+ }
139
+ }
140
+ cache = {}
141
+ lruList = {}
142
+ lru = 0
143
+ mru = 0
144
+ length = 0
145
+ itemCount = 0
146
+ }
147
+
148
+ // Provided for debugging/dev purposes only. No promises whatsoever that
149
+ // this API stays stable.
150
+ this.dump = function () {
151
+ return cache
152
+ }
153
+
154
+ this.dumpLru = function () {
155
+ return lruList
156
+ }
157
+
158
+ this.set = function (key, value) {
159
+ if (hOP(cache, key)) {
160
+ // dispose of the old one before overwriting
161
+ if (dispose) dispose(key, cache[key].value)
162
+ if (maxAge) cache[key].now = Date.now()
163
+ cache[key].value = value
164
+ this.get(key)
165
+ return true
166
+ }
167
+
168
+ var len = lengthCalculator(value)
169
+ var age = maxAge ? Date.now() : 0
170
+ var hit = new Entry(key, value, mru++, len, age)
171
+
172
+ // oversized objects fall out of cache automatically.
173
+ if (hit.length > max) {
174
+ if (dispose) dispose(key, value)
175
+ return false
176
+ }
177
+
178
+ length += hit.length
179
+ lruList[hit.lu] = cache[key] = hit
180
+ itemCount ++
181
+
182
+ if (length > max) trim()
183
+ return true
184
+ }
185
+
186
+ this.has = function (key) {
187
+ if (!hOP(cache, key)) return false
188
+ var hit = cache[key]
189
+ if (maxAge && (Date.now() - hit.now > maxAge)) {
190
+ return false
191
+ }
192
+ return true
193
+ }
194
+
195
+ this.get = function (key) {
196
+ return get(key, true)
197
+ }
198
+
199
+ this.peek = function (key) {
200
+ return get(key, false)
201
+ }
202
+
203
+ function get (key, doUse) {
204
+ var hit = cache[key]
205
+ if (hit) {
206
+ if (maxAge && (Date.now() - hit.now > maxAge)) {
207
+ del(hit)
208
+ if (!allowStale) hit = undefined
209
+ } else {
210
+ if (doUse) use(hit)
211
+ }
212
+ if (hit) hit = hit.value
213
+ }
214
+ return hit
215
+ }
216
+
217
+ function use (hit) {
218
+ shiftLU(hit)
219
+ hit.lu = mru ++
220
+ lruList[hit.lu] = hit
221
+ }
222
+
223
+ this.del = function (key) {
224
+ del(cache[key])
225
+ }
226
+
227
+ function trim () {
228
+ while (lru < mru && length > max)
229
+ del(lruList[lru])
230
+ }
231
+
232
+ function shiftLU(hit) {
233
+ delete lruList[ hit.lu ]
234
+ while (lru < mru && !lruList[lru]) lru ++
235
+ }
236
+
237
+ function del(hit) {
238
+ if (hit) {
239
+ if (dispose) dispose(hit.key, hit.value)
240
+ length -= hit.length
241
+ itemCount --
242
+ delete cache[ hit.key ]
243
+ shiftLU(hit)
244
+ }
245
+ }
246
+ }
247
+
248
+ // classy, since V8 prefers predictable objects.
249
+ function Entry (key, value, mru, len, age) {
250
+ this.key = key
251
+ this.value = value
252
+ this.lu = mru
253
+ this.length = len
254
+ this.now = age
255
+ }
256
+
257
+ })()
@@ -0,0 +1,59 @@
1
+ {
2
+ "name": "lru-cache",
3
+ "description": "A cache object that deletes the least-recently-used items.",
4
+ "version": "2.3.0",
5
+ "author": {
6
+ "name": "Isaac Z. Schlueter",
7
+ "email": "i@izs.me"
8
+ },
9
+ "scripts": {
10
+ "test": "tap test --gc"
11
+ },
12
+ "main": "lib/lru-cache.js",
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git://github.com/isaacs/node-lru-cache.git"
16
+ },
17
+ "devDependencies": {
18
+ "tap": "",
19
+ "weak": ""
20
+ },
21
+ "license": {
22
+ "type": "MIT",
23
+ "url": "http://github.com/isaacs/node-lru-cache/raw/master/LICENSE"
24
+ },
25
+ "contributors": [
26
+ {
27
+ "name": "Isaac Z. Schlueter",
28
+ "email": "i@izs.me"
29
+ },
30
+ {
31
+ "name": "Carlos Brito Lage",
32
+ "email": "carlos@carloslage.net"
33
+ },
34
+ {
35
+ "name": "Marko Mikulicic",
36
+ "email": "marko.mikulicic@isti.cnr.it"
37
+ },
38
+ {
39
+ "name": "Trent Mick",
40
+ "email": "trentm@gmail.com"
41
+ },
42
+ {
43
+ "name": "Kevin O'Hara",
44
+ "email": "kevinohara80@gmail.com"
45
+ },
46
+ {
47
+ "name": "Marco Rogers",
48
+ "email": "marco.rogers@gmail.com"
49
+ },
50
+ {
51
+ "name": "Jesse Dailey",
52
+ "email": "jesse.dailey@gmail.com"
53
+ }
54
+ ],
55
+ "readme": "# lru cache\n\nA cache object that deletes the least-recently-used items.\n\n## Usage:\n\n```javascript\nvar LRU = require(\"lru-cache\")\n , options = { max: 500\n , length: function (n) { return n * 2 }\n , dispose: function (key, n) { n.close() }\n , maxAge: 1000 * 60 * 60 }\n , cache = LRU(options)\n , otherCache = LRU(50) // sets just the max size\n\ncache.set(\"key\", \"value\")\ncache.get(\"key\") // \"value\"\n\ncache.reset() // empty the cache\n```\n\nIf you put more stuff in it, then items will fall out.\n\nIf you try to put an oversized thing in it, then it'll fall out right\naway.\n\n## Options\n\n* `max` The maximum size of the cache, checked by applying the length\n function to all values in the cache. Not setting this is kind of\n silly, since that's the whole purpose of this lib, but it defaults\n to `Infinity`.\n* `maxAge` Maximum age in ms. Items are not pro-actively pruned out\n as they age, but if you try to get an item that is too old, it'll\n drop it and return undefined instead of giving it to you.\n* `length` Function that is used to calculate the length of stored\n items. If you're storing strings or buffers, then you probably want\n to do something like `function(n){return n.length}`. The default is\n `function(n){return 1}`, which is fine if you want to store `n`\n like-sized things.\n* `dispose` Function that is called on items when they are dropped\n from the cache. This can be handy if you want to close file\n descriptors or do other cleanup tasks when items are no longer\n accessible. Called with `key, value`. It's called *before*\n actually removing the item from the internal cache, so if you want\n to immediately put it back in, you'll have to do that in a\n `nextTick` or `setTimeout` callback or it won't do anything.\n* `stale` By default, if you set a `maxAge`, it'll only actually pull\n stale items out of the cache when you `get(key)`. (That is, it's\n not pre-emptively doing a `setTimeout` or anything.) If you set\n `stale:true`, it'll return the stale value before deleting it. If\n you don't set this, then it'll return `undefined` when you try to\n get a stale entry, as if it had already been deleted.\n\n## API\n\n* `set(key, value)`\n* `get(key) => value`\n\n Both of these will update the \"recently used\"-ness of the key.\n They do what you think.\n\n* `peek(key)`\n\n Returns the key value (or `undefined` if not found) without\n updating the \"recently used\"-ness of the key.\n\n (If you find yourself using this a lot, you *might* be using the\n wrong sort of data structure, but there are some use cases where\n it's handy.)\n\n* `del(key)`\n\n Deletes a key out of the cache.\n\n* `reset()`\n\n Clear the cache entirely, throwing away all values.\n\n* `has(key)`\n\n Check if a key is in the cache, without updating the recent-ness\n or deleting it for being stale.\n\n* `forEach(function(value,key,cache), [thisp])`\n\n Just like `Array.prototype.forEach`. Iterates over all the keys\n in the cache, in order of recent-ness. (Ie, more recently used\n items are iterated over first.)\n\n* `keys()`\n\n Return an array of the keys in the cache.\n\n* `values()`\n\n Return an array of the values in the cache.\n",
56
+ "readmeFilename": "README.md",
57
+ "_id": "lru-cache@2.3.0",
58
+ "_from": "lru-cache@2"
59
+ }
@@ -0,0 +1,25 @@
1
+ var LRU = require('lru-cache');
2
+
3
+ var max = +process.argv[2] || 10240;
4
+ var more = 1024;
5
+
6
+ var cache = LRU({
7
+ max: max, maxAge: 86400e3
8
+ });
9
+
10
+ // fill cache
11
+ for (var i = 0; i < max; ++i) {
12
+ cache.set(i, {});
13
+ }
14
+
15
+ var start = process.hrtime();
16
+
17
+ // adding more items
18
+ for ( ; i < max+more; ++i) {
19
+ cache.set(i, {});
20
+ }
21
+
22
+ var end = process.hrtime(start);
23
+ var msecs = end[0] * 1E3 + end[1] / 1E6;
24
+
25
+ console.log('adding %d items took %d ms', more, msecs.toPrecision(5));