Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

graphology

Package Overview
Dependencies
Maintainers
1
Versions
65
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

graphology - npm Package Compare versions

Comparing version 0.0.4 to 0.1.0

24

dist/attributes.js

@@ -64,6 +64,4 @@ 'use strict';

var data = void 0;
var data = this[key].get(element);
if (this.map) data = this[key].get(element);else data = this[key][element];
return data.attributes[name];

@@ -114,6 +112,4 @@ };

var data = void 0;
var data = this[key].get(element);
if (this.map) data = this[key].get(element);else data = this[key][element];
return data.attributes;

@@ -172,6 +168,4 @@ };

var data = void 0;
var data = this[key].get(element);
if (this.map) data = this[key].get(element);else data = this[key][element];
data.attributes[name] = value;

@@ -243,6 +237,4 @@

var data = void 0;
var data = this[key].get(element);
if (this.map) data = this[key].get(element);else data = this[key][element];
data.attributes[name] = updater(data.attributes[name]);

@@ -312,6 +304,4 @@

var data = void 0;
var data = this[key].get(element);
if (this.map) data = this[key].get(element);else data = this[key][element];
var oldAttributes = data.attributes;

@@ -383,6 +373,4 @@

var data = void 0;
var data = this[key].get(element);
if (this.map) data = this[key].get(element);else data = this[key][element];
(0, _utils.assign)(data.attributes, attributes);

@@ -389,0 +377,0 @@

@@ -32,7 +32,2 @@ 'use strict';

_this.data = data || {};
// This is V8 specific to enhance stack readability
// TODO: tweak this part with real world examples
// if (typeof Error.captureStackTrace === 'function')
// Error.captureStackTrace(this, this.constructor);
return _this;

@@ -53,2 +48,5 @@ }

_this2.name = 'InvalidArgumentsGraphError';
// This is V8 specific to enhance stack readability
if (typeof Error.captureStackTrace === 'function') Error.captureStackTrace(_this2, InvalidArgumentsGraphError.prototype.constructor);
return _this2;

@@ -69,2 +67,5 @@ }

_this3.name = 'NotFoundGraphError';
// This is V8 specific to enhance stack readability
if (typeof Error.captureStackTrace === 'function') Error.captureStackTrace(_this3, NotFoundGraphError.prototype.constructor);
return _this3;

@@ -85,2 +86,5 @@ }

_this4.name = 'UsageGraphError';
// This is V8 specific to enhance stack readability
if (typeof Error.captureStackTrace === 'function') Error.captureStackTrace(_this4, UsageGraphError.prototype.constructor);
return _this4;

@@ -87,0 +91,0 @@ }

@@ -76,62 +76,2 @@ 'use strict';

