parent
33edd91c61
commit
0505300de9
@ -1 +1,16 @@
|
|||||||
../color-support/bin.js
|
#!/bin/sh
|
||||||
|
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
|
||||||
|
|
||||||
|
case `uname` in
|
||||||
|
*CYGWIN*|*MINGW*|*MSYS*)
|
||||||
|
if command -v cygpath > /dev/null 2>&1; then
|
||||||
|
basedir=`cygpath -w "$basedir"`
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
if [ -x "$basedir/node" ]; then
|
||||||
|
exec "$basedir/node" "$basedir/../color-support/bin.js" "$@"
|
||||||
|
else
|
||||||
|
exec node "$basedir/../color-support/bin.js" "$@"
|
||||||
|
fi
|
||||||
|
|||||||
@ -1 +1,16 @@
|
|||||||
../@mapbox/node-pre-gyp/bin/node-pre-gyp
|
#!/bin/sh
|
||||||
|
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
|
||||||
|
|
||||||
|
case `uname` in
|
||||||
|
*CYGWIN*|*MINGW*|*MSYS*)
|
||||||
|
if command -v cygpath > /dev/null 2>&1; then
|
||||||
|
basedir=`cygpath -w "$basedir"`
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
if [ -x "$basedir/node" ]; then
|
||||||
|
exec "$basedir/node" "$basedir/../@mapbox/node-pre-gyp/bin/node-pre-gyp" "$@"
|
||||||
|
else
|
||||||
|
exec node "$basedir/../@mapbox/node-pre-gyp/bin/node-pre-gyp" "$@"
|
||||||
|
fi
|
||||||
|
|||||||
@ -1 +1,16 @@
|
|||||||
../nopt/bin/nopt.js
|
#!/bin/sh
|
||||||
|
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
|
||||||
|
|
||||||
|
case `uname` in
|
||||||
|
*CYGWIN*|*MINGW*|*MSYS*)
|
||||||
|
if command -v cygpath > /dev/null 2>&1; then
|
||||||
|
basedir=`cygpath -w "$basedir"`
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
if [ -x "$basedir/node" ]; then
|
||||||
|
exec "$basedir/node" "$basedir/../nopt/bin/nopt.js" "$@"
|
||||||
|
else
|
||||||
|
exec node "$basedir/../nopt/bin/nopt.js" "$@"
|
||||||
|
fi
|
||||||
|
|||||||
@ -1 +1,16 @@
|
|||||||
../semver/bin/semver.js
|
#!/bin/sh
|
||||||
|
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
|
||||||
|
|
||||||
|
case `uname` in
|
||||||
|
*CYGWIN*|*MINGW*|*MSYS*)
|
||||||
|
if command -v cygpath > /dev/null 2>&1; then
|
||||||
|
basedir=`cygpath -w "$basedir"`
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
if [ -x "$basedir/node" ]; then
|
||||||
|
exec "$basedir/node" "$basedir/../semver/bin/semver.js" "$@"
|
||||||
|
else
|
||||||
|
exec node "$basedir/../semver/bin/semver.js" "$@"
|
||||||
|
fi
|
||||||
|
|||||||
@ -1,15 +0,0 @@
|
|||||||
The ISC License
|
|
||||||
|
|
||||||
Copyright (c) Isaac Z. Schlueter and Contributors
|
|
||||||
|
|
||||||
Permission to use, copy, modify, and/or distribute this software for any
|
|
||||||
purpose with or without fee is hereby granted, provided that the above
|
|
||||||
copyright notice and this permission notice appear in all copies.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
||||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
||||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
||||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
||||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
|
|
||||||
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
@ -1,166 +0,0 @@
|
|||||||
# lru cache
|
|
||||||
|
|
||||||
A cache object that deletes the least-recently-used items.
|
|
||||||
|
|
||||||
[](https://travis-ci.org/isaacs/node-lru-cache) [](https://coveralls.io/github/isaacs/node-lru-cache)
|
|
||||||
|
|
||||||
## Installation:
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
npm install lru-cache --save
|
|
||||||
```
|
|
||||||
|
|
||||||
## Usage:
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
var LRU = require("lru-cache")
|
|
||||||
, options = { max: 500
|
|
||||||
, length: function (n, key) { return n * 2 + key.length }
|
|
||||||
, dispose: function (key, n) { n.close() }
|
|
||||||
, maxAge: 1000 * 60 * 60 }
|
|
||||||
, cache = new LRU(options)
|
|
||||||
, otherCache = new LRU(50) // sets just the max size
|
|
||||||
|
|
||||||
cache.set("key", "value")
|
|
||||||
cache.get("key") // "value"
|
|
||||||
|
|
||||||
// non-string keys ARE fully supported
|
|
||||||
// but note that it must be THE SAME object, not
|
|
||||||
// just a JSON-equivalent object.
|
|
||||||
var someObject = { a: 1 }
|
|
||||||
cache.set(someObject, 'a value')
|
|
||||||
// Object keys are not toString()-ed
|
|
||||||
cache.set('[object Object]', 'a different value')
|
|
||||||
assert.equal(cache.get(someObject), 'a value')
|
|
||||||
// A similar object with same keys/values won't work,
|
|
||||||
// because it's a different object identity
|
|
||||||
assert.equal(cache.get({ a: 1 }), undefined)
|
|
||||||
|
|
||||||
cache.reset() // empty the cache
|
|
||||||
```
|
|
||||||
|
|
||||||
If you put more stuff in it, then items will fall out.
|
|
||||||
|
|
||||||
If you try to put an oversized thing in it, then it'll fall out right
|
|
||||||
away.
|
|
||||||
|
|
||||||
## Options
|
|
||||||
|
|
||||||
* `max` The maximum size of the cache, checked by applying the length
|
|
||||||
function to all values in the cache. Not setting this is kind of
|
|
||||||
silly, since that's the whole purpose of this lib, but it defaults
|
|
||||||
to `Infinity`. Setting it to a non-number or negative number will
|
|
||||||
throw a `TypeError`. Setting it to 0 makes it be `Infinity`.
|
|
||||||
* `maxAge` Maximum age in ms. Items are not pro-actively pruned out
|
|
||||||
as they age, but if you try to get an item that is too old, it'll
|
|
||||||
drop it and return undefined instead of giving it to you.
|
|
||||||
Setting this to a negative value will make everything seem old!
|
|
||||||
Setting it to a non-number will throw a `TypeError`.
|
|
||||||
* `length` Function that is used to calculate the length of stored
|
|
||||||
items. If you're storing strings or buffers, then you probably want
|
|
||||||
to do something like `function(n, key){return n.length}`. The default is
|
|
||||||
`function(){return 1}`, which is fine if you want to store `max`
|
|
||||||
like-sized things. The item is passed as the first argument, and
|
|
||||||
the key is passed as the second argumnet.
|
|
||||||
* `dispose` Function that is called on items when they are dropped
|
|
||||||
from the cache. This can be handy if you want to close file
|
|
||||||
descriptors or do other cleanup tasks when items are no longer
|
|
||||||
accessible. Called with `key, value`. It's called *before*
|
|
||||||
actually removing the item from the internal cache, so if you want
|
|
||||||
to immediately put it back in, you'll have to do that in a
|
|
||||||
`nextTick` or `setTimeout` callback or it won't do anything.
|
|
||||||
* `stale` By default, if you set a `maxAge`, it'll only actually pull
|
|
||||||
stale items out of the cache when you `get(key)`. (That is, it's
|
|
||||||
not pre-emptively doing a `setTimeout` or anything.) If you set
|
|
||||||
`stale:true`, it'll return the stale value before deleting it. If
|
|
||||||
you don't set this, then it'll return `undefined` when you try to
|
|
||||||
get a stale entry, as if it had already been deleted.
|
|
||||||
* `noDisposeOnSet` By default, if you set a `dispose()` method, then
|
|
||||||
it'll be called whenever a `set()` operation overwrites an existing
|
|
||||||
key. If you set this option, `dispose()` will only be called when a
|
|
||||||
key falls out of the cache, not when it is overwritten.
|
|
||||||
* `updateAgeOnGet` When using time-expiring entries with `maxAge`,
|
|
||||||
setting this to `true` will make each item's effective time update
|
|
||||||
to the current time whenever it is retrieved from cache, causing it
|
|
||||||
to not expire. (It can still fall out of cache based on recency of
|
|
||||||
use, of course.)
|
|
||||||
|
|
||||||
## API
|
|
||||||
|
|
||||||
* `set(key, value, maxAge)`
|
|
||||||
* `get(key) => value`
|
|
||||||
|
|
||||||
Both of these will update the "recently used"-ness of the key.
|
|
||||||
They do what you think. `maxAge` is optional and overrides the
|
|
||||||
cache `maxAge` option if provided.
|
|
||||||
|
|
||||||
If the key is not found, `get()` will return `undefined`.
|
|
||||||
|
|
||||||
The key and val can be any value.
|
|
||||||
|
|
||||||
* `peek(key)`
|
|
||||||
|
|
||||||
Returns the key value (or `undefined` if not found) without
|
|
||||||
updating the "recently used"-ness of the key.
|
|
||||||
|
|
||||||
(If you find yourself using this a lot, you *might* be using the
|
|
||||||
wrong sort of data structure, but there are some use cases where
|
|
||||||
it's handy.)
|
|
||||||
|
|
||||||
* `del(key)`
|
|
||||||
|
|
||||||
Deletes a key out of the cache.
|
|
||||||
|
|
||||||
* `reset()`
|
|
||||||
|
|
||||||
Clear the cache entirely, throwing away all values.
|
|
||||||
|
|
||||||
* `has(key)`
|
|
||||||
|
|
||||||
Check if a key is in the cache, without updating the recent-ness
|
|
||||||
or deleting it for being stale.
|
|
||||||
|
|
||||||
* `forEach(function(value,key,cache), [thisp])`
|
|
||||||
|
|
||||||
Just like `Array.prototype.forEach`. Iterates over all the keys
|
|
||||||
in the cache, in order of recent-ness. (Ie, more recently used
|
|
||||||
items are iterated over first.)
|
|
||||||
|
|
||||||
* `rforEach(function(value,key,cache), [thisp])`
|
|
||||||
|
|
||||||
The same as `cache.forEach(...)` but items are iterated over in
|
|
||||||
reverse order. (ie, less recently used items are iterated over
|
|
||||||
first.)
|
|
||||||
|
|
||||||
* `keys()`
|
|
||||||
|
|
||||||
Return an array of the keys in the cache.
|
|
||||||
|
|
||||||
* `values()`
|
|
||||||
|
|
||||||
Return an array of the values in the cache.
|
|
||||||
|
|
||||||
* `length`
|
|
||||||
|
|
||||||
Return total length of objects in cache taking into account
|
|
||||||
`length` options function.
|
|
||||||
|
|
||||||
* `itemCount`
|
|
||||||
|
|
||||||
Return total quantity of objects currently in cache. Note, that
|
|
||||||
`stale` (see options) items are returned as part of this item
|
|
||||||
count.
|
|
||||||
|
|
||||||
* `dump()`
|
|
||||||
|
|
||||||
Return an array of the cache entries ready for serialization and usage
|
|
||||||
with 'destinationCache.load(arr)`.
|
|
||||||
|
|
||||||
* `load(cacheEntriesArray)`
|
|
||||||
|
|
||||||
Loads another cache entries array, obtained with `sourceCache.dump()`,
|
|
||||||
into the cache. The destination cache is reset before loading new entries
|
|
||||||
|
|
||||||
* `prune()`
|
|
||||||
|
|
||||||
Manually iterates over the entire cache proactively pruning old entries
|
|
||||||
@ -1,334 +0,0 @@
|
|||||||
'use strict'
|
|
||||||
|
|
||||||
// A linked list to keep track of recently-used-ness
|
|
||||||
const Yallist = require('yallist')
|
|
||||||
|
|
||||||
const MAX = Symbol('max')
|
|
||||||
const LENGTH = Symbol('length')
|
|
||||||
const LENGTH_CALCULATOR = Symbol('lengthCalculator')
|
|
||||||
const ALLOW_STALE = Symbol('allowStale')
|
|
||||||
const MAX_AGE = Symbol('maxAge')
|
|
||||||
const DISPOSE = Symbol('dispose')
|
|
||||||
const NO_DISPOSE_ON_SET = Symbol('noDisposeOnSet')
|
|
||||||
const LRU_LIST = Symbol('lruList')
|
|
||||||
const CACHE = Symbol('cache')
|
|
||||||
const UPDATE_AGE_ON_GET = Symbol('updateAgeOnGet')
|
|
||||||
|
|
||||||
const naiveLength = () => 1
|
|
||||||
|
|
||||||
// lruList is a yallist where the head is the youngest
|
|
||||||
// item, and the tail is the oldest. the list contains the Hit
|
|
||||||
// objects as the entries.
|
|
||||||
// Each Hit object has a reference to its Yallist.Node. This
|
|
||||||
// never changes.
|
|
||||||
//
|
|
||||||
// cache is a Map (or PseudoMap) that matches the keys to
|
|
||||||
// the Yallist.Node object.
|
|
||||||
class LRUCache {
|
|
||||||
constructor (options) {
|
|
||||||
if (typeof options === 'number')
|
|
||||||
options = { max: options }
|
|
||||||
|
|
||||||
if (!options)
|
|
||||||
options = {}
|
|
||||||
|
|
||||||
if (options.max && (typeof options.max !== 'number' || options.max < 0))
|
|
||||||
throw new TypeError('max must be a non-negative number')
|
|
||||||
// Kind of weird to have a default max of Infinity, but oh well.
|
|
||||||
const max = this[MAX] = options.max || Infinity
|
|
||||||
|
|
||||||
const lc = options.length || naiveLength
|
|
||||||
this[LENGTH_CALCULATOR] = (typeof lc !== 'function') ? naiveLength : lc
|
|
||||||
this[ALLOW_STALE] = options.stale || false
|
|
||||||
if (options.maxAge && typeof options.maxAge !== 'number')
|
|
||||||
throw new TypeError('maxAge must be a number')
|
|
||||||
this[MAX_AGE] = options.maxAge || 0
|
|
||||||
this[DISPOSE] = options.dispose
|
|
||||||
this[NO_DISPOSE_ON_SET] = options.noDisposeOnSet || false
|
|
||||||
this[UPDATE_AGE_ON_GET] = options.updateAgeOnGet || false
|
|
||||||
this.reset()
|
|
||||||
}
|
|
||||||
|
|
||||||
// resize the cache when the max changes.
|
|
||||||
set max (mL) {
|
|
||||||
if (typeof mL !== 'number' || mL < 0)
|
|
||||||
throw new TypeError('max must be a non-negative number')
|
|
||||||
|
|
||||||
this[MAX] = mL || Infinity
|
|
||||||
trim(this)
|
|
||||||
}
|
|
||||||
get max () {
|
|
||||||
return this[MAX]
|
|
||||||
}
|
|
||||||
|
|
||||||
set allowStale (allowStale) {
|
|
||||||
this[ALLOW_STALE] = !!allowStale
|
|
||||||
}
|
|
||||||
get allowStale () {
|
|
||||||
return this[ALLOW_STALE]
|
|
||||||
}
|
|
||||||
|
|
||||||
set maxAge (mA) {
|
|
||||||
if (typeof mA !== 'number')
|
|
||||||
throw new TypeError('maxAge must be a non-negative number')
|
|
||||||
|
|
||||||
this[MAX_AGE] = mA
|
|
||||||
trim(this)
|
|
||||||
}
|
|
||||||
get maxAge () {
|
|
||||||
return this[MAX_AGE]
|
|
||||||
}
|
|
||||||
|
|
||||||
// resize the cache when the lengthCalculator changes.
|
|
||||||
set lengthCalculator (lC) {
|
|
||||||
if (typeof lC !== 'function')
|
|
||||||
lC = naiveLength
|
|
||||||
|
|
||||||
if (lC !== this[LENGTH_CALCULATOR]) {
|
|
||||||
this[LENGTH_CALCULATOR] = lC
|
|
||||||
this[LENGTH] = 0
|
|
||||||
this[LRU_LIST].forEach(hit => {
|
|
||||||
hit.length = this[LENGTH_CALCULATOR](hit.value, hit.key)
|
|
||||||
this[LENGTH] += hit.length
|
|
||||||
})
|
|
||||||
}
|
|
||||||
trim(this)
|
|
||||||
}
|
|
||||||
get lengthCalculator () { return this[LENGTH_CALCULATOR] }
|
|
||||||
|
|
||||||
get length () { return this[LENGTH] }
|
|
||||||
get itemCount () { return this[LRU_LIST].length }
|
|
||||||
|
|
||||||
rforEach (fn, thisp) {
|
|
||||||
thisp = thisp || this
|
|
||||||
for (let walker = this[LRU_LIST].tail; walker !== null;) {
|
|
||||||
const prev = walker.prev
|
|
||||||
forEachStep(this, fn, walker, thisp)
|
|
||||||
walker = prev
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
forEach (fn, thisp) {
|
|
||||||
thisp = thisp || this
|
|
||||||
for (let walker = this[LRU_LIST].head; walker !== null;) {
|
|
||||||
const next = walker.next
|
|
||||||
forEachStep(this, fn, walker, thisp)
|
|
||||||
walker = next
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
keys () {
|
|
||||||
return this[LRU_LIST].toArray().map(k => k.key)
|
|
||||||
}
|
|
||||||
|
|
||||||
values () {
|
|
||||||
return this[LRU_LIST].toArray().map(k => k.value)
|
|
||||||
}
|
|
||||||
|
|
||||||
reset () {
|
|
||||||
if (this[DISPOSE] &&
|
|
||||||
this[LRU_LIST] &&
|
|
||||||
this[LRU_LIST].length) {
|
|
||||||
this[LRU_LIST].forEach(hit => this[DISPOSE](hit.key, hit.value))
|
|
||||||
}
|
|
||||||
|
|
||||||
this[CACHE] = new Map() // hash of items by key
|
|
||||||
this[LRU_LIST] = new Yallist() // list of items in order of use recency
|
|
||||||
this[LENGTH] = 0 // length of items in the list
|
|
||||||
}
|
|
||||||
|
|
||||||
dump () {
|
|
||||||
return this[LRU_LIST].map(hit =>
|
|
||||||
isStale(this, hit) ? false : {
|
|
||||||
k: hit.key,
|
|
||||||
v: hit.value,
|
|
||||||
e: hit.now + (hit.maxAge || 0)
|
|
||||||
}).toArray().filter(h => h)
|
|
||||||
}
|
|
||||||
|
|
||||||
dumpLru () {
|
|
||||||
return this[LRU_LIST]
|
|
||||||
}
|
|
||||||
|
|
||||||
set (key, value, maxAge) {
|
|
||||||
maxAge = maxAge || this[MAX_AGE]
|
|
||||||
|
|
||||||
if (maxAge && typeof maxAge !== 'number')
|
|
||||||
throw new TypeError('maxAge must be a number')
|
|
||||||
|
|
||||||
const now = maxAge ? Date.now() : 0
|
|
||||||
const len = this[LENGTH_CALCULATOR](value, key)
|
|
||||||
|
|
||||||
if (this[CACHE].has(key)) {
|
|
||||||
if (len > this[MAX]) {
|
|
||||||
del(this, this[CACHE].get(key))
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
const node = this[CACHE].get(key)
|
|
||||||
const item = node.value
|
|
||||||
|
|
||||||
// dispose of the old one before overwriting
|
|
||||||
// split out into 2 ifs for better coverage tracking
|
|
||||||
if (this[DISPOSE]) {
|
|
||||||
if (!this[NO_DISPOSE_ON_SET])
|
|
||||||
this[DISPOSE](key, item.value)
|
|
||||||
}
|
|
||||||
|
|
||||||
item.now = now
|
|
||||||
item.maxAge = maxAge
|
|
||||||
item.value = value
|
|
||||||
this[LENGTH] += len - item.length
|
|
||||||
item.length = len
|
|
||||||
this.get(key)
|
|
||||||
trim(this)
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
const hit = new Entry(key, value, len, now, maxAge)
|
|
||||||
|
|
||||||
// oversized objects fall out of cache automatically.
|
|
||||||
if (hit.length > this[MAX]) {
|
|
||||||
if (this[DISPOSE])
|
|
||||||
this[DISPOSE](key, value)
|
|
||||||
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
this[LENGTH] += hit.length
|
|
||||||
this[LRU_LIST].unshift(hit)
|
|
||||||
this[CACHE].set(key, this[LRU_LIST].head)
|
|
||||||
trim(this)
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
has (key) {
|
|
||||||
if (!this[CACHE].has(key)) return false
|
|
||||||
const hit = this[CACHE].get(key).value
|
|
||||||
return !isStale(this, hit)
|
|
||||||
}
|
|
||||||
|
|
||||||
get (key) {
|
|
||||||
return get(this, key, true)
|
|
||||||
}
|
|
||||||
|
|
||||||
peek (key) {
|
|
||||||
return get(this, key, false)
|
|
||||||
}
|
|
||||||
|
|
||||||
pop () {
|
|
||||||
const node = this[LRU_LIST].tail
|
|
||||||
if (!node)
|
|
||||||
return null
|
|
||||||
|
|
||||||
del(this, node)
|
|
||||||
return node.value
|
|
||||||
}
|
|
||||||
|
|
||||||
del (key) {
|
|
||||||
del(this, this[CACHE].get(key))
|
|
||||||
}
|
|
||||||
|
|
||||||
load (arr) {
|
|
||||||
// reset the cache
|
|
||||||
this.reset()
|
|
||||||
|
|
||||||
const now = Date.now()
|
|
||||||
// A previous serialized cache has the most recent items first
|
|
||||||
for (let l = arr.length - 1; l >= 0; l--) {
|
|
||||||
const hit = arr[l]
|
|
||||||
const expiresAt = hit.e || 0
|
|
||||||
if (expiresAt === 0)
|
|
||||||
// the item was created without expiration in a non aged cache
|
|
||||||
this.set(hit.k, hit.v)
|
|
||||||
else {
|
|
||||||
const maxAge = expiresAt - now
|
|
||||||
// dont add already expired items
|
|
||||||
if (maxAge > 0) {
|
|
||||||
this.set(hit.k, hit.v, maxAge)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
prune () {
|
|
||||||
this[CACHE].forEach((value, key) => get(this, key, false))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const get = (self, key, doUse) => {
|
|
||||||
const node = self[CACHE].get(key)
|
|
||||||
if (node) {
|
|
||||||
const hit = node.value
|
|
||||||
if (isStale(self, hit)) {
|
|
||||||
del(self, node)
|
|
||||||
if (!self[ALLOW_STALE])
|
|
||||||
return undefined
|
|
||||||
} else {
|
|
||||||
if (doUse) {
|
|
||||||
if (self[UPDATE_AGE_ON_GET])
|
|
||||||
node.value.now = Date.now()
|
|
||||||
self[LRU_LIST].unshiftNode(node)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return hit.value
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const isStale = (self, hit) => {
|
|
||||||
if (!hit || (!hit.maxAge && !self[MAX_AGE]))
|
|
||||||
return false
|
|
||||||
|
|
||||||
const diff = Date.now() - hit.now
|
|
||||||
return hit.maxAge ? diff > hit.maxAge
|
|
||||||
: self[MAX_AGE] && (diff > self[MAX_AGE])
|
|
||||||
}
|
|
||||||
|
|
||||||
const trim = self => {
|
|
||||||
if (self[LENGTH] > self[MAX]) {
|
|
||||||
for (let walker = self[LRU_LIST].tail;
|
|
||||||
self[LENGTH] > self[MAX] && walker !== null;) {
|
|
||||||
// We know that we're about to delete this one, and also
|
|
||||||
// what the next least recently used key will be, so just
|
|
||||||
// go ahead and set it now.
|
|
||||||
const prev = walker.prev
|
|
||||||
del(self, walker)
|
|
||||||
walker = prev
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const del = (self, node) => {
|
|
||||||
if (node) {
|
|
||||||
const hit = node.value
|
|
||||||
if (self[DISPOSE])
|
|
||||||
self[DISPOSE](hit.key, hit.value)
|
|
||||||
|
|
||||||
self[LENGTH] -= hit.length
|
|
||||||
self[CACHE].delete(hit.key)
|
|
||||||
self[LRU_LIST].removeNode(node)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class Entry {
|
|
||||||
constructor (key, value, length, now, maxAge) {
|
|
||||||
this.key = key
|
|
||||||
this.value = value
|
|
||||||
this.length = length
|
|
||||||
this.now = now
|
|
||||||
this.maxAge = maxAge || 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const forEachStep = (self, fn, node, thisp) => {
|
|
||||||
let hit = node.value
|
|
||||||
if (isStale(self, hit)) {
|
|
||||||
del(self, node)
|
|
||||||
if (!self[ALLOW_STALE])
|
|
||||||
hit = undefined
|
|
||||||
}
|
|
||||||
if (hit)
|
|
||||||
fn.call(thisp, hit.value, hit.key, self)
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = LRUCache
|
|
||||||
@ -1,34 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "lru-cache",
|
|
||||||
"description": "A cache object that deletes the least-recently-used items.",
|
|
||||||
"version": "6.0.0",
|
|
||||||
"author": "Isaac Z. Schlueter <i@izs.me>",
|
|
||||||
"keywords": [
|
|
||||||
"mru",
|
|
||||||
"lru",
|
|
||||||
"cache"
|
|
||||||
],
|
|
||||||
"scripts": {
|
|
||||||
"test": "tap",
|
|
||||||
"snap": "tap",
|
|
||||||
"preversion": "npm test",
|
|
||||||
"postversion": "npm publish",
|
|
||||||
"prepublishOnly": "git push origin --follow-tags"
|
|
||||||
},
|
|
||||||
"main": "index.js",
|
|
||||||
"repository": "git://github.com/isaacs/node-lru-cache.git",
|
|
||||||
"devDependencies": {
|
|
||||||
"benchmark": "^2.1.4",
|
|
||||||
"tap": "^14.10.7"
|
|
||||||
},
|
|
||||||
"license": "ISC",
|
|
||||||
"dependencies": {
|
|
||||||
"yallist": "^4.0.0"
|
|
||||||
},
|
|
||||||
"files": [
|
|
||||||
"index.js"
|
|
||||||
],
|
|
||||||
"engines": {
|
|
||||||
"node": ">=10"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
17
node_modules/@mapbox/node-pre-gyp/node_modules/make-dir/node_modules/.bin/semver
generated
vendored
17
node_modules/@mapbox/node-pre-gyp/node_modules/make-dir/node_modules/.bin/semver
generated
vendored
@ -1 +1,16 @@
|
|||||||
../semver/bin/semver.js
|
#!/bin/sh
|
||||||
|
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
|
||||||
|
|
||||||
|
case `uname` in
|
||||||
|
*CYGWIN*|*MINGW*|*MSYS*)
|
||||||
|
if command -v cygpath > /dev/null 2>&1; then
|
||||||
|
basedir=`cygpath -w "$basedir"`
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
if [ -x "$basedir/node" ]; then
|
||||||
|
exec "$basedir/node" "$basedir/../semver/bin/semver.js" "$@"
|
||||||
|
else
|
||||||
|
exec node "$basedir/../semver/bin/semver.js" "$@"
|
||||||
|
fi
|
||||||
|
|||||||
70
node_modules/@mapbox/node-pre-gyp/node_modules/make-dir/node_modules/semver/CHANGELOG.md
generated
vendored
70
node_modules/@mapbox/node-pre-gyp/node_modules/make-dir/node_modules/semver/CHANGELOG.md
generated
vendored
@ -1,70 +0,0 @@
|
|||||||
# changes log
|
|
||||||
|
|
||||||
## 6.2.0
|
|
||||||
|
|
||||||
* Coerce numbers to strings when passed to semver.coerce()
|
|
||||||
* Add `rtl` option to coerce from right to left
|
|
||||||
|
|
||||||
## 6.1.3
|
|
||||||
|
|
||||||
* Handle X-ranges properly in includePrerelease mode
|
|
||||||
|
|
||||||
## 6.1.2
|
|
||||||
|
|
||||||
* Do not throw when testing invalid version strings
|
|
||||||
|
|
||||||
## 6.1.1
|
|
||||||
|
|
||||||
* Add options support for semver.coerce()
|
|
||||||
* Handle undefined version passed to Range.test
|
|
||||||
|
|
||||||
## 6.1.0
|
|
||||||
|
|
||||||
* Add semver.compareBuild function
|
|
||||||
* Support `*` in semver.intersects
|
|
||||||
|
|
||||||
## 6.0
|
|
||||||
|
|
||||||
* Fix `intersects` logic.
|
|
||||||
|
|
||||||
This is technically a bug fix, but since it is also a change to behavior
|
|
||||||
that may require users updating their code, it is marked as a major
|
|
||||||
version increment.
|
|
||||||
|
|
||||||
## 5.7
|
|
||||||
|
|
||||||
* Add `minVersion` method
|
|
||||||
|
|
||||||
## 5.6
|
|
||||||
|
|
||||||
* Move boolean `loose` param to an options object, with
|
|
||||||
backwards-compatibility protection.
|
|
||||||
* Add ability to opt out of special prerelease version handling with
|
|
||||||
the `includePrerelease` option flag.
|
|
||||||
|
|
||||||
## 5.5
|
|
||||||
|
|
||||||
* Add version coercion capabilities
|
|
||||||
|
|
||||||
## 5.4
|
|
||||||
|
|
||||||
* Add intersection checking
|
|
||||||
|
|
||||||
## 5.3
|
|
||||||
|
|
||||||
* Add `minSatisfying` method
|
|
||||||
|
|
||||||
## 5.2
|
|
||||||
|
|
||||||
* Add `prerelease(v)` that returns prerelease components
|
|
||||||
|
|
||||||
## 5.1
|
|
||||||
|
|
||||||
* Add Backus-Naur for ranges
|
|
||||||
* Remove excessively cute inspection methods
|
|
||||||
|
|
||||||
## 5.0
|
|
||||||
|
|
||||||
* Remove AMD/Browserified build artifacts
|
|
||||||
* Fix ltr and gtr when using the `*` range
|
|
||||||
* Fix for range `*` with a prerelease identifier
|
|
||||||
28
node_modules/@mapbox/node-pre-gyp/node_modules/make-dir/node_modules/semver/package.json
generated
vendored
28
node_modules/@mapbox/node-pre-gyp/node_modules/make-dir/node_modules/semver/package.json
generated
vendored
95
node_modules/@mapbox/node-pre-gyp/node_modules/make-dir/node_modules/semver/semver.js
generated
vendored
95
node_modules/@mapbox/node-pre-gyp/node_modules/make-dir/node_modules/semver/semver.js
generated
vendored
@ -1,23 +1,65 @@
|
|||||||
const parse = require('./parse')
|
const parse = require('./parse.js')
|
||||||
const eq = require('./eq')
|
|
||||||
|
|
||||||
const diff = (version1, version2) => {
|
const diff = (version1, version2) => {
|
||||||
if (eq(version1, version2)) {
|
const v1 = parse(version1, null, true)
|
||||||
|
const v2 = parse(version2, null, true)
|
||||||
|
const comparison = v1.compare(v2)
|
||||||
|
|
||||||
|
if (comparison === 0) {
|
||||||
return null
|
return null
|
||||||
} else {
|
|
||||||
const v1 = parse(version1)
|
|
||||||
const v2 = parse(version2)
|
|
||||||
const hasPre = v1.prerelease.length || v2.prerelease.length
|
|
||||||
const prefix = hasPre ? 'pre' : ''
|
|
||||||
const defaultResult = hasPre ? 'prerelease' : ''
|
|
||||||
for (const key in v1) {
|
|
||||||
if (key === 'major' || key === 'minor' || key === 'patch') {
|
|
||||||
if (v1[key] !== v2[key]) {
|
|
||||||
return prefix + key
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const v1Higher = comparison > 0
|
||||||
|
const highVersion = v1Higher ? v1 : v2
|
||||||
|
const lowVersion = v1Higher ? v2 : v1
|
||||||
|
const highHasPre = !!highVersion.prerelease.length
|
||||||
|
const lowHasPre = !!lowVersion.prerelease.length
|
||||||
|
|
||||||
|
if (lowHasPre && !highHasPre) {
|
||||||
|
// Going from prerelease -> no prerelease requires some special casing
|
||||||
|
|
||||||
|
// If the low version has only a major, then it will always be a major
|
||||||
|
// Some examples:
|
||||||
|
// 1.0.0-1 -> 1.0.0
|
||||||
|
// 1.0.0-1 -> 1.1.1
|
||||||
|
// 1.0.0-1 -> 2.0.0
|
||||||
|
if (!lowVersion.patch && !lowVersion.minor) {
|
||||||
|
return 'major'
|
||||||
|
}
|
||||||
|
|
||||||
|
// Otherwise it can be determined by checking the high version
|
||||||
|
|
||||||
|
if (highVersion.patch) {
|
||||||
|
// anything higher than a patch bump would result in the wrong version
|
||||||
|
return 'patch'
|
||||||
|
}
|
||||||
|
|
||||||
|
if (highVersion.minor) {
|
||||||
|
// anything higher than a minor bump would result in the wrong version
|
||||||
|
return 'minor'
|
||||||
|
}
|
||||||
|
|
||||||
|
// bumping major/minor/patch all have same result
|
||||||
|
return 'major'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// add the `pre` prefix if we are going to a prerelease version
|
||||||
|
const prefix = highHasPre ? 'pre' : ''
|
||||||
|
|
||||||
|
if (v1.major !== v2.major) {
|
||||||
|
return prefix + 'major'
|
||||||
}
|
}
|
||||||
return defaultResult // may be undefined
|
|
||||||
|
if (v1.minor !== v2.minor) {
|
||||||
|
return prefix + 'minor'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (v1.patch !== v2.patch) {
|
||||||
|
return prefix + 'patch'
|
||||||
|
}
|
||||||
|
|
||||||
|
// high and low are preleases
|
||||||
|
return 'prerelease'
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = diff
|
module.exports = diff
|
||||||
|
|||||||
@ -1,33 +1,16 @@
|
|||||||
const { MAX_LENGTH } = require('../internal/constants')
|
|
||||||
const { re, t } = require('../internal/re')
|
|
||||||
const SemVer = require('../classes/semver')
|
const SemVer = require('../classes/semver')
|
||||||
|
const parse = (version, options, throwErrors = false) => {
|
||||||
const parseOptions = require('../internal/parse-options')
|
|
||||||
const parse = (version, options) => {
|
|
||||||
options = parseOptions(options)
|
|
||||||
|
|
||||||
if (version instanceof SemVer) {
|
if (version instanceof SemVer) {
|
||||||
return version
|
return version
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof version !== 'string') {
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
if (version.length > MAX_LENGTH) {
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
const r = options.loose ? re[t.LOOSE] : re[t.FULL]
|
|
||||||
if (!r.test(version)) {
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return new SemVer(version, options)
|
return new SemVer(version, options)
|
||||||
} catch (er) {
|
} catch (er) {
|
||||||
|
if (!throwErrors) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
throw er
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = parse
|
module.exports = parse
|
||||||
|
|||||||
24
node_modules/@mapbox/node-pre-gyp/node_modules/semver/internal/parse-options.js
generated
vendored
24
node_modules/@mapbox/node-pre-gyp/node_modules/semver/internal/parse-options.js
generated
vendored
@ -1,11 +1,15 @@
|
|||||||
// parse out just the options we care about so we always get a consistent
|
// parse out just the options we care about
|
||||||
// obj with keys in a consistent order.
|
const looseOption = Object.freeze({ loose: true })
|
||||||
const opts = ['includePrerelease', 'loose', 'rtl']
|
const emptyOpts = Object.freeze({ })
|
||||||
const parseOptions = options =>
|
const parseOptions = options => {
|
||||||
!options ? {}
|
if (!options) {
|
||||||
: typeof options !== 'object' ? { loose: true }
|
return emptyOpts
|
||||||
: opts.filter(k => options[k]).reduce((o, k) => {
|
}
|
||||||
o[k] = true
|
|
||||||
return o
|
if (typeof options !== 'object') {
|
||||||
}, {})
|
return looseOption
|
||||||
|
}
|
||||||
|
|
||||||
|
return options
|
||||||
|
}
|
||||||
module.exports = parseOptions
|
module.exports = parseOptions
|
||||||
|
|||||||
@ -1,15 +0,0 @@
|
|||||||
The ISC License
|
|
||||||
|
|
||||||
Copyright (c) Isaac Z. Schlueter and Contributors
|
|
||||||
|
|
||||||
Permission to use, copy, modify, and/or distribute this software for any
|
|
||||||
purpose with or without fee is hereby granted, provided that the above
|
|
||||||
copyright notice and this permission notice appear in all copies.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
||||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
||||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
||||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
||||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
|
|
||||||
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
@ -1,204 +0,0 @@
|
|||||||
# yallist
|
|
||||||
|
|
||||||
Yet Another Linked List
|
|
||||||
|
|
||||||
There are many doubly-linked list implementations like it, but this
|
|
||||||
one is mine.
|
|
||||||
|
|
||||||
For when an array would be too big, and a Map can't be iterated in
|
|
||||||
reverse order.
|
|
||||||
|
|
||||||
|
|
||||||
[](https://travis-ci.org/isaacs/yallist) [](https://coveralls.io/github/isaacs/yallist)
|
|
||||||
|
|
||||||
## basic usage
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
var yallist = require('yallist')
|
|
||||||
var myList = yallist.create([1, 2, 3])
|
|
||||||
myList.push('foo')
|
|
||||||
myList.unshift('bar')
|
|
||||||
// of course pop() and shift() are there, too
|
|
||||||
console.log(myList.toArray()) // ['bar', 1, 2, 3, 'foo']
|
|
||||||
myList.forEach(function (k) {
|
|
||||||
// walk the list head to tail
|
|
||||||
})
|
|
||||||
myList.forEachReverse(function (k, index, list) {
|
|
||||||
// walk the list tail to head
|
|
||||||
})
|
|
||||||
var myDoubledList = myList.map(function (k) {
|
|
||||||
return k + k
|
|
||||||
})
|
|
||||||
// now myDoubledList contains ['barbar', 2, 4, 6, 'foofoo']
|
|
||||||
// mapReverse is also a thing
|
|
||||||
var myDoubledListReverse = myList.mapReverse(function (k) {
|
|
||||||
return k + k
|
|
||||||
}) // ['foofoo', 6, 4, 2, 'barbar']
|
|
||||||
|
|
||||||
var reduced = myList.reduce(function (set, entry) {
|
|
||||||
set += entry
|
|
||||||
return set
|
|
||||||
}, 'start')
|
|
||||||
console.log(reduced) // 'startfoo123bar'
|
|
||||||
```
|
|
||||||
|
|
||||||
## api
|
|
||||||
|
|
||||||
The whole API is considered "public".
|
|
||||||
|
|
||||||
Functions with the same name as an Array method work more or less the
|
|
||||||
same way.
|
|
||||||
|
|
||||||
There's reverse versions of most things because that's the point.
|
|
||||||
|
|
||||||
### Yallist
|
|
||||||
|
|
||||||
Default export, the class that holds and manages a list.
|
|
||||||
|
|
||||||
Call it with either a forEach-able (like an array) or a set of
|
|
||||||
arguments, to initialize the list.
|
|
||||||
|
|
||||||
The Array-ish methods all act like you'd expect. No magic length,
|
|
||||||
though, so if you change that it won't automatically prune or add
|
|
||||||
empty spots.
|
|
||||||
|
|
||||||
### Yallist.create(..)
|
|
||||||
|
|
||||||
Alias for Yallist function. Some people like factories.
|
|
||||||
|
|
||||||
#### yallist.head
|
|
||||||
|
|
||||||
The first node in the list
|
|
||||||
|
|
||||||
#### yallist.tail
|
|
||||||
|
|
||||||
The last node in the list
|
|
||||||
|
|
||||||
#### yallist.length
|
|
||||||
|
|
||||||
The number of nodes in the list. (Change this at your peril. It is
|
|
||||||
not magic like Array length.)
|
|
||||||
|
|
||||||
#### yallist.toArray()
|
|
||||||
|
|
||||||
Convert the list to an array.
|
|
||||||
|
|
||||||
#### yallist.forEach(fn, [thisp])
|
|
||||||
|
|
||||||
Call a function on each item in the list.
|
|
||||||
|
|
||||||
#### yallist.forEachReverse(fn, [thisp])
|
|
||||||
|
|
||||||
Call a function on each item in the list, in reverse order.
|
|
||||||
|
|
||||||
#### yallist.get(n)
|
|
||||||
|
|
||||||
Get the data at position `n` in the list. If you use this a lot,
|
|
||||||
probably better off just using an Array.
|
|
||||||
|
|
||||||
#### yallist.getReverse(n)
|
|
||||||
|
|
||||||
Get the data at position `n`, counting from the tail.
|
|
||||||
|
|
||||||
#### yallist.map(fn, thisp)
|
|
||||||
|
|
||||||
Create a new Yallist with the result of calling the function on each
|
|
||||||
item.
|
|
||||||
|
|
||||||
#### yallist.mapReverse(fn, thisp)
|
|
||||||
|
|
||||||
Same as `map`, but in reverse.
|
|
||||||
|
|
||||||
#### yallist.pop()
|
|
||||||
|
|
||||||
Get the data from the list tail, and remove the tail from the list.
|
|
||||||
|
|
||||||
#### yallist.push(item, ...)
|
|
||||||
|
|
||||||
Insert one or more items to the tail of the list.
|
|
||||||
|
|
||||||
#### yallist.reduce(fn, initialValue)
|
|
||||||
|
|
||||||
Like Array.reduce.
|
|
||||||
|
|
||||||
#### yallist.reduceReverse
|
|
||||||
|
|
||||||
Like Array.reduce, but in reverse.
|
|
||||||
|
|
||||||
#### yallist.reverse
|
|
||||||
|
|
||||||
Reverse the list in place.
|
|
||||||
|
|
||||||
#### yallist.shift()
|
|
||||||
|
|
||||||
Get the data from the list head, and remove the head from the list.
|
|
||||||
|
|
||||||
#### yallist.slice([from], [to])
|
|
||||||
|
|
||||||
Just like Array.slice, but returns a new Yallist.
|
|
||||||
|
|
||||||
#### yallist.sliceReverse([from], [to])
|
|
||||||
|
|
||||||
Just like yallist.slice, but the result is returned in reverse.
|
|
||||||
|
|
||||||
#### yallist.toArray()
|
|
||||||
|
|
||||||
Create an array representation of the list.
|
|
||||||
|
|
||||||
#### yallist.toArrayReverse()
|
|
||||||
|
|
||||||
Create a reversed array representation of the list.
|
|
||||||
|
|
||||||
#### yallist.unshift(item, ...)
|
|
||||||
|
|
||||||
Insert one or more items to the head of the list.
|
|
||||||
|
|
||||||
#### yallist.unshiftNode(node)
|
|
||||||
|
|
||||||
Move a Node object to the front of the list. (That is, pull it out of
|
|
||||||
wherever it lives, and make it the new head.)
|
|
||||||
|
|
||||||
If the node belongs to a different list, then that list will remove it
|
|
||||||
first.
|
|
||||||
|
|
||||||
#### yallist.pushNode(node)
|
|
||||||
|
|
||||||
Move a Node object to the end of the list. (That is, pull it out of
|
|
||||||
wherever it lives, and make it the new tail.)
|
|
||||||
|
|
||||||
If the node belongs to a list already, then that list will remove it
|
|
||||||
first.
|
|
||||||
|
|
||||||
#### yallist.removeNode(node)
|
|
||||||
|
|
||||||
Remove a node from the list, preserving referential integrity of head
|
|
||||||
and tail and other nodes.
|
|
||||||
|
|
||||||
Will throw an error if you try to have a list remove a node that
|
|
||||||
doesn't belong to it.
|
|
||||||
|
|
||||||
### Yallist.Node
|
|
||||||
|
|
||||||
The class that holds the data and is actually the list.
|
|
||||||
|
|
||||||
Call with `var n = new Node(value, previousNode, nextNode)`
|
|
||||||
|
|
||||||
Note that if you do direct operations on Nodes themselves, it's very
|
|
||||||
easy to get into weird states where the list is broken. Be careful :)
|
|
||||||
|
|
||||||
#### node.next
|
|
||||||
|
|
||||||
The next node in the list.
|
|
||||||
|
|
||||||
#### node.prev
|
|
||||||
|
|
||||||
The previous node in the list.
|
|
||||||
|
|
||||||
#### node.value
|
|
||||||
|
|
||||||
The data the node contains.
|
|
||||||
|
|
||||||
#### node.list
|
|
||||||
|
|
||||||
The list to which this node belongs. (Null if it does not belong to
|
|
||||||
any list.)
|
|
||||||
@ -1,8 +0,0 @@
|
|||||||
'use strict'
|
|
||||||
module.exports = function (Yallist) {
|
|
||||||
Yallist.prototype[Symbol.iterator] = function* () {
|
|
||||||
for (let walker = this.head; walker; walker = walker.next) {
|
|
||||||
yield walker.value
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,29 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "yallist",
|
|
||||||
"version": "4.0.0",
|
|
||||||
"description": "Yet Another Linked List",
|
|
||||||
"main": "yallist.js",
|
|
||||||
"directories": {
|
|
||||||
"test": "test"
|
|
||||||
},
|
|
||||||
"files": [
|
|
||||||
"yallist.js",
|
|
||||||
"iterator.js"
|
|
||||||
],
|
|
||||||
"dependencies": {},
|
|
||||||
"devDependencies": {
|
|
||||||
"tap": "^12.1.0"
|
|
||||||
},
|
|
||||||
"scripts": {
|
|
||||||
"test": "tap test/*.js --100",
|
|
||||||
"preversion": "npm test",
|
|
||||||
"postversion": "npm publish",
|
|
||||||
"postpublish": "git push origin --all; git push origin --tags"
|
|
||||||
},
|
|
||||||
"repository": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "git+https://github.com/isaacs/yallist.git"
|
|
||||||
},
|
|
||||||
"author": "Isaac Z. Schlueter <i@izs.me> (http://blog.izs.me/)",
|
|
||||||
"license": "ISC"
|
|
||||||
}
|
|
||||||
@ -1,426 +0,0 @@
|
|||||||
'use strict'
|
|
||||||
module.exports = Yallist
|
|
||||||
|
|
||||||
Yallist.Node = Node
|
|
||||||
Yallist.create = Yallist
|
|
||||||
|
|
||||||
function Yallist (list) {
|
|
||||||
var self = this
|
|
||||||
if (!(self instanceof Yallist)) {
|
|
||||||
self = new Yallist()
|
|
||||||
}
|
|
||||||
|
|
||||||
self.tail = null
|
|
||||||
self.head = null
|
|
||||||
self.length = 0
|
|
||||||
|
|
||||||
if (list && typeof list.forEach === 'function') {
|
|
||||||
list.forEach(function (item) {
|
|
||||||
self.push(item)
|
|
||||||
})
|
|
||||||
} else if (arguments.length > 0) {
|
|
||||||
for (var i = 0, l = arguments.length; i < l; i++) {
|
|
||||||
self.push(arguments[i])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return self
|
|
||||||
}
|
|
||||||
|
|
||||||
Yallist.prototype.removeNode = function (node) {
|
|
||||||
if (node.list !== this) {
|
|
||||||
throw new Error('removing node which does not belong to this list')
|
|
||||||
}
|
|
||||||
|
|
||||||
var next = node.next
|
|
||||||
var prev = node.prev
|
|
||||||
|
|
||||||
if (next) {
|
|
||||||
next.prev = prev
|
|
||||||
}
|
|
||||||
|
|
||||||
if (prev) {
|
|
||||||
prev.next = next
|
|
||||||
}
|
|
||||||
|
|
||||||
if (node === this.head) {
|
|
||||||
this.head = next
|
|
||||||
}
|
|
||||||
if (node === this.tail) {
|
|
||||||
this.tail = prev
|
|
||||||
}
|
|
||||||
|
|
||||||
node.list.length--
|
|
||||||
node.next = null
|
|
||||||
node.prev = null
|
|
||||||
node.list = null
|
|
||||||
|
|
||||||
return next
|
|
||||||
}
|
|
||||||
|
|
||||||
Yallist.prototype.unshiftNode = function (node) {
|
|
||||||
if (node === this.head) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if (node.list) {
|
|
||||||
node.list.removeNode(node)
|
|
||||||
}
|
|
||||||
|
|
||||||
var head = this.head
|
|
||||||
node.list = this
|
|
||||||
node.next = head
|
|
||||||
if (head) {
|
|
||||||
head.prev = node
|
|
||||||
}
|
|
||||||
|
|
||||||
this.head = node
|
|
||||||
if (!this.tail) {
|
|
||||||
this.tail = node
|
|
||||||
}
|
|
||||||
this.length++
|
|
||||||
}
|
|
||||||
|
|
||||||
Yallist.prototype.pushNode = function (node) {
|
|
||||||
if (node === this.tail) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if (node.list) {
|
|
||||||
node.list.removeNode(node)
|
|
||||||
}
|
|
||||||
|
|
||||||
var tail = this.tail
|
|
||||||
node.list = this
|
|
||||||
node.prev = tail
|
|
||||||
if (tail) {
|
|
||||||
tail.next = node
|
|
||||||
}
|
|
||||||
|
|
||||||
this.tail = node
|
|
||||||
if (!this.head) {
|
|
||||||
this.head = node
|
|
||||||
}
|
|
||||||
this.length++
|
|
||||||
}
|
|
||||||
|
|
||||||
Yallist.prototype.push = function () {
|
|
||||||
for (var i = 0, l = arguments.length; i < l; i++) {
|
|
||||||
push(this, arguments[i])
|
|
||||||
}
|
|
||||||
return this.length
|
|
||||||
}
|
|
||||||
|
|
||||||
Yallist.prototype.unshift = function () {
|
|
||||||
for (var i = 0, l = arguments.length; i < l; i++) {
|
|
||||||
unshift(this, arguments[i])
|
|
||||||
}
|
|
||||||
return this.length
|
|
||||||
}
|
|
||||||
|
|
||||||
Yallist.prototype.pop = function () {
|
|
||||||
if (!this.tail) {
|
|
||||||
return undefined
|
|
||||||
}
|
|
||||||
|
|
||||||
var res = this.tail.value
|
|
||||||
this.tail = this.tail.prev
|
|
||||||
if (this.tail) {
|
|
||||||
this.tail.next = null
|
|
||||||
} else {
|
|
||||||
this.head = null
|
|
||||||
}
|
|
||||||
this.length--
|
|
||||||
return res
|
|
||||||
}
|
|
||||||
|
|
||||||
Yallist.prototype.shift = function () {
|
|
||||||
if (!this.head) {
|
|
||||||
return undefined
|
|
||||||
}
|
|
||||||
|
|
||||||
var res = this.head.value
|
|
||||||
this.head = this.head.next
|
|
||||||
if (this.head) {
|
|
||||||
this.head.prev = null
|
|
||||||
} else {
|
|
||||||
this.tail = null
|
|
||||||
}
|
|
||||||
this.length--
|
|
||||||
return res
|
|
||||||
}
|
|
||||||
|
|
||||||
Yallist.prototype.forEach = function (fn, thisp) {
|
|
||||||
thisp = thisp || this
|
|
||||||
for (var walker = this.head, i = 0; walker !== null; i++) {
|
|
||||||
fn.call(thisp, walker.value, i, this)
|
|
||||||
walker = walker.next
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Yallist.prototype.forEachReverse = function (fn, thisp) {
|
|
||||||
thisp = thisp || this
|
|
||||||
for (var walker = this.tail, i = this.length - 1; walker !== null; i--) {
|
|
||||||
fn.call(thisp, walker.value, i, this)
|
|
||||||
walker = walker.prev
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Yallist.prototype.get = function (n) {
|
|
||||||
for (var i = 0, walker = this.head; walker !== null && i < n; i++) {
|
|
||||||
// abort out of the list early if we hit a cycle
|
|
||||||
walker = walker.next
|
|
||||||
}
|
|
||||||
if (i === n && walker !== null) {
|
|
||||||
return walker.value
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Yallist.prototype.getReverse = function (n) {
|
|
||||||
for (var i = 0, walker = this.tail; walker !== null && i < n; i++) {
|
|
||||||
// abort out of the list early if we hit a cycle
|
|
||||||
walker = walker.prev
|
|
||||||
}
|
|
||||||
if (i === n && walker !== null) {
|
|
||||||
return walker.value
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Yallist.prototype.map = function (fn, thisp) {
|
|
||||||
thisp = thisp || this
|
|
||||||
var res = new Yallist()
|
|
||||||
for (var walker = this.head; walker !== null;) {
|
|
||||||
res.push(fn.call(thisp, walker.value, this))
|
|
||||||
walker = walker.next
|
|
||||||
}
|
|
||||||
return res
|
|
||||||
}
|
|
||||||
|
|
||||||
Yallist.prototype.mapReverse = function (fn, thisp) {
|
|
||||||
thisp = thisp || this
|
|
||||||
var res = new Yallist()
|
|
||||||
for (var walker = this.tail; walker !== null;) {
|
|
||||||
res.push(fn.call(thisp, walker.value, this))
|
|
||||||
walker = walker.prev
|
|
||||||
}
|
|
||||||
return res
|
|
||||||
}
|
|
||||||
|
|
||||||
Yallist.prototype.reduce = function (fn, initial) {
|
|
||||||
var acc
|
|
||||||
var walker = this.head
|
|
||||||
if (arguments.length > 1) {
|
|
||||||
acc = initial
|
|
||||||
} else if (this.head) {
|
|
||||||
walker = this.head.next
|
|
||||||
acc = this.head.value
|
|
||||||
} else {
|
|
||||||
throw new TypeError('Reduce of empty list with no initial value')
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var i = 0; walker !== null; i++) {
|
|
||||||
acc = fn(acc, walker.value, i)
|
|
||||||
walker = walker.next
|
|
||||||
}
|
|
||||||
|
|
||||||
return acc
|
|
||||||
}
|
|
||||||
|
|
||||||
Yallist.prototype.reduceReverse = function (fn, initial) {
|
|
||||||
var acc
|
|
||||||
var walker = this.tail
|
|
||||||
if (arguments.length > 1) {
|
|
||||||
acc = initial
|
|
||||||
} else if (this.tail) {
|
|
||||||
walker = this.tail.prev
|
|
||||||
acc = this.tail.value
|
|
||||||
} else {
|
|
||||||
throw new TypeError('Reduce of empty list with no initial value')
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var i = this.length - 1; walker !== null; i--) {
|
|
||||||
acc = fn(acc, walker.value, i)
|
|
||||||
walker = walker.prev
|
|
||||||
}
|
|
||||||
|
|
||||||
return acc
|
|
||||||
}
|
|
||||||
|
|
||||||
Yallist.prototype.toArray = function () {
|
|
||||||
var arr = new Array(this.length)
|
|
||||||
for (var i = 0, walker = this.head; walker !== null; i++) {
|
|
||||||
arr[i] = walker.value
|
|
||||||
walker = walker.next
|
|
||||||
}
|
|
||||||
return arr
|
|
||||||
}
|
|
||||||
|
|
||||||
Yallist.prototype.toArrayReverse = function () {
|
|
||||||
var arr = new Array(this.length)
|
|
||||||
for (var i = 0, walker = this.tail; walker !== null; i++) {
|
|
||||||
arr[i] = walker.value
|
|
||||||
walker = walker.prev
|
|
||||||
}
|
|
||||||
return arr
|
|
||||||
}
|
|
||||||
|
|
||||||
Yallist.prototype.slice = function (from, to) {
|
|
||||||
to = to || this.length
|
|
||||||
if (to < 0) {
|
|
||||||
to += this.length
|
|
||||||
}
|
|
||||||
from = from || 0
|
|
||||||
if (from < 0) {
|
|
||||||
from += this.length
|
|
||||||
}
|
|
||||||
var ret = new Yallist()
|
|
||||||
if (to < from || to < 0) {
|
|
||||||
return ret
|
|
||||||
}
|
|
||||||
if (from < 0) {
|
|
||||||
from = 0
|
|
||||||
}
|
|
||||||
if (to > this.length) {
|
|
||||||
to = this.length
|
|
||||||
}
|
|
||||||
for (var i = 0, walker = this.head; walker !== null && i < from; i++) {
|
|
||||||
walker = walker.next
|
|
||||||
}
|
|
||||||
for (; walker !== null && i < to; i++, walker = walker.next) {
|
|
||||||
ret.push(walker.value)
|
|
||||||
}
|
|
||||||
return ret
|
|
||||||
}
|
|
||||||
|
|
||||||
Yallist.prototype.sliceReverse = function (from, to) {
|
|
||||||
to = to || this.length
|
|
||||||
if (to < 0) {
|
|
||||||
to += this.length
|
|
||||||
}
|
|
||||||
from = from || 0
|
|
||||||
if (from < 0) {
|
|
||||||
from += this.length
|
|
||||||
}
|
|
||||||
var ret = new Yallist()
|
|
||||||
if (to < from || to < 0) {
|
|
||||||
return ret
|
|
||||||
}
|
|
||||||
if (from < 0) {
|
|
||||||
from = 0
|
|
||||||
}
|
|
||||||
if (to > this.length) {
|
|
||||||
to = this.length
|
|
||||||
}
|
|
||||||
for (var i = this.length, walker = this.tail; walker !== null && i > to; i--) {
|
|
||||||
walker = walker.prev
|
|
||||||
}
|
|
||||||
for (; walker !== null && i > from; i--, walker = walker.prev) {
|
|
||||||
ret.push(walker.value)
|
|
||||||
}
|
|
||||||
return ret
|
|
||||||
}
|
|
||||||
|
|
||||||
Yallist.prototype.splice = function (start, deleteCount, ...nodes) {
|
|
||||||
if (start > this.length) {
|
|
||||||
start = this.length - 1
|
|
||||||
}
|
|
||||||
if (start < 0) {
|
|
||||||
start = this.length + start;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var i = 0, walker = this.head; walker !== null && i < start; i++) {
|
|
||||||
walker = walker.next
|
|
||||||
}
|
|
||||||
|
|
||||||
var ret = []
|
|
||||||
for (var i = 0; walker && i < deleteCount; i++) {
|
|
||||||
ret.push(walker.value)
|
|
||||||
walker = this.removeNode(walker)
|
|
||||||
}
|
|
||||||
if (walker === null) {
|
|
||||||
walker = this.tail
|
|
||||||
}
|
|
||||||
|
|
||||||
if (walker !== this.head && walker !== this.tail) {
|
|
||||||
walker = walker.prev
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var i = 0; i < nodes.length; i++) {
|
|
||||||
walker = insert(this, walker, nodes[i])
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
Yallist.prototype.reverse = function () {
|
|
||||||
var head = this.head
|
|
||||||
var tail = this.tail
|
|
||||||
for (var walker = head; walker !== null; walker = walker.prev) {
|
|
||||||
var p = walker.prev
|
|
||||||
walker.prev = walker.next
|
|
||||||
walker.next = p
|
|
||||||
}
|
|
||||||
this.head = tail
|
|
||||||
this.tail = head
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
function insert (self, node, value) {
|
|
||||||
var inserted = node === self.head ?
|
|
||||||
new Node(value, null, node, self) :
|
|
||||||
new Node(value, node, node.next, self)
|
|
||||||
|
|
||||||
if (inserted.next === null) {
|
|
||||||
self.tail = inserted
|
|
||||||
}
|
|
||||||
if (inserted.prev === null) {
|
|
||||||
self.head = inserted
|
|
||||||
}
|
|
||||||
|
|
||||||
self.length++
|
|
||||||
|
|
||||||
return inserted
|
|
||||||
}
|
|
||||||
|
|
||||||
function push (self, item) {
|
|
||||||
self.tail = new Node(item, self.tail, null, self)
|
|
||||||
if (!self.head) {
|
|
||||||
self.head = self.tail
|
|
||||||
}
|
|
||||||
self.length++
|
|
||||||
}
|
|
||||||
|
|
||||||
function unshift (self, item) {
|
|
||||||
self.head = new Node(item, null, self.head, self)
|
|
||||||
if (!self.tail) {
|
|
||||||
self.tail = self.head
|
|
||||||
}
|
|
||||||
self.length++
|
|
||||||
}
|
|
||||||
|
|
||||||
function Node (value, prev, next, list) {
|
|
||||||
if (!(this instanceof Node)) {
|
|
||||||
return new Node(value, prev, next, list)
|
|
||||||
}
|
|
||||||
|
|
||||||
this.list = list
|
|
||||||
this.value = value
|
|
||||||
|
|
||||||
if (prev) {
|
|
||||||
prev.next = this
|
|
||||||
this.prev = prev
|
|
||||||
} else {
|
|
||||||
this.prev = null
|
|
||||||
}
|
|
||||||
|
|
||||||
if (next) {
|
|
||||||
next.prev = this
|
|
||||||
this.next = next
|
|
||||||
} else {
|
|
||||||
this.next = null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
// add if support for Symbol.iterator is present
|
|
||||||
require('./iterator.js')(Yallist)
|
|
||||||
} catch (er) {}
|
|
||||||
Binary file not shown.
@ -1,21 +1,28 @@
|
|||||||
var bcrypt = require('../bcrypt');
|
var bcrypt = require('../bcrypt');
|
||||||
|
|
||||||
var start = Date.now();
|
(async () => {
|
||||||
bcrypt.genSalt(10, function(err, salt) {
|
const start = Date.now();
|
||||||
|
|
||||||
|
// genSalt
|
||||||
|
const salt = await bcrypt.genSalt(10)
|
||||||
console.log('salt: ' + salt);
|
console.log('salt: ' + salt);
|
||||||
console.log('salt cb end: ' + (Date.now() - start) + 'ms');
|
console.log('salt cb end: ' + (Date.now() - start) + 'ms');
|
||||||
bcrypt.hash('test', salt, function(err, crypted) {
|
|
||||||
|
// hash
|
||||||
|
const crypted = await bcrypt.hash('test', salt)
|
||||||
console.log('crypted: ' + crypted);
|
console.log('crypted: ' + crypted);
|
||||||
console.log('crypted cb end: ' + (Date.now() - start) + 'ms');
|
console.log('crypted cb end: ' + (Date.now() - start) + 'ms');
|
||||||
console.log('rounds used from hash:', bcrypt.getRounds(crypted));
|
console.log('rounds used from hash:', bcrypt.getRounds(crypted));
|
||||||
bcrypt.compare('test', crypted, function(err, res) {
|
|
||||||
|
// compare
|
||||||
|
const res = await bcrypt.compare('test', crypted)
|
||||||
console.log('compared true: ' + res);
|
console.log('compared true: ' + res);
|
||||||
console.log('compared true cb end: ' + (Date.now() - start) + 'ms');
|
console.log('compared true cb end: ' + (Date.now() - start) + 'ms');
|
||||||
});
|
|
||||||
bcrypt.compare('bacon', crypted, function(err, res) {
|
// compare
|
||||||
|
const res = await bcrypt.compare('bacon', crypted)
|
||||||
console.log('compared false: ' + res);
|
console.log('compared false: ' + res);
|
||||||
console.log('compared false cb end: ' + (Date.now() - start) + 'ms');
|
console.log('compared false cb end: ' + (Date.now() - start) + 'ms');
|
||||||
});
|
|
||||||
});
|
|
||||||
})
|
|
||||||
console.log('end: ' + (Date.now() - start) + 'ms');
|
console.log('end: ' + (Date.now() - start) + 'ms');
|
||||||
|
})();
|
||||||
|
|||||||
Binary file not shown.
@ -1,12 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
|
|
||||||
set -xe
|
|
||||||
|
|
||||||
echo "Running on $(node -v)"
|
|
||||||
|
|
||||||
apk add make g++ python
|
|
||||||
npm test --unsafe-perm
|
|
||||||
|
|
||||||
./node_modules/.bin/node-pre-gyp configure
|
|
||||||
./node_modules/.bin/node-pre-gyp build
|
|
||||||
./node_modules/.bin/node-pre-gyp package
|
|
||||||
@ -1,15 +0,0 @@
|
|||||||
The ISC License
|
|
||||||
|
|
||||||
Copyright (c) Isaac Z. Schlueter and Contributors
|
|
||||||
|
|
||||||
Permission to use, copy, modify, and/or distribute this software for any
|
|
||||||
purpose with or without fee is hereby granted, provided that the above
|
|
||||||
copyright notice and this permission notice appear in all copies.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
||||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
||||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
||||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
||||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
|
|
||||||
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
@ -1,204 +0,0 @@
|
|||||||
# yallist
|
|
||||||
|
|
||||||
Yet Another Linked List
|
|
||||||
|
|
||||||
There are many doubly-linked list implementations like it, but this
|
|
||||||
one is mine.
|
|
||||||
|
|
||||||
For when an array would be too big, and a Map can't be iterated in
|
|
||||||
reverse order.
|
|
||||||
|
|
||||||
|
|
||||||
[](https://travis-ci.org/isaacs/yallist) [](https://coveralls.io/github/isaacs/yallist)
|
|
||||||
|
|
||||||
## basic usage
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
var yallist = require('yallist')
|
|
||||||
var myList = yallist.create([1, 2, 3])
|
|
||||||
myList.push('foo')
|
|
||||||
myList.unshift('bar')
|
|
||||||
// of course pop() and shift() are there, too
|
|
||||||
console.log(myList.toArray()) // ['bar', 1, 2, 3, 'foo']
|
|
||||||
myList.forEach(function (k) {
|
|
||||||
// walk the list head to tail
|
|
||||||
})
|
|
||||||
myList.forEachReverse(function (k, index, list) {
|
|
||||||
// walk the list tail to head
|
|
||||||
})
|
|
||||||
var myDoubledList = myList.map(function (k) {
|
|
||||||
return k + k
|
|
||||||
})
|
|
||||||
// now myDoubledList contains ['barbar', 2, 4, 6, 'foofoo']
|
|
||||||
// mapReverse is also a thing
|
|
||||||
var myDoubledListReverse = myList.mapReverse(function (k) {
|
|
||||||
return k + k
|
|
||||||
}) // ['foofoo', 6, 4, 2, 'barbar']
|
|
||||||
|
|
||||||
var reduced = myList.reduce(function (set, entry) {
|
|
||||||
set += entry
|
|
||||||
return set
|
|
||||||
}, 'start')
|
|
||||||
console.log(reduced) // 'startfoo123bar'
|
|
||||||
```
|
|
||||||
|
|
||||||
## api
|
|
||||||
|
|
||||||
The whole API is considered "public".
|
|
||||||
|
|
||||||
Functions with the same name as an Array method work more or less the
|
|
||||||
same way.
|
|
||||||
|
|
||||||
There's reverse versions of most things because that's the point.
|
|
||||||
|
|
||||||
### Yallist
|
|
||||||
|
|
||||||
Default export, the class that holds and manages a list.
|
|
||||||
|
|
||||||
Call it with either a forEach-able (like an array) or a set of
|
|
||||||
arguments, to initialize the list.
|
|
||||||
|
|
||||||
The Array-ish methods all act like you'd expect. No magic length,
|
|
||||||
though, so if you change that it won't automatically prune or add
|
|
||||||
empty spots.
|
|
||||||
|
|
||||||
### Yallist.create(..)
|
|
||||||
|
|
||||||
Alias for Yallist function. Some people like factories.
|
|
||||||
|
|
||||||
#### yallist.head
|
|
||||||
|
|
||||||
The first node in the list
|
|
||||||
|
|
||||||
#### yallist.tail
|
|
||||||
|
|
||||||
The last node in the list
|
|
||||||
|
|
||||||
#### yallist.length
|
|
||||||
|
|
||||||
The number of nodes in the list. (Change this at your peril. It is
|
|
||||||
not magic like Array length.)
|
|
||||||
|
|
||||||
#### yallist.toArray()
|
|
||||||
|
|
||||||
Convert the list to an array.
|
|
||||||
|
|
||||||
#### yallist.forEach(fn, [thisp])
|
|
||||||
|
|
||||||
Call a function on each item in the list.
|
|
||||||
|
|
||||||
#### yallist.forEachReverse(fn, [thisp])
|
|
||||||
|
|
||||||
Call a function on each item in the list, in reverse order.
|
|
||||||
|
|
||||||
#### yallist.get(n)
|
|
||||||
|
|
||||||
Get the data at position `n` in the list. If you use this a lot,
|
|
||||||
probably better off just using an Array.
|
|
||||||
|
|
||||||
#### yallist.getReverse(n)
|
|
||||||
|
|
||||||
Get the data at position `n`, counting from the tail.
|
|
||||||
|
|
||||||
#### yallist.map(fn, thisp)
|
|
||||||
|
|
||||||
Create a new Yallist with the result of calling the function on each
|
|
||||||
item.
|
|
||||||
|
|
||||||
#### yallist.mapReverse(fn, thisp)
|
|
||||||
|
|
||||||
Same as `map`, but in reverse.
|
|
||||||
|
|
||||||
#### yallist.pop()
|
|
||||||
|
|
||||||
Get the data from the list tail, and remove the tail from the list.
|
|
||||||
|
|
||||||
#### yallist.push(item, ...)
|
|
||||||
|
|
||||||
Insert one or more items to the tail of the list.
|
|
||||||
|
|
||||||
#### yallist.reduce(fn, initialValue)
|
|
||||||
|
|
||||||
Like Array.reduce.
|
|
||||||
|
|
||||||
#### yallist.reduceReverse
|
|
||||||
|
|
||||||
Like Array.reduce, but in reverse.
|
|
||||||
|
|
||||||
#### yallist.reverse
|
|
||||||
|
|
||||||
Reverse the list in place.
|
|
||||||
|
|
||||||
#### yallist.shift()
|
|
||||||
|
|
||||||
Get the data from the list head, and remove the head from the list.
|
|
||||||
|
|
||||||
#### yallist.slice([from], [to])
|
|
||||||
|
|
||||||
Just like Array.slice, but returns a new Yallist.
|
|
||||||
|
|
||||||
#### yallist.sliceReverse([from], [to])
|
|
||||||
|
|
||||||
Just like yallist.slice, but the result is returned in reverse.
|
|
||||||
|
|
||||||
#### yallist.toArray()
|
|
||||||
|
|
||||||
Create an array representation of the list.
|
|
||||||
|
|
||||||
#### yallist.toArrayReverse()
|
|
||||||
|
|
||||||
Create a reversed array representation of the list.
|
|
||||||
|
|
||||||
#### yallist.unshift(item, ...)
|
|
||||||
|
|
||||||
Insert one or more items to the head of the list.
|
|
||||||
|
|
||||||
#### yallist.unshiftNode(node)
|
|
||||||
|
|
||||||
Move a Node object to the front of the list. (That is, pull it out of
|
|
||||||
wherever it lives, and make it the new head.)
|
|
||||||
|
|
||||||
If the node belongs to a different list, then that list will remove it
|
|
||||||
first.
|
|
||||||
|
|
||||||
#### yallist.pushNode(node)
|
|
||||||
|
|
||||||
Move a Node object to the end of the list. (That is, pull it out of
|
|
||||||
wherever it lives, and make it the new tail.)
|
|
||||||
|
|
||||||
If the node belongs to a list already, then that list will remove it
|
|
||||||
first.
|
|
||||||
|
|
||||||
#### yallist.removeNode(node)
|
|
||||||
|
|
||||||
Remove a node from the list, preserving referential integrity of head
|
|
||||||
and tail and other nodes.
|
|
||||||
|
|
||||||
Will throw an error if you try to have a list remove a node that
|
|
||||||
doesn't belong to it.
|
|
||||||
|
|
||||||
### Yallist.Node
|
|
||||||
|
|
||||||
The class that holds the data and is actually the list.
|
|
||||||
|
|
||||||
Call with `var n = new Node(value, previousNode, nextNode)`
|
|
||||||
|
|
||||||
Note that if you do direct operations on Nodes themselves, it's very
|
|
||||||
easy to get into weird states where the list is broken. Be careful :)
|
|
||||||
|
|
||||||
#### node.next
|
|
||||||
|
|
||||||
The next node in the list.
|
|
||||||
|
|
||||||
#### node.prev
|
|
||||||
|
|
||||||
The previous node in the list.
|
|
||||||
|
|
||||||
#### node.value
|
|
||||||
|
|
||||||
The data the node contains.
|
|
||||||
|
|
||||||
#### node.list
|
|
||||||
|
|
||||||
The list to which this node belongs. (Null if it does not belong to
|
|
||||||
any list.)
|
|
||||||
@ -1,8 +0,0 @@
|
|||||||
'use strict'
|
|
||||||
module.exports = function (Yallist) {
|
|
||||||
Yallist.prototype[Symbol.iterator] = function* () {
|
|
||||||
for (let walker = this.head; walker; walker = walker.next) {
|
|
||||||
yield walker.value
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,29 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "yallist",
|
|
||||||
"version": "4.0.0",
|
|
||||||
"description": "Yet Another Linked List",
|
|
||||||
"main": "yallist.js",
|
|
||||||
"directories": {
|
|
||||||
"test": "test"
|
|
||||||
},
|
|
||||||
"files": [
|
|
||||||
"yallist.js",
|
|
||||||
"iterator.js"
|
|
||||||
],
|
|
||||||
"dependencies": {},
|
|
||||||
"devDependencies": {
|
|
||||||
"tap": "^12.1.0"
|
|
||||||
},
|
|
||||||
"scripts": {
|
|
||||||
"test": "tap test/*.js --100",
|
|
||||||
"preversion": "npm test",
|
|
||||||
"postversion": "npm publish",
|
|
||||||
"postpublish": "git push origin --all; git push origin --tags"
|
|
||||||
},
|
|
||||||
"repository": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "git+https://github.com/isaacs/yallist.git"
|
|
||||||
},
|
|
||||||
"author": "Isaac Z. Schlueter <i@izs.me> (http://blog.izs.me/)",
|
|
||||||
"license": "ISC"
|
|
||||||
}
|
|
||||||
@ -1,426 +0,0 @@
|
|||||||
'use strict'
|
|
||||||
module.exports = Yallist
|
|
||||||
|
|
||||||
Yallist.Node = Node
|
|
||||||
Yallist.create = Yallist
|
|
||||||
|
|
||||||
function Yallist (list) {
|
|
||||||
var self = this
|
|
||||||
if (!(self instanceof Yallist)) {
|
|
||||||
self = new Yallist()
|
|
||||||
}
|
|
||||||
|
|
||||||
self.tail = null
|
|
||||||
self.head = null
|
|
||||||
self.length = 0
|
|
||||||
|
|
||||||
if (list && typeof list.forEach === 'function') {
|
|
||||||
list.forEach(function (item) {
|
|
||||||
self.push(item)
|
|
||||||
})
|
|
||||||
} else if (arguments.length > 0) {
|
|
||||||
for (var i = 0, l = arguments.length; i < l; i++) {
|
|
||||||
self.push(arguments[i])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return self
|
|
||||||
}
|
|
||||||
|
|
||||||
Yallist.prototype.removeNode = function (node) {
|
|
||||||
if (node.list !== this) {
|
|
||||||
throw new Error('removing node which does not belong to this list')
|
|
||||||
}
|
|
||||||
|
|
||||||
var next = node.next
|
|
||||||
var prev = node.prev
|
|
||||||
|
|
||||||
if (next) {
|
|
||||||
next.prev = prev
|
|
||||||
}
|
|
||||||
|
|
||||||
if (prev) {
|
|
||||||
prev.next = next
|
|
||||||
}
|
|
||||||
|
|
||||||
if (node === this.head) {
|
|
||||||
this.head = next
|
|
||||||
}
|
|
||||||
if (node === this.tail) {
|
|
||||||
this.tail = prev
|
|
||||||
}
|
|
||||||
|
|
||||||
node.list.length--
|
|
||||||
node.next = null
|
|
||||||
node.prev = null
|
|
||||||
node.list = null
|
|
||||||
|
|
||||||
return next
|
|
||||||
}
|
|
||||||
|
|
||||||
Yallist.prototype.unshiftNode = function (node) {
|
|
||||||
if (node === this.head) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if (node.list) {
|
|
||||||
node.list.removeNode(node)
|
|
||||||
}
|
|
||||||
|
|
||||||
var head = this.head
|
|
||||||
node.list = this
|
|
||||||
node.next = head
|
|
||||||
if (head) {
|
|
||||||
head.prev = node
|
|
||||||
}
|
|
||||||
|
|
||||||
this.head = node
|
|
||||||
if (!this.tail) {
|
|
||||||
this.tail = node
|
|
||||||
}
|
|
||||||
this.length++
|
|
||||||
}
|
|
||||||
|
|
||||||
Yallist.prototype.pushNode = function (node) {
|
|
||||||
if (node === this.tail) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if (node.list) {
|
|
||||||
node.list.removeNode(node)
|
|
||||||
}
|
|
||||||
|
|
||||||
var tail = this.tail
|
|
||||||
node.list = this
|
|
||||||
node.prev = tail
|
|
||||||
if (tail) {
|
|
||||||
tail.next = node
|
|
||||||
}
|
|
||||||
|
|
||||||
this.tail = node
|
|
||||||
if (!this.head) {
|
|
||||||
this.head = node
|
|
||||||
}
|
|
||||||
this.length++
|
|
||||||
}
|
|
||||||
|
|
||||||
Yallist.prototype.push = function () {
|
|
||||||
for (var i = 0, l = arguments.length; i < l; i++) {
|
|
||||||
push(this, arguments[i])
|
|
||||||
}
|
|
||||||
return this.length
|
|
||||||
}
|
|
||||||
|
|
||||||
Yallist.prototype.unshift = function () {
|
|
||||||
for (var i = 0, l = arguments.length; i < l; i++) {
|
|
||||||
unshift(this, arguments[i])
|
|
||||||
}
|
|
||||||
return this.length
|
|
||||||
}
|
|
||||||
|
|
||||||
Yallist.prototype.pop = function () {
|
|
||||||
if (!this.tail) {
|
|
||||||
return undefined
|
|
||||||
}
|
|
||||||
|
|
||||||
var res = this.tail.value
|
|
||||||
this.tail = this.tail.prev
|
|
||||||
if (this.tail) {
|
|
||||||
this.tail.next = null
|
|
||||||
} else {
|
|
||||||
this.head = null
|
|
||||||
}
|
|
||||||
this.length--
|
|
||||||
return res
|
|
||||||
}
|
|
||||||
|
|
||||||
Yallist.prototype.shift = function () {
|
|
||||||
if (!this.head) {
|
|
||||||
return undefined
|
|
||||||
}
|
|
||||||
|
|
||||||
var res = this.head.value
|
|
||||||
this.head = this.head.next
|
|
||||||
if (this.head) {
|
|
||||||
this.head.prev = null
|
|
||||||
} else {
|
|
||||||
this.tail = null
|
|
||||||
}
|
|
||||||
this.length--
|
|
||||||
return res
|
|
||||||
}
|
|
||||||
|
|
||||||
Yallist.prototype.forEach = function (fn, thisp) {
|
|
||||||
thisp = thisp || this
|
|
||||||
for (var walker = this.head, i = 0; walker !== null; i++) {
|
|
||||||
fn.call(thisp, walker.value, i, this)
|
|
||||||
walker = walker.next
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Yallist.prototype.forEachReverse = function (fn, thisp) {
|
|
||||||
thisp = thisp || this
|
|
||||||
for (var walker = this.tail, i = this.length - 1; walker !== null; i--) {
|
|
||||||
fn.call(thisp, walker.value, i, this)
|
|
||||||
walker = walker.prev
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Yallist.prototype.get = function (n) {
|
|
||||||
for (var i = 0, walker = this.head; walker !== null && i < n; i++) {
|
|
||||||
// abort out of the list early if we hit a cycle
|
|
||||||
walker = walker.next
|
|
||||||
}
|
|
||||||
if (i === n && walker !== null) {
|
|
||||||
return walker.value
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Yallist.prototype.getReverse = function (n) {
|
|
||||||
for (var i = 0, walker = this.tail; walker !== null && i < n; i++) {
|
|
||||||
// abort out of the list early if we hit a cycle
|
|
||||||
walker = walker.prev
|
|
||||||
}
|
|
||||||
if (i === n && walker !== null) {
|
|
||||||
return walker.value
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Yallist.prototype.map = function (fn, thisp) {
|
|
||||||
thisp = thisp || this
|
|
||||||
var res = new Yallist()
|
|
||||||
for (var walker = this.head; walker !== null;) {
|
|
||||||
res.push(fn.call(thisp, walker.value, this))
|
|
||||||
walker = walker.next
|
|
||||||
}
|
|
||||||
return res
|
|
||||||
}
|
|
||||||
|
|
||||||
Yallist.prototype.mapReverse = function (fn, thisp) {
|
|
||||||
thisp = thisp || this
|
|
||||||
var res = new Yallist()
|
|
||||||
for (var walker = this.tail; walker !== null;) {
|
|
||||||
res.push(fn.call(thisp, walker.value, this))
|
|
||||||
walker = walker.prev
|
|
||||||
}
|
|
||||||
return res
|
|
||||||
}
|
|
||||||
|
|
||||||
Yallist.prototype.reduce = function (fn, initial) {
|
|
||||||
var acc
|
|
||||||
var walker = this.head
|
|
||||||
if (arguments.length > 1) {
|
|
||||||
acc = initial
|
|
||||||
} else if (this.head) {
|
|
||||||
walker = this.head.next
|
|
||||||
acc = this.head.value
|
|
||||||
} else {
|
|
||||||
throw new TypeError('Reduce of empty list with no initial value')
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var i = 0; walker !== null; i++) {
|
|
||||||
acc = fn(acc, walker.value, i)
|
|
||||||
walker = walker.next
|
|
||||||
}
|
|
||||||
|
|
||||||
return acc
|
|
||||||
}
|
|
||||||
|
|
||||||
Yallist.prototype.reduceReverse = function (fn, initial) {
|
|
||||||
var acc
|
|
||||||
var walker = this.tail
|
|
||||||
if (arguments.length > 1) {
|
|
||||||
acc = initial
|
|
||||||
} else if (this.tail) {
|
|
||||||
walker = this.tail.prev
|
|
||||||
acc = this.tail.value
|
|
||||||
} else {
|
|
||||||
throw new TypeError('Reduce of empty list with no initial value')
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var i = this.length - 1; walker !== null; i--) {
|
|
||||||
acc = fn(acc, walker.value, i)
|
|
||||||
walker = walker.prev
|
|
||||||
}
|
|
||||||
|
|
||||||
return acc
|
|
||||||
}
|
|
||||||
|
|
||||||
Yallist.prototype.toArray = function () {
|
|
||||||
var arr = new Array(this.length)
|
|
||||||
for (var i = 0, walker = this.head; walker !== null; i++) {
|
|
||||||
arr[i] = walker.value
|
|
||||||
walker = walker.next
|
|
||||||
}
|
|
||||||
return arr
|
|
||||||
}
|
|
||||||
|
|
||||||
Yallist.prototype.toArrayReverse = function () {
|
|
||||||
var arr = new Array(this.length)
|
|
||||||
for (var i = 0, walker = this.tail; walker !== null; i++) {
|
|
||||||
arr[i] = walker.value
|
|
||||||
walker = walker.prev
|
|
||||||
}
|
|
||||||
return arr
|
|
||||||
}
|
|
||||||
|
|
||||||
Yallist.prototype.slice = function (from, to) {
|
|
||||||
to = to || this.length
|
|
||||||
if (to < 0) {
|
|
||||||
to += this.length
|
|
||||||
}
|
|
||||||
from = from || 0
|
|
||||||
if (from < 0) {
|
|
||||||
from += this.length
|
|
||||||
}
|
|
||||||
var ret = new Yallist()
|
|
||||||
if (to < from || to < 0) {
|
|
||||||
return ret
|
|
||||||
}
|
|
||||||
if (from < 0) {
|
|
||||||
from = 0
|
|
||||||
}
|
|
||||||
if (to > this.length) {
|
|
||||||
to = this.length
|
|
||||||
}
|
|
||||||
for (var i = 0, walker = this.head; walker !== null && i < from; i++) {
|
|
||||||
walker = walker.next
|
|
||||||
}
|
|
||||||
for (; walker !== null && i < to; i++, walker = walker.next) {
|
|
||||||
ret.push(walker.value)
|
|
||||||
}
|
|
||||||
return ret
|
|
||||||
}
|
|
||||||
|
|
||||||
Yallist.prototype.sliceReverse = function (from, to) {
|
|
||||||
to = to || this.length
|
|
||||||
if (to < 0) {
|
|
||||||
to += this.length
|
|
||||||
}
|
|
||||||
from = from || 0
|
|
||||||
if (from < 0) {
|
|
||||||
from += this.length
|
|
||||||
}
|
|
||||||
var ret = new Yallist()
|
|
||||||
if (to < from || to < 0) {
|
|
||||||
return ret
|
|
||||||
}
|
|
||||||
if (from < 0) {
|
|
||||||
from = 0
|
|
||||||
}
|
|
||||||
if (to > this.length) {
|
|
||||||
to = this.length
|
|
||||||
}
|
|
||||||
for (var i = this.length, walker = this.tail; walker !== null && i > to; i--) {
|
|
||||||
walker = walker.prev
|
|
||||||
}
|
|
||||||
for (; walker !== null && i > from; i--, walker = walker.prev) {
|
|
||||||
ret.push(walker.value)
|
|
||||||
}
|
|
||||||
return ret
|
|
||||||
}
|
|
||||||
|
|
||||||
Yallist.prototype.splice = function (start, deleteCount, ...nodes) {
|
|
||||||
if (start > this.length) {
|
|
||||||
start = this.length - 1
|
|
||||||
}
|
|
||||||
if (start < 0) {
|
|
||||||
start = this.length + start;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var i = 0, walker = this.head; walker !== null && i < start; i++) {
|
|
||||||
walker = walker.next
|
|
||||||
}
|
|
||||||
|
|
||||||
var ret = []
|
|
||||||
for (var i = 0; walker && i < deleteCount; i++) {
|
|
||||||
ret.push(walker.value)
|
|
||||||
walker = this.removeNode(walker)
|
|
||||||
}
|
|
||||||
if (walker === null) {
|
|
||||||
walker = this.tail
|
|
||||||
}
|
|
||||||
|
|
||||||
if (walker !== this.head && walker !== this.tail) {
|
|
||||||
walker = walker.prev
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var i = 0; i < nodes.length; i++) {
|
|
||||||
walker = insert(this, walker, nodes[i])
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
Yallist.prototype.reverse = function () {
|
|
||||||
var head = this.head
|
|
||||||
var tail = this.tail
|
|
||||||
for (var walker = head; walker !== null; walker = walker.prev) {
|
|
||||||
var p = walker.prev
|
|
||||||
walker.prev = walker.next
|
|
||||||
walker.next = p
|
|
||||||
}
|
|
||||||
this.head = tail
|
|
||||||
this.tail = head
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
function insert (self, node, value) {
|
|
||||||
var inserted = node === self.head ?
|
|
||||||
new Node(value, null, node, self) :
|
|
||||||
new Node(value, node, node.next, self)
|
|
||||||
|
|
||||||
if (inserted.next === null) {
|
|
||||||
self.tail = inserted
|
|
||||||
}
|
|
||||||
if (inserted.prev === null) {
|
|
||||||
self.head = inserted
|
|
||||||
}
|
|
||||||
|
|
||||||
self.length++
|
|
||||||
|
|
||||||
return inserted
|
|
||||||
}
|
|
||||||
|
|
||||||
function push (self, item) {
|
|
||||||
self.tail = new Node(item, self.tail, null, self)
|
|
||||||
if (!self.head) {
|
|
||||||
self.head = self.tail
|
|
||||||
}
|
|
||||||
self.length++
|
|
||||||
}
|
|
||||||
|
|
||||||
function unshift (self, item) {
|
|
||||||
self.head = new Node(item, null, self.head, self)
|
|
||||||
if (!self.tail) {
|
|
||||||
self.tail = self.head
|
|
||||||
}
|
|
||||||
self.length++
|
|
||||||
}
|
|
||||||
|
|
||||||
function Node (value, prev, next, list) {
|
|
||||||
if (!(this instanceof Node)) {
|
|
||||||
return new Node(value, prev, next, list)
|
|
||||||
}
|
|
||||||
|
|
||||||
this.list = list
|
|
||||||
this.value = value
|
|
||||||
|
|
||||||
if (prev) {
|
|
||||||
prev.next = this
|
|
||||||
this.prev = prev
|
|
||||||
} else {
|
|
||||||
this.prev = null
|
|
||||||
}
|
|
||||||
|
|
||||||
if (next) {
|
|
||||||
next.prev = this
|
|
||||||
this.next = next
|
|
||||||
} else {
|
|
||||||
this.next = null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
// add if support for Symbol.iterator is present
|
|
||||||
require('./iterator.js')(Yallist)
|
|
||||||
} catch (er) {}
|
|
||||||
@ -1,11 +1,11 @@
|
|||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
const include_dir = path.relative('.', __dirname);
|
const includeDir = path.relative('.', __dirname);
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
include: `"${__dirname}"`, // deprecated, can be removed as part of 4.0.0
|
include: `"${__dirname}"`, // deprecated, can be removed as part of 4.0.0
|
||||||
include_dir,
|
include_dir: includeDir,
|
||||||
gyp: path.join(include_dir, 'node_api.gyp:nothing'),
|
gyp: path.join(includeDir, 'node_api.gyp:nothing'),
|
||||||
isNodeApiBuiltin: true,
|
isNodeApiBuiltin: true,
|
||||||
needsFlag: false
|
needsFlag: false
|
||||||
};
|
};
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Loading…
Reference in new issue