Initial commit
This commit is contained in:
56
node_modules/hashmap/.jshintrc
generated
vendored
56
node_modules/hashmap/.jshintrc
generated
vendored
@@ -1,28 +1,28 @@
|
||||
{
|
||||
"shadow": "inner",
|
||||
"indent": 1,
|
||||
|
||||
"camelcase": false,
|
||||
"eqeqeq": true,
|
||||
"eqnull": true,
|
||||
"freeze": true,
|
||||
"funcscope": true,
|
||||
"newcap": true,
|
||||
"noarg": true,
|
||||
"noempty": true,
|
||||
"nonbsp": true,
|
||||
"unused": "vars",
|
||||
"undef": true,
|
||||
"scripturl": true,
|
||||
"loopfunc": true,
|
||||
"strict": "implied",
|
||||
"validthis": true,
|
||||
|
||||
"esnext": true,
|
||||
"globals": {},
|
||||
"browser": true,
|
||||
"devel": true,
|
||||
"mocha": true,
|
||||
"node": true,
|
||||
"jquery": true
|
||||
}
|
||||
{
|
||||
"shadow": "inner",
|
||||
"indent": 1,
|
||||
|
||||
"camelcase": false,
|
||||
"eqeqeq": true,
|
||||
"eqnull": true,
|
||||
"freeze": true,
|
||||
"funcscope": true,
|
||||
"newcap": true,
|
||||
"noarg": true,
|
||||
"noempty": true,
|
||||
"nonbsp": true,
|
||||
"unused": "vars",
|
||||
"undef": true,
|
||||
"scripturl": true,
|
||||
"loopfunc": true,
|
||||
"strict": "implied",
|
||||
"validthis": true,
|
||||
|
||||
"esnext": true,
|
||||
"globals": {},
|
||||
"browser": true,
|
||||
"devel": true,
|
||||
"mocha": true,
|
||||
"node": true,
|
||||
"jquery": true
|
||||
}
|
||||
|
||||
340
node_modules/hashmap/Readme.md
generated
vendored
340
node_modules/hashmap/Readme.md
generated
vendored
@@ -1,170 +1,170 @@
|
||||
# HashMap Class for JavaScript
|
||||
|
||||
## Installation
|
||||
|
||||
[](https://npmjs.org/package/hashmap)
|
||||
|
||||
Using [npm](https://npmjs.org/package/hashmap):
|
||||
|
||||
$ npm install hashmap
|
||||
|
||||
Using bower:
|
||||
|
||||
$ bower install hashmap
|
||||
|
||||
You can download the last stable version from the [releases page](https://github.com/flesler/hashmap/releases).
|
||||
|
||||
If you like risk, you can download the [latest master version](https://raw.github.com/flesler/hashmap/master/hashmap.js), it's usually stable.
|
||||
|
||||
To run the tests:
|
||||
|
||||
$ npm test
|
||||
|
||||
## Description
|
||||
|
||||
This project provides a `HashMap` class that works both on __Node.js__ and the __browser__.
|
||||
HashMap instances __store key/value pairs__ allowing __keys of any type__.
|
||||
|
||||
Unlike regular objects, __keys will not be stringified__. For example numbers and strings won't be mixed, you can pass `Date`'s, `RegExp`'s, DOM Elements, anything! (even `null` and `undefined`)
|
||||
|
||||
## HashMap constructor overloads
|
||||
- `new HashMap()` creates an empty hashmap
|
||||
- `new HashMap(map:HashMap)` creates a hashmap with the key-value pairs of `map`
|
||||
- `new HashMap(arr:Array)` creates a hashmap from the 2D key-value array `arr`, e.g. `[['key1','val1'], ['key2','val2']]`
|
||||
- `new HashMap(key:*, value:*, key2:*, value2:*, ...)` creates a hashmap with several key-value pairs
|
||||
|
||||
## HashMap methods
|
||||
|
||||
- `get(key:*) : *` returns the value stored for that key.
|
||||
- `set(key:*, value:*) : HashMap` stores a key-value pair
|
||||
- `multi(key:*, value:*, key2:*, value2:*, ...) : HashMap` stores several key-value pairs
|
||||
- `copy(other:HashMap) : HashMap` copies all key-value pairs from other to this instance
|
||||
- `has(key:*) : Boolean` returns whether a key is set on the hashmap
|
||||
- `search(value:*) : *` returns key under which given value is stored (`null` if not found)
|
||||
- `delete(key:*) : HashMap` deletes a key-value pair by key
|
||||
- `remove(key:*) : HashMap` Alias for `delete(key:*)` *(deprecated)*
|
||||
- `type(key:*) : String` returns the data type of the provided key (used internally)
|
||||
- `keys() : Array<*>` returns an array with all the registered keys
|
||||
- `values() : Array<*>` returns an array with all the values
|
||||
- `entries() : Array<[*,*]>` returns an array with [key,value] pairs
|
||||
- `size : Number` the amount of key-value pairs
|
||||
- `count() : Number` returns the amount of key-value pairs *(deprecated)*
|
||||
- `clear() : HashMap` deletes all the key-value pairs on the hashmap
|
||||
- `clone() : HashMap` creates a new hashmap with all the key-value pairs of the original
|
||||
- `hash(key:*) : String` returns the stringified version of a key (used internally)
|
||||
- `forEach(function(value, key)) : HashMap` iterates the pairs and calls the function for each one
|
||||
|
||||
### Method chaining
|
||||
|
||||
All methods that don't return something, will return the HashMap instance to enable chaining.
|
||||
|
||||
## Examples
|
||||
|
||||
Assume this for all examples below
|
||||
|
||||
```js
|
||||
var map = new HashMap();
|
||||
```
|
||||
|
||||
If you're using this within Node, you first need to import the class
|
||||
|
||||
```js
|
||||
var HashMap = require('hashmap');
|
||||
```
|
||||
|
||||
### Basic use case
|
||||
|
||||
```js
|
||||
map.set("some_key", "some value");
|
||||
map.get("some_key"); // --> "some value"
|
||||
```
|
||||
|
||||
### Map size / number of elements
|
||||
|
||||
```js
|
||||
var map = new HashMap();
|
||||
map.set("key1", "val1");
|
||||
map.set("key2", "val2");
|
||||
map.size; // -> 2
|
||||
```
|
||||
|
||||
### Deleting key-value pairs
|
||||
|
||||
```js
|
||||
map.set("some_key", "some value");
|
||||
map.delete("some_key");
|
||||
map.get("some_key"); // --> undefined
|
||||
```
|
||||
|
||||
### No stringification
|
||||
|
||||
```js
|
||||
map.set("1", "string one");
|
||||
map.set(1, "number one");
|
||||
map.get("1"); // --> "string one"
|
||||
```
|
||||
|
||||
A regular `Object` used as a map would yield `"number one"`
|
||||
|
||||
### Objects as keys
|
||||
|
||||
```js
|
||||
var key = {};
|
||||
var key2 = {};
|
||||
map.set(key, 123);
|
||||
map.set(key2, 321);
|
||||
map.get(key); // --> 123
|
||||
```
|
||||
A regular `Object` used as a map would yield `321`
|
||||
|
||||
### Iterating
|
||||
|
||||
```js
|
||||
map.set(1, "test 1");
|
||||
map.set(2, "test 2");
|
||||
map.set(3, "test 3");
|
||||
|
||||
map.forEach(function(value, key) {
|
||||
console.log(key + " : " + value);
|
||||
});
|
||||
```
|
||||
|
||||
### Method chaining
|
||||
|
||||
```js
|
||||
map
|
||||
.set(1, "test 1")
|
||||
.set(2, "test 2")
|
||||
.set(3, "test 3")
|
||||
.forEach(function(value, key) {
|
||||
console.log(key + " : " + value);
|
||||
});
|
||||
```
|
||||
|
||||
## LICENSE
|
||||
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2012 Ariel Flesler
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF
|
||||
|
||||
## To-Do
|
||||
|
||||
* (?) Allow extending the hashing function in a AOP way or by passing a service
|
||||
* Make tests work on the browser
|
||||
# HashMap Class for JavaScript
|
||||
|
||||
## Installation
|
||||
|
||||
[](https://npmjs.org/package/hashmap)
|
||||
|
||||
Using [npm](https://npmjs.org/package/hashmap):
|
||||
|
||||
$ npm install hashmap
|
||||
|
||||
Using bower:
|
||||
|
||||
$ bower install hashmap
|
||||
|
||||
You can download the last stable version from the [releases page](https://github.com/flesler/hashmap/releases).
|
||||
|
||||
If you like risk, you can download the [latest master version](https://raw.github.com/flesler/hashmap/master/hashmap.js), it's usually stable.
|
||||
|
||||
To run the tests:
|
||||
|
||||
$ npm test
|
||||
|
||||
## Description
|
||||
|
||||
This project provides a `HashMap` class that works both on __Node.js__ and the __browser__.
|
||||
HashMap instances __store key/value pairs__ allowing __keys of any type__.
|
||||
|
||||
Unlike regular objects, __keys will not be stringified__. For example numbers and strings won't be mixed, you can pass `Date`'s, `RegExp`'s, DOM Elements, anything! (even `null` and `undefined`)
|
||||
|
||||
## HashMap constructor overloads
|
||||
- `new HashMap()` creates an empty hashmap
|
||||
- `new HashMap(map:HashMap)` creates a hashmap with the key-value pairs of `map`
|
||||
- `new HashMap(arr:Array)` creates a hashmap from the 2D key-value array `arr`, e.g. `[['key1','val1'], ['key2','val2']]`
|
||||
- `new HashMap(key:*, value:*, key2:*, value2:*, ...)` creates a hashmap with several key-value pairs
|
||||
|
||||
## HashMap methods
|
||||
|
||||
- `get(key:*) : *` returns the value stored for that key.
|
||||
- `set(key:*, value:*) : HashMap` stores a key-value pair
|
||||
- `multi(key:*, value:*, key2:*, value2:*, ...) : HashMap` stores several key-value pairs
|
||||
- `copy(other:HashMap) : HashMap` copies all key-value pairs from other to this instance
|
||||
- `has(key:*) : Boolean` returns whether a key is set on the hashmap
|
||||
- `search(value:*) : *` returns key under which given value is stored (`null` if not found)
|
||||
- `delete(key:*) : HashMap` deletes a key-value pair by key
|
||||
- `remove(key:*) : HashMap` Alias for `delete(key:*)` *(deprecated)*
|
||||
- `type(key:*) : String` returns the data type of the provided key (used internally)
|
||||
- `keys() : Array<*>` returns an array with all the registered keys
|
||||
- `values() : Array<*>` returns an array with all the values
|
||||
- `entries() : Array<[*,*]>` returns an array with [key,value] pairs
|
||||
- `size : Number` the amount of key-value pairs
|
||||
- `count() : Number` returns the amount of key-value pairs *(deprecated)*
|
||||
- `clear() : HashMap` deletes all the key-value pairs on the hashmap
|
||||
- `clone() : HashMap` creates a new hashmap with all the key-value pairs of the original
|
||||
- `hash(key:*) : String` returns the stringified version of a key (used internally)
|
||||
- `forEach(function(value, key)) : HashMap` iterates the pairs and calls the function for each one
|
||||
|
||||
### Method chaining
|
||||
|
||||
All methods that don't return something, will return the HashMap instance to enable chaining.
|
||||
|
||||
## Examples
|
||||
|
||||
Assume this for all examples below
|
||||
|
||||
```js
|
||||
var map = new HashMap();
|
||||
```
|
||||
|
||||
If you're using this within Node, you first need to import the class
|
||||
|
||||
```js
|
||||
var HashMap = require('hashmap');
|
||||
```
|
||||
|
||||
### Basic use case
|
||||
|
||||
```js
|
||||
map.set("some_key", "some value");
|
||||
map.get("some_key"); // --> "some value"
|
||||
```
|
||||
|
||||
### Map size / number of elements
|
||||
|
||||
```js
|
||||
var map = new HashMap();
|
||||
map.set("key1", "val1");
|
||||
map.set("key2", "val2");
|
||||
map.size; // -> 2
|
||||
```
|
||||
|
||||
### Deleting key-value pairs
|
||||
|
||||
```js
|
||||
map.set("some_key", "some value");
|
||||
map.delete("some_key");
|
||||
map.get("some_key"); // --> undefined
|
||||
```
|
||||
|
||||
### No stringification
|
||||
|
||||
```js
|
||||
map.set("1", "string one");
|
||||
map.set(1, "number one");
|
||||
map.get("1"); // --> "string one"
|
||||
```
|
||||
|
||||
A regular `Object` used as a map would yield `"number one"`
|
||||
|
||||
### Objects as keys
|
||||
|
||||
```js
|
||||
var key = {};
|
||||
var key2 = {};
|
||||
map.set(key, 123);
|
||||
map.set(key2, 321);
|
||||
map.get(key); // --> 123
|
||||
```
|
||||
A regular `Object` used as a map would yield `321`
|
||||
|
||||
### Iterating
|
||||
|
||||
```js
|
||||
map.set(1, "test 1");
|
||||
map.set(2, "test 2");
|
||||
map.set(3, "test 3");
|
||||
|
||||
map.forEach(function(value, key) {
|
||||
console.log(key + " : " + value);
|
||||
});
|
||||
```
|
||||
|
||||
### Method chaining
|
||||
|
||||
```js
|
||||
map
|
||||
.set(1, "test 1")
|
||||
.set(2, "test 2")
|
||||
.set(3, "test 3")
|
||||
.forEach(function(value, key) {
|
||||
console.log(key + " : " + value);
|
||||
});
|
||||
```
|
||||
|
||||
## LICENSE
|
||||
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2012 Ariel Flesler
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF
|
||||
|
||||
## To-Do
|
||||
|
||||
* (?) Allow extending the hashing function in a AOP way or by passing a service
|
||||
* Make tests work on the browser
|
||||
|
||||
420
node_modules/hashmap/hashmap.js
generated
vendored
420
node_modules/hashmap/hashmap.js
generated
vendored
@@ -1,210 +1,210 @@
|
||||
/**
|
||||
* HashMap - HashMap Class for JavaScript
|
||||
* @author Ariel Flesler <aflesler@gmail.com>
|
||||
* @version 2.0.6
|
||||
* Homepage: https://github.com/flesler/hashmap
|
||||
*/
|
||||
|
||||
(function(factory) {
|
||||
/* global define */
|
||||
if (typeof define === 'function' && define.amd) {
|
||||
// AMD. Register as an anonymous module.
|
||||
define([], factory);
|
||||
} else if (typeof module === 'object') {
|
||||
// Node js environment
|
||||
var HashMap = module.exports = factory();
|
||||
// Keep it backwards compatible
|
||||
HashMap.HashMap = HashMap;
|
||||
} else {
|
||||
// Browser globals (this is window)
|
||||
this.HashMap = factory();
|
||||
}
|
||||
}(function() {
|
||||
|
||||
function HashMap(other) {
|
||||
this.clear();
|
||||
switch (arguments.length) {
|
||||
case 0: break;
|
||||
case 1: {
|
||||
if ('length' in other) {
|
||||
// Flatten 2D array to alternating key-value array
|
||||
multi(this, Array.prototype.concat.apply([], other));
|
||||
} else { // Assumed to be a HashMap instance
|
||||
this.copy(other);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: multi(this, arguments); break;
|
||||
}
|
||||
}
|
||||
|
||||
var proto = HashMap.prototype = {
|
||||
constructor:HashMap,
|
||||
|
||||
get:function(key) {
|
||||
var data = this._data[this.hash(key)];
|
||||
return data && data[1];
|
||||
},
|
||||
|
||||
set:function(key, value) {
|
||||
// Store original key as well (for iteration)
|
||||
var hash = this.hash(key);
|
||||
if ( !(hash in this._data) ) {
|
||||
this.size++;
|
||||
}
|
||||
this._data[hash] = [key, value];
|
||||
},
|
||||
|
||||
multi:function() {
|
||||
multi(this, arguments);
|
||||
},
|
||||
|
||||
copy:function(other) {
|
||||
for (var hash in other._data) {
|
||||
if ( !(hash in this._data) ) {
|
||||
this.size++;
|
||||
}
|
||||
this._data[hash] = other._data[hash];
|
||||
}
|
||||
},
|
||||
|
||||
has:function(key) {
|
||||
return this.hash(key) in this._data;
|
||||
},
|
||||
|
||||
search:function(value) {
|
||||
for (var key in this._data) {
|
||||
if (this._data[key][1] === value) {
|
||||
return this._data[key][0];
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
},
|
||||
|
||||
delete:function(key) {
|
||||
var hash = this.hash(key);
|
||||
if ( hash in this._data ) {
|
||||
this.size--;
|
||||
delete this._data[hash];
|
||||
}
|
||||
},
|
||||
|
||||
type:function(key) {
|
||||
var str = Object.prototype.toString.call(key);
|
||||
var type = str.slice(8, -1).toLowerCase();
|
||||
// Some browsers yield DOMWindow or Window for null and undefined, works fine on Node
|
||||
if (!key && (type === 'domwindow' || type === 'window')) {
|
||||
return key + '';
|
||||
}
|
||||
return type;
|
||||
},
|
||||
|
||||
keys:function() {
|
||||
var keys = [];
|
||||
this.forEach(function(_, key) { keys.push(key); });
|
||||
return keys;
|
||||
},
|
||||
|
||||
values:function() {
|
||||
var values = [];
|
||||
this.forEach(function(value) { values.push(value); });
|
||||
return values;
|
||||
},
|
||||
|
||||
entries:function() {
|
||||
var entries = [];
|
||||
this.forEach(function(value, key) { entries.push([key, value]); });
|
||||
return entries;
|
||||
},
|
||||
|
||||
// TODO: This is deprecated and will be deleted in a future version
|
||||
count:function() {
|
||||
return this.size;
|
||||
},
|
||||
|
||||
clear:function() {
|
||||
// TODO: Would Object.create(null) make any difference
|
||||
this._data = {};
|
||||
this.size = 0;
|
||||
},
|
||||
|
||||
clone:function() {
|
||||
return new HashMap(this);
|
||||
},
|
||||
|
||||
hash:function(key) {
|
||||
switch (this.type(key)) {
|
||||
case 'undefined':
|
||||
case 'null':
|
||||
case 'boolean':
|
||||
case 'number':
|
||||
case 'regexp':
|
||||
return key + '';
|
||||
|
||||
case 'date':
|
||||
return '♣' + key.getTime();
|
||||
|
||||
case 'string':
|
||||
return '♠' + key;
|
||||
|
||||
case 'array':
|
||||
var hashes = [];
|
||||
for (var i = 0; i < key.length; i++) {
|
||||
hashes[i] = this.hash(key[i]);
|
||||
}
|
||||
return '♥' + hashes.join('⁞');
|
||||
|
||||
default:
|
||||
// TODO: Don't use expandos when Object.defineProperty is not available?
|
||||
if (!key.hasOwnProperty('_hmuid_')) {
|
||||
key._hmuid_ = ++HashMap.uid;
|
||||
hide(key, '_hmuid_');
|
||||
}
|
||||
|
||||
return '♦' + key._hmuid_;
|
||||
}
|
||||
},
|
||||
|
||||
forEach:function(func, ctx) {
|
||||
for (var key in this._data) {
|
||||
var data = this._data[key];
|
||||
func.call(ctx || this, data[1], data[0]);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
HashMap.uid = 0;
|
||||
|
||||
//- Add chaining to all methods that don't return something
|
||||
|
||||
['set','multi','copy','delete','clear','forEach'].forEach(function(method) {
|
||||
var fn = proto[method];
|
||||
proto[method] = function() {
|
||||
fn.apply(this, arguments);
|
||||
return this;
|
||||
};
|
||||
});
|
||||
|
||||
//- Backwards compatibility
|
||||
|
||||
// TODO: remove() is deprecated and will be deleted in a future version
|
||||
HashMap.prototype.remove = HashMap.prototype.delete;
|
||||
|
||||
//- Utils
|
||||
|
||||
function multi(map, args) {
|
||||
for (var i = 0; i < args.length; i += 2) {
|
||||
map.set(args[i], args[i+1]);
|
||||
}
|
||||
}
|
||||
|
||||
function hide(obj, prop) {
|
||||
// Make non iterable if supported
|
||||
if (Object.defineProperty) {
|
||||
Object.defineProperty(obj, prop, {enumerable:false});
|
||||
}
|
||||
}
|
||||
|
||||
return HashMap;
|
||||
}));
|
||||
/**
|
||||
* HashMap - HashMap Class for JavaScript
|
||||
* @author Ariel Flesler <aflesler@gmail.com>
|
||||
* @version 2.0.6
|
||||
* Homepage: https://github.com/flesler/hashmap
|
||||
*/
|
||||
|
||||
(function(factory) {
|
||||
/* global define */
|
||||
if (typeof define === 'function' && define.amd) {
|
||||
// AMD. Register as an anonymous module.
|
||||
define([], factory);
|
||||
} else if (typeof module === 'object') {
|
||||
// Node js environment
|
||||
var HashMap = module.exports = factory();
|
||||
// Keep it backwards compatible
|
||||
HashMap.HashMap = HashMap;
|
||||
} else {
|
||||
// Browser globals (this is window)
|
||||
this.HashMap = factory();
|
||||
}
|
||||
}(function() {
|
||||
|
||||
function HashMap(other) {
|
||||
this.clear();
|
||||
switch (arguments.length) {
|
||||
case 0: break;
|
||||
case 1: {
|
||||
if ('length' in other) {
|
||||
// Flatten 2D array to alternating key-value array
|
||||
multi(this, Array.prototype.concat.apply([], other));
|
||||
} else { // Assumed to be a HashMap instance
|
||||
this.copy(other);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: multi(this, arguments); break;
|
||||
}
|
||||
}
|
||||
|
||||
var proto = HashMap.prototype = {
|
||||
constructor:HashMap,
|
||||
|
||||
get:function(key) {
|
||||
var data = this._data[this.hash(key)];
|
||||
return data && data[1];
|
||||
},
|
||||
|
||||
set:function(key, value) {
|
||||
// Store original key as well (for iteration)
|
||||
var hash = this.hash(key);
|
||||
if ( !(hash in this._data) ) {
|
||||
this.size++;
|
||||
}
|
||||
this._data[hash] = [key, value];
|
||||
},
|
||||
|
||||
multi:function() {
|
||||
multi(this, arguments);
|
||||
},
|
||||
|
||||
copy:function(other) {
|
||||
for (var hash in other._data) {
|
||||
if ( !(hash in this._data) ) {
|
||||
this.size++;
|
||||
}
|
||||
this._data[hash] = other._data[hash];
|
||||
}
|
||||
},
|
||||
|
||||
has:function(key) {
|
||||
return this.hash(key) in this._data;
|
||||
},
|
||||
|
||||
search:function(value) {
|
||||
for (var key in this._data) {
|
||||
if (this._data[key][1] === value) {
|
||||
return this._data[key][0];
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
},
|
||||
|
||||
delete:function(key) {
|
||||
var hash = this.hash(key);
|
||||
if ( hash in this._data ) {
|
||||
this.size--;
|
||||
delete this._data[hash];
|
||||
}
|
||||
},
|
||||
|
||||
type:function(key) {
|
||||
var str = Object.prototype.toString.call(key);
|
||||
var type = str.slice(8, -1).toLowerCase();
|
||||
// Some browsers yield DOMWindow or Window for null and undefined, works fine on Node
|
||||
if (!key && (type === 'domwindow' || type === 'window')) {
|
||||
return key + '';
|
||||
}
|
||||
return type;
|
||||
},
|
||||
|
||||
keys:function() {
|
||||
var keys = [];
|
||||
this.forEach(function(_, key) { keys.push(key); });
|
||||
return keys;
|
||||
},
|
||||
|
||||
values:function() {
|
||||
var values = [];
|
||||
this.forEach(function(value) { values.push(value); });
|
||||
return values;
|
||||
},
|
||||
|
||||
entries:function() {
|
||||
var entries = [];
|
||||
this.forEach(function(value, key) { entries.push([key, value]); });
|
||||
return entries;
|
||||
},
|
||||
|
||||
// TODO: This is deprecated and will be deleted in a future version
|
||||
count:function() {
|
||||
return this.size;
|
||||
},
|
||||
|
||||
clear:function() {
|
||||
// TODO: Would Object.create(null) make any difference
|
||||
this._data = {};
|
||||
this.size = 0;
|
||||
},
|
||||
|
||||
clone:function() {
|
||||
return new HashMap(this);
|
||||
},
|
||||
|
||||
hash:function(key) {
|
||||
switch (this.type(key)) {
|
||||
case 'undefined':
|
||||
case 'null':
|
||||
case 'boolean':
|
||||
case 'number':
|
||||
case 'regexp':
|
||||
return key + '';
|
||||
|
||||
case 'date':
|
||||
return '♣' + key.getTime();
|
||||
|
||||
case 'string':
|
||||
return '♠' + key;
|
||||
|
||||
case 'array':
|
||||
var hashes = [];
|
||||
for (var i = 0; i < key.length; i++) {
|
||||
hashes[i] = this.hash(key[i]);
|
||||
}
|
||||
return '♥' + hashes.join('⁞');
|
||||
|
||||
default:
|
||||
// TODO: Don't use expandos when Object.defineProperty is not available?
|
||||
if (!key.hasOwnProperty('_hmuid_')) {
|
||||
key._hmuid_ = ++HashMap.uid;
|
||||
hide(key, '_hmuid_');
|
||||
}
|
||||
|
||||
return '♦' + key._hmuid_;
|
||||
}
|
||||
},
|
||||
|
||||
forEach:function(func, ctx) {
|
||||
for (var key in this._data) {
|
||||
var data = this._data[key];
|
||||
func.call(ctx || this, data[1], data[0]);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
HashMap.uid = 0;
|
||||
|
||||
//- Add chaining to all methods that don't return something
|
||||
|
||||
['set','multi','copy','delete','clear','forEach'].forEach(function(method) {
|
||||
var fn = proto[method];
|
||||
proto[method] = function() {
|
||||
fn.apply(this, arguments);
|
||||
return this;
|
||||
};
|
||||
});
|
||||
|
||||
//- Backwards compatibility
|
||||
|
||||
// TODO: remove() is deprecated and will be deleted in a future version
|
||||
HashMap.prototype.remove = HashMap.prototype.delete;
|
||||
|
||||
//- Utils
|
||||
|
||||
function multi(map, args) {
|
||||
for (var i = 0; i < args.length; i += 2) {
|
||||
map.set(args[i], args[i+1]);
|
||||
}
|
||||
}
|
||||
|
||||
function hide(obj, prop) {
|
||||
// Make non iterable if supported
|
||||
if (Object.defineProperty) {
|
||||
Object.defineProperty(obj, prop, {enumerable:false});
|
||||
}
|
||||
}
|
||||
|
||||
return HashMap;
|
||||
}));
|
||||
|
||||
24
node_modules/hashmap/package.json
generated
vendored
24
node_modules/hashmap/package.json
generated
vendored
@@ -1,28 +1,32 @@
|
||||
{
|
||||
"_from": "hashmap",
|
||||
"_args": [
|
||||
[
|
||||
"hashmap@2.3.0",
|
||||
"/var/www/backend/minis-data"
|
||||
]
|
||||
],
|
||||
"_from": "hashmap@2.3.0",
|
||||
"_id": "hashmap@2.3.0",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha1-sT+2XafIul49uPwbjFuh0ASdryI=",
|
||||
"_location": "/hashmap",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "tag",
|
||||
"type": "version",
|
||||
"registry": true,
|
||||
"raw": "hashmap",
|
||||
"raw": "hashmap@2.3.0",
|
||||
"name": "hashmap",
|
||||
"escapedName": "hashmap",
|
||||
"rawSpec": "",
|
||||
"rawSpec": "2.3.0",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "latest"
|
||||
"fetchSpec": "2.3.0"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"#USER",
|
||||
"/"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/hashmap/-/hashmap-2.3.0.tgz",
|
||||
"_shasum": "b13fb65da7c8ba5e3db8fc1b8c5ba1d0049daf22",
|
||||
"_spec": "hashmap",
|
||||
"_where": "C:\\Users\\jonio\\Documents\\Programmieren\\Miniportal\\Neu\\MiniportalAPI",
|
||||
"_spec": "2.3.0",
|
||||
"_where": "/var/www/backend/minis-data",
|
||||
"author": {
|
||||
"name": "Ariel Flesler",
|
||||
"url": "https://github.com/flesler"
|
||||
@@ -30,9 +34,7 @@
|
||||
"bugs": {
|
||||
"url": "https://github.com/flesler/hashmap/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"dependencies": {},
|
||||
"deprecated": false,
|
||||
"description": "HashMap Class for JavaScript",
|
||||
"devDependencies": {
|
||||
"chai": "4.1.1",
|
||||
|
||||
Reference in New Issue
Block a user