var GraphMap = function (_Graph5) {
_inherits(GraphMap, _Graph5);
function GraphMap(data, options) {
_classCallCheck(this, GraphMap);
return _possibleConstructorReturn(this, _Graph5.call(this, data, (0, _utils.assign)({ map: true }, options)));
}
return GraphMap;
}(_graph2.default);
var DirectedGraphMap = function (_Graph6) {
_inherits(DirectedGraphMap, _Graph6);
function DirectedGraphMap(data, options) {
_classCallCheck(this, DirectedGraphMap);
return _possibleConstructorReturn(this, _Graph6.call(this, data, (0, _utils.assign)({ map: true, type: 'directed' }, options)));
}
return DirectedGraphMap;
}(_graph2.default);
var UndirectedGraphMap = function (_Graph7) {
_inherits(UndirectedGraphMap, _Graph7);
function UndirectedGraphMap(data, options) {
_classCallCheck(this, UndirectedGraphMap);
return _possibleConstructorReturn(this, _Graph7.call(this, data, (0, _utils.assign)({ map: true, type: 'undirected' }, options)));
}
return UndirectedGraphMap;
}(_graph2.default);
var MultiDirectedGraphMap = function (_Graph8) {
_inherits(MultiDirectedGraphMap, _Graph8);
function MultiDirectedGraphMap(data, options) {
_classCallCheck(this, MultiDirectedGraphMap);
return _possibleConstructorReturn(this, _Graph8.call(this, data, (0, _utils.assign)({ map: true, multi: true, type: 'directed' }, options)));
}
return MultiDirectedGraphMap;
}(_graph2.default);
var MultiUndirectedGraphMap = function (_Graph9) {
_inherits(MultiUndirectedGraphMap, _Graph9);
function MultiUndirectedGraphMap(data, options) {
_classCallCheck(this, MultiUndirectedGraphMap);
return _possibleConstructorReturn(this, _Graph9.call(this, data, (0, _utils.assign)({ map: true, multi: true, type: 'undirected' }, options)));
}
return MultiUndirectedGraphMap;
}(_graph2.default);
/**

@@ -146,7 +86,2 @@ * Exporting as CommonJS for convenience.

_graph2.default.MultiUndirectedGraph = MultiUndirectedGraph;
_graph2.default.GraphMap = GraphMap;
_graph2.default.DirectedGraphMap = DirectedGraphMap;
_graph2.default.UndirectedGraphMap = UndirectedGraphMap;
_graph2.default.MultiDirectedGraphMap = MultiDirectedGraphMap;
_graph2.default.MultiUndirectedGraphMap = MultiUndirectedGraphMap;

@@ -153,0 +88,0 @@ _graph2.default.InvalidArgumentsGraphError = _errors.InvalidArgumentsGraphError;

@@ -6,11 +6,13 @@ 'use strict';

});
exports.INDICES = undefined;
exports.updateStructureIndex = updateStructureIndex;
exports.clearEdgeFromStructureIndex = clearEdgeFromStructureIndex;
exports.clearStructureIndex = clearStructureIndex;
/**
* Graphology Indexes Functions
* =============================
*
* Bunch of functions used to compute or clear indexes.
*/
var INDICES = exports.INDICES = new Set(['structure']);
var _utils = require('./utils');
var INDICES = exports.INDICES = new _utils.BasicSet(['structure', 'neighbors']);
/**

@@ -27,11 +29,3 @@ * Structure.

*/
/**
* Graphology Indexes Functions
* =============================
*
* Bunch of functions used to compute or clear indexes.
*/
function updateStructureIndex(graph, edge, data) {
var map = graph.map,
CSet = map ? Set : _utils.BasicSet;

@@ -45,4 +39,4 @@ // Retrieving edge information

var sourceData = map ? graph._nodes.get(source) : graph._nodes[source],
targetData = map ? graph._nodes.get(target) : graph._nodes[target];
var sourceData = graph._nodes.get(source),
targetData = graph._nodes.get(target);

@@ -53,14 +47,9 @@ var outKey = undirected ? 'undirectedOut' : 'out',

// NOTE: The set of edges is the same for source & target
var commonSet = new CSet();
var commonSet = new Set();
// Handling source
sourceData[outKey] = sourceData[outKey] || (map ? new Map() : {});
sourceData[outKey] = sourceData[outKey] || Object.create(null);
if (map) {
if (!sourceData[outKey].has(target)) sourceData[outKey].set(target, commonSet);
sourceData[outKey].get(target).add(edge);
} else {
if (!(target in sourceData[outKey])) sourceData[outKey][target] = commonSet;
sourceData[outKey][target].add(edge);
}
if (!(target in sourceData[outKey])) sourceData[outKey][target] = commonSet;
sourceData[outKey][target].add(edge);

@@ -72,9 +61,5 @@ // If selfLoop, we break here

// care of with source above)
targetData[inKey] = targetData[inKey] || (map ? new Map() : {});
targetData[inKey] = targetData[inKey] || Object.create(null);
if (map) {
if (!targetData[inKey].has(source)) targetData[inKey].set(source, commonSet);
} else {
if (!(source in targetData[inKey])) targetData[inKey][source] = commonSet;
}
if (!(source in targetData[inKey])) targetData[inKey][source] = commonSet;
}

@@ -93,8 +78,8 @@

var undirected = data.undirected;
var map = graph.map;
// NOTE: since the edge set is the same for source & target, we can only
// affect source
var sourceData = map ? graph._nodes.get(source) : graph._nodes[source];
var sourceData = graph._nodes.get(source);
var outKey = undirected ? 'undirectedOut' : 'out';

@@ -105,7 +90,3 @@

// NOTE: possible to clear empty sets from memory altogether
if (map) {
if (sourceIndex.has(target)) sourceIndex.get(target).delete(edge);
} else {
if (target in sourceIndex) sourceIndex[target].delete(edge);
}
if (target in sourceIndex) sourceIndex[target].delete(edge);
}

@@ -119,22 +100,10 @@

function clearStructureIndex(graph) {
if (graph.map) {
graph._nodes.forEach(function (data) {
graph._nodes.forEach(function (data) {
// Clearing properties
delete data.in;
delete data.out;
delete data.undirectedIn;
delete data.undirectedOut;
});
} else {
for (var node in graph._nodes) {
var data = graph._nodes[node];
// Clearing properties
delete data.in;
delete data.out;
delete data.undirectedIn;
delete data.undirectedOut;
}
}
// Clearing properties
delete data.in;
delete data.out;
delete data.undirectedIn;
delete data.undirectedOut;
});
}

@@ -61,25 +61,2 @@ 'use strict';

/**
* Function collecting edges from the given map.
*
* @param {Map|undefined} map - Target map.
* @param {mixed} [key] - Optional key.
* @return {array} - The found edges.
*/
function collectEdgesFromMap(map, key) {
var edges = [];
var hasKey = arguments.length > 1;
if (!map || hasKey && !map.get(key)) return edges;
if (hasKey) return Array.from(map.get(key));
map.forEach(function (set) {
edges.push.apply(edges, Array.from(set));
});
return edges;
}
/**
* Function collecting edges from the given object.

@@ -91,3 +68,3 @@ *

*/
function collectEdgesFromObject(object, key) {
function collectEdges(object, key) {
var edges = [];

@@ -99,6 +76,6 @@

if (hasKey) return object[key].values();
if (hasKey) return Array.from(object[key]);
for (var k in object) {
edges.push.apply(edges, object[k].values());
edges.push.apply(edges, Array.from(object[k]));
}return edges;

@@ -108,25 +85,2 @@ }

/**
* Function counting edges from the given map.
*
* @param {Map|undefined} map - Target map.
* @param {mixed} [key] - Optional key.
* @return {number} - The number of found edges.
*/
function countEdgesFromMap(map, key) {
var nb = 0;
var hasKey = arguments.length > 1;
if (!map || hasKey && !map.get(key)) return nb;
if (hasKey) return map.get(key).size;
map.forEach(function (set) {
nb += set.size;
});
return nb;
}
/**
* Function counting edges from the given object.

@@ -138,3 +92,3 @@ *

*/
function countEdgesFromObject(object, key) {
function countEdges(object, key) {
var nb = 0;

@@ -154,18 +108,2 @@

/**
* Function merging edges found in a map into the given set.
*
* @param {Set} edges - Current set of edges.
* @param {Map|undefined} map - Target map.
*/
function mergeEdgesFromMap(edges, map) {
if (!map) return;
map.forEach(function (set) {
set.forEach(function (value) {
return edges.add(value);
});
});
}
/**
* Function merging edges found in an object into the given set.

@@ -176,9 +114,9 @@ *

*/
function mergeEdgesFromObject(edges, object) {
function mergeEdges(edges, object) {
if (!object) return;
for (var k in object) {
for (var v in object[k].entries) {
edges.add(v);
}
object[k].forEach(function (value) {
return edges.add(value);
});
}

@@ -201,28 +139,13 @@ }

if (graph.map) {
if (type === 'mixed') return Array.from(graph._edges.keys());
if (type === 'mixed') return Array.from(graph._edges.keys());
graph._edges.forEach(function (data, edge) {
graph._edges.forEach(function (data, edge) {
if (type === 'selfLoops' === (data.source === data.target) && !!data.undirected === (type === 'undirected')) {
if (type === 'selfLoops' === (data.source === data.target) && !!data.undirected === (type === 'undirected')) {
if (!count) list.push(edge);
if (!count) list.push(edge);
nb++;
}
});
} else {
if (type === 'mixed') return Object.keys(graph._edges);
for (var edge in graph._edges) {
var data = graph._edges[edge];
if (type === 'selfLoops' === (data.source === data.target) && !!data.undirected === (type === 'undirected')) {
if (!count) list.push(edge);
nb++;
}
nb++;
}
}
});

@@ -243,4 +166,2 @@ return count ? nb : list;

function createEdgeArrayForNode(count, graph, type, direction, node) {
var countEdges = graph.map ? countEdgesFromMap : countEdgesFromObject,
collectEdges = graph.map ? collectEdgesFromMap : collectEdgesFromObject;

@@ -253,6 +174,4 @@ // For this, we need to compute the "structure" index

var nodeData = void 0;
var nodeData = graph._nodes.get(node);
if (graph.map) nodeData = graph._nodes.get(node);else nodeData = graph._nodes[node];
if (type === 'mixed' || type === 'directed' || type === 'selfLoops') {

@@ -301,3 +220,2 @@

function createEdgeArrayForBunch(name, graph, type, direction, bunch) {
var mergeEdges = graph.map ? mergeEdgesFromMap : mergeEdgesFromObject;

@@ -307,9 +225,9 @@ // For this, we need to compute the "structure" index

var edges = graph.map ? new Set() : new _utils.BasicSet();
var edges = new Set();
// Iterating over the bunch
(0, _utils.overBunch)(bunch, function (error, node) {
(0, _utils.overBunch)(bunch, function (node) {
if (!graph.hasNode(node)) throw new _errors.NotFoundGraphError('Graph.' + name + ': could not find the "' + node + '" node in the graph in the given bunch.');
var nodeData = graph.map ? graph._nodes.get(node) : graph._nodes[node];
var nodeData = graph._nodes.get(node);

@@ -329,3 +247,3 @@ if (type === 'mixed' || type === 'directed') {

return graph.map ? Array.from(edges.values()) : edges.values();
return Array.from(edges.values());
}

@@ -344,4 +262,2 @@

function createEdgeArrayForPath(count, graph, type, source, target) {
var countEdges = graph.map ? countEdgesFromMap : countEdgesFromObject,
collectEdges = graph.map ? collectEdgesFromMap : collectEdgesFromObject;

@@ -354,3 +270,3 @@ // For this, we need to compute the "structure" index

var sourceData = graph.map ? graph._nodes.get(source) : graph._nodes[source];
var sourceData = graph._nodes.get(source);

@@ -357,0 +273,0 @@ if (type === 'mixed' || type === 'directed') {

@@ -57,16 +57,2 @@ 'use strict';

/**
* Function merging neighbors into the given set iterating over the given map.
*
* @param {Set} neighbors - Neighbors set.
* @param {Map} map - Target map.
*/
function mergeNeighborsFromMap(neighbors, map) {
if (!map) return;
map.forEach(function (_, neighbor) {
neighbors.add(neighbor);
});
}
/**
* Function merging neighbors into the given set iterating over the given object.

@@ -77,3 +63,3 @@ *

*/
function mergeNeighborsFromObject(neighbors, object) {
function mergeNeighbors(neighbors, object) {
if (!object) return;

@@ -96,3 +82,2 @@

function createNeighborSetForNode(graph, type, direction, node) {
var mergeNeighbors = graph.map ? mergeNeighborsFromMap : mergeNeighborsFromObject;

@@ -102,5 +87,5 @@ // For this, we need to compute the "structure" index

var neighbors = graph.map ? new Set() : new _utils.BasicSet();
var neighbors = new Set();
var nodeData = graph.map ? graph._nodes.get(node) : graph._nodes[node];
var nodeData = graph._nodes.get(node);

@@ -141,3 +126,2 @@ if (type === 'mixed' || type === 'directed') {

function createNeighborSetForBunch(name, graph, type, direction, bunch) {
var mergeNeighbors = graph.map ? mergeNeighborsFromMap : mergeNeighborsFromObject;

@@ -147,8 +131,8 @@ // For this, we need to compute the "structure" index

var neighbors = graph.map ? new Set() : new _utils.BasicSet();
var neighbors = new Set();
(0, _utils.overBunch)(bunch, function (error, node) {
(0, _utils.overBunch)(bunch, function (node) {
if (!graph.hasNode(node)) throw new _errors.NotFoundGraphError('Graph.' + name + ': could not find the "' + node + '" node in the graph in the given bunch.');
var nodeData = graph.map ? graph._nodes.get(node) : graph._nodes[node];
var nodeData = graph._nodes.get(node);

@@ -241,3 +225,3 @@ if (type === 'mixed' || type === 'directed') {

return this.map ? Array.from(_neighbors) : _neighbors.values();
return Array.from(_neighbors);
} else if ((0, _utils.isBunch)(nodeOrBunch)) {

@@ -255,3 +239,3 @@

return this.map ? Array.from(_neighbors2) : _neighbors2.values();
return Array.from(_neighbors2);
} else {

@@ -258,0 +242,0 @@ throw new _errors.NotFoundGraphError('Graph.' + name + ': could not find the "' + nodeOrBunch + '" node in the graph.');

@@ -12,2 +12,4 @@ 'use strict';

exports.assign = assign;
exports.createInternalMap = createInternalMap;
exports.firstItemOfSet = firstItemOfSet;
exports.isBunch = isBunch;

@@ -21,6 +23,2 @@ exports.isGraph = isGraph;

exports.uuid = uuid;
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/* eslint no-nested-ternary: 0 */
/**

@@ -59,59 +57,37 @@ * Graphology Utilities

/**
* Class emulating a Set object & used internally to reduce memory footprint &
* ensure ES5 compatibility.
* Custom Map used internally to coerce keys on vital operations.
*
* @constructor
* @return {Map}
*/
function createInternalMap() {
var map = new Map();
var BasicSet = exports.BasicSet = function () {
function BasicSet(values) {
_classCallCheck(this, BasicSet);
this.entries = {};
this.size = 0;
if (values) {
for (var i = 0, l = values.length; i < l; i++) {
this.add(values[i]);
}
}
}
BasicSet.prototype.add = function add(value) {
if (!(value in this.entries)) {
this.entries[value] = true;
this.size++;
}
map.set = function (key, value) {
key = '' + key;
return Map.prototype.set.call(this, key, value);
};
BasicSet.prototype.delete = function _delete(value) {
delete this.entries[value];
this.size--;
map.get = function (key) {
key = '' + key;
return Map.prototype.get.call(this, key);
};
BasicSet.prototype.has = function has(value) {
return value in this.entries;
map.has = function (key) {
key = '' + key;
return Map.prototype.has.call(this, key);
};
BasicSet.prototype.first = function first() {
for (var value in this.entries) {
return value;
}
};
return map;
}
BasicSet.prototype.values = function values() {
return Object.keys(this.entries);
};
/**
* Function returning the first item of a Set.
*
* @param {object} set - Target set.
* @return {any} - The "first" item.
*/
function firstItemOfSet(set) {
return set.values().next().value;
}
BasicSet.prototype.inspect = function inspect() {
var values = this.values().map(function (v) {
return JSON.stringify(v);
}).join(', ');
return 'BasicSet { ' + values + ' }';
};
return BasicSet;
}();
/**

@@ -123,4 +99,2 @@ * Checks whether the given value is a potential bunch.

*/
function isBunch(value) {

@@ -156,5 +130,2 @@ return !!value && (typeof value === 'undefined' ? 'undefined' : _typeof(value)) === 'object' && (Array.isArray(value) || typeof Map === 'function' && value instanceof Map || typeof Set === 'function' && value instanceof Set || !(value instanceof Date) && !(value instanceof RegExp));

*/
// TODO: error management
// TODO: support ES6 Maps as attributes
function overBunch(bunch, callback) {

@@ -165,3 +136,3 @@

for (var i = 0, l = bunch.length; i < l; i++) {
var shouldBreak = callback(null, bunch[i], {}) === false;
var shouldBreak = callback(bunch[i], null) === false;

@@ -174,32 +145,24 @@ if (shouldBreak) break;

else if (typeof bunch.forEach === 'function') {
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
var iterator = bunch.entries();
try {
for (var _iterator = bunch.entries()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var _step$value = _slicedToArray(_step.value, 2);
var _shouldBreak = false,
step = void 0;
var k = _step$value[0];
var v = _step$value[1];
while (step = iterator.next()) {
var _step = step;
var value = _step.value;
var done = _step.done;
var _shouldBreak = false;
if (v === k) _shouldBreak = callback(null, v, {}) === false;else _shouldBreak = callback(null, k, v) === false;
if (done) break;
if (_shouldBreak) break;
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
var _value = _slicedToArray(value, 2);
var k = _value[0];
var v = _value[1];
if (v === k) _shouldBreak = callback(v, null) === false;else _shouldBreak = callback(k, v) === false;
if (_shouldBreak) break;
}

@@ -213,3 +176,3 @@ }

var _shouldBreak2 = callback(null, key, attributes);
var _shouldBreak2 = callback(key, attributes);

@@ -264,32 +227,80 @@ if (_shouldBreak2) break;

* @param {string} name - Member name.
* @param {function} getter - The attached getter function.
* @param {mixed} value - The attached getter or fixed value.
*/
function readOnlyProperty(target, name, getter) {
Object.defineProperty(target, name, {
function readOnlyProperty(target, name, value) {
var descriptor = {
enumerable: true,
configurable: false,
get: getter
});
configurable: false
};
if (typeof value === 'function') {
descriptor.get = value;
} else {
descriptor.value = value;
descriptor.writable = false;
}
Object.defineProperty(target, name, descriptor);
}
/**
* Simple uuid v4 function.
* Function returning uuid v4 compressed into base62 to have 22 characters-long
* ids easily copy-pastable or usable in a URL.
*
* @return {string} - The uuid.
*/
function uuid() {
var id = '',
random = void 0,
i = void 0;
var RANDOM_BYTES = new Uint8Array(16),
BASE62 = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
for (i = 0; i < 32; i++) {
random = Math.random() * 16 | 0;
function rng() {
for (var i = 0, r; i < 16; i++) {
if ((i & 0x03) === 0) r = Math.random() * 0x100000000;
RANDOM_BYTES[i] = r >>> ((i & 0x03) << 3) & 0xff;
}
if (i === 8 || i === 12 || i === 16 || i === 20) {
id += '-';
return RANDOM_BYTES;
}
function uuidBytes() {
var random = rng();
random[6] = random[6] & 0x0f | 0x40;
random[8] = random[8] & 0x3f | 0x80;
return random;
}
function toBase62(bytes) {
var digits = [0];
for (var i = 0, l = bytes.length; i < l; i++) {
var carry = bytes[i];
for (var j = 0, m = digits.length; j < m; j++) {
carry += digits[j] << 8;
digits[j] = carry % 62;
carry = carry / 62 | 0;
}
id += (i === 12 ? 4 : i === 16 ? random & 3 | 8 : random).toString(16);
while (carry > 0) {
digits.push(carry % 62);
carry = carry / 62 | 0;
}
}
return id;
var string = '';
for (var _i = 0, _l = bytes.length; bytes[_i] === 0 && _i < _l - 1; _i++) {
string += BASE62[0];
}for (var _i2 = digits.length - 1; _i2 >= 0; _i2--) {
string += BASE62[digits[_i2]];
}while (string.length < 22) {
string += '0';
}return string;
}
function uuid() {
var bytes = uuidBytes();
return toBase62(bytes);
}
{
"name": "graphology",
"version": "0.0.4",
"version": "0.1.0",
"description": "A robust and multipurpose Graph object for JavaScript.",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -57,10 +57,4 @@ 'use strict';

var _helpers = require('./helpers');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var DEFAULTS = {
map: true
};
var createErrorChecker = function createErrorChecker(name) {

@@ -80,4 +74,3 @@ return function () {

*/
function specs(Graph, implementation, options) {
options = (0, _helpers.deepMerge)({}, DEFAULTS, options);
function specs(Graph, implementation) {

@@ -112,18 +105,3 @@ var errors = [['invalid', 'InvalidArgumentsGraphError'], ['notFound', 'NotFoundGraphError'], ['usage', 'UsageGraphError']];

if (options.map) {
var GraphMap = implementation.GraphMap;
tests.Map = {
'Mutation': (0, _mutation2.default)(GraphMap, errorCheckers),
'Read': (0, _read2.default)(GraphMap, errorCheckers),
'Attributes': (0, _attributes2.default)(GraphMap, errorCheckers),
'Iteration': (0, _iteration2.default)(GraphMap, errorCheckers),
'Serialization': (0, _serialization2.default)(GraphMap, errorCheckers),
'Events': (0, _events2.default)(GraphMap),
'Known Methods': (0, _known2.default)(GraphMap, errorCheckers),
'Miscellaneous': (0, _misc2.default)(GraphMap)
};
}
return tests;
}

@@ -23,5 +23,5 @@ 'use strict';

*/
var CONSTRUCTORS = ['DirectedGraph', 'UndirectedGraph', 'MultiDirectedGraph', 'MultiUndirectedGraph', 'GraphMap', 'DirectedGraphMap', 'UndirectedGraphMap', 'MultiDirectedGraphMap', 'MultiUndirectedGraphMap'];
var CONSTRUCTORS = ['DirectedGraph', 'UndirectedGraph', 'MultiDirectedGraph', 'MultiUndirectedGraph'];
var OPTIONS = [{ map: false, multi: false, type: 'directed' }, { map: false, multi: false, type: 'undirected' }, { map: false, multi: true, type: 'directed' }, { map: false, multi: true, type: 'undirected' }, { map: true, multi: false, type: 'mixed' }, { map: true, multi: false, type: 'directed' }, { map: true, multi: false, type: 'undirected' }, { map: true, multi: true, type: 'directed' }, { map: true, multi: true, type: 'undirected' }];
var OPTIONS = [{ multi: false, type: 'directed' }, { multi: false, type: 'undirected' }, { multi: true, type: 'directed' }, { multi: true, type: 'undirected' }];

@@ -142,14 +142,2 @@ function instantiation(Graph, inmplementation, checkers) {

/**
* map
*/
'map': {
'providing a non-boolean value should throw.': function providingANonBooleanValueShouldThrow() {
_assert2.default.throws(function () {
var graph = new Graph(null, { map: 'test' });
}, invalid());
}
},
/**
* multi

@@ -273,3 +261,2 @@ */

var _OPTIONS$index = OPTIONS[index];
var map = _OPTIONS$index.map;
var multi = _OPTIONS$index.multi;

@@ -279,3 +266,2 @@ var type = _OPTIONS$index.type;

_assert2.default.strictEqual(graph.map, map);
_assert2.default.strictEqual(graph.multi, multi);

@@ -282,0 +268,0 @@ _assert2.default.strictEqual(graph.type, type);

@@ -18,3 +18,3 @@ 'use strict';

* Graphology Edges Iteration Specs
* ================================
* =================================
*

@@ -21,0 +21,0 @@ * Testing the edges iteration-related methods of the graph.

@@ -21,3 +21,3 @@ 'use strict';

* Graphology Edges Iteration Specs
* ================================
* =================================
*

@@ -24,0 +24,0 @@ * Testing the edges iteration-related methods of the graph.

@@ -28,5 +28,5 @@ 'use strict';

* Graphology Nodes Iteration Specs
* ================================
* =================================
*
* Testing the nodes iteration-related methods of the graph.
*/

@@ -27,2 +27,20 @@ 'use strict';

}
},
'Key coercion': {
'keys should be correctly coerced to strings.': function keysShouldBeCorrectlyCoercedToStrings() {
var graph = new Graph();
graph.addNode(1);
graph.addNode('2');
_assert2.default.strictEqual(graph.hasNode(1), true);
_assert2.default.strictEqual(graph.hasNode('1'), true);
_assert2.default.strictEqual(graph.hasNode(2), true);
_assert2.default.strictEqual(graph.hasNode('2'), true);
graph.addEdgeWithKey(3, 1, 2);
_assert2.default.strictEqual(graph.hasEdge(3), true);
_assert2.default.strictEqual(graph.hasEdge('3'), true);
}
}

@@ -29,0 +47,0 @@ };

@@ -14,8 +14,8 @@ 'use strict';

var PROPERTIES = ['order', 'size', 'type', 'multi', 'map', 'allowSelfLoops']; /**
* Graphology Properties Specs
* ============================
*
* Testing the properties of the graph.
*/
var PROPERTIES = ['order', 'size', 'type', 'multi', 'allowSelfLoops']; /**
* Graphology Properties Specs
* ============================
*
* Testing the properties of the graph.
*/
function properties(Graph) {

@@ -88,13 +88,2 @@

/**
* Map.
*/
'#.map': {
'it should be false by default.': function itShouldBeFalseByDefault() {
var graph = new Graph();
_assert2.default.strictEqual(graph.map, false);
}
},
/**
* Multi.

@@ -101,0 +90,0 @@ */

@@ -268,2 +268,12 @@ 'use strict';

'it should throw if the node & the edge are not related.': function itShouldThrowIfTheNodeTheEdgeAreNotRelated() {
var graph = new Graph();
graph.addNodesFrom(['Thomas', 'Isabella', 'Estelle']);
graph.addEdgeWithKey('I->E', 'Isabella', 'Estelle');
_assert2.default.throws(function () {
graph.relatedNode('Thomas', 'I->E');
}, notFound());
},
'it should return the correct node.': function itShouldReturnTheCorrectNode() {

@@ -447,3 +457,3 @@ var graph = new Graph();

_assert2.default.strictEqual(graph.directedDegree('Helen'), 4);
_assert2.default.strictEqual(graph.directedDegree('Helen'), 5);
_assert2.default.strictEqual(graph.directedDegree('Helen', false), 3);

@@ -482,3 +492,3 @@ }

_assert2.default.strictEqual(graph.undirectedDegree('Helen'), 2);
_assert2.default.strictEqual(graph.undirectedDegree('Helen'), 3);
_assert2.default.strictEqual(graph.undirectedDegree('Helen', false), 1);

@@ -519,3 +529,3 @@ }

_assert2.default.strictEqual(graph.degree('Helen'), 5);
_assert2.default.strictEqual(graph.degree('Helen'), 6);
_assert2.default.strictEqual(graph.degree('Helen', false), 4);

@@ -522,0 +532,0 @@ }

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc