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

topo

Package Overview
Dependencies
Maintainers
2
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

topo - npm Package Compare versions

Comparing version 1.1.0 to 2.0.0

123

lib/index.js

@@ -0,4 +1,6 @@

'use strict';
// Load modules
var Hoek = require('hoek');
const Hoek = require('hoek');

@@ -8,3 +10,3 @@

var internals = {};
const internals = {};

@@ -21,4 +23,2 @@

var self = this;
options = options || {};

@@ -28,6 +28,6 @@

var before = [].concat(options.before || []);
var after = [].concat(options.after || []);
var group = options.group || '?';
var sort = options.sort || 0; // Used for merging only
const before = [].concat(options.before || []);
const after = [].concat(options.after || []);
const group = options.group || '?';
const sort = options.sort || 0; // Used for merging only

@@ -39,6 +39,6 @@ Hoek.assert(before.indexOf(group) === -1, 'Item cannot come before itself:', group);

([].concat(nodes)).forEach(function (node, i) {
([].concat(nodes)).forEach((node, i) => {
var item = {
seq: self._items.length,
const item = {
seq: this._items.length,
sort: sort,

@@ -51,3 +51,3 @@ before: before,

self._items.push(item);
this._items.push(item);
});

@@ -57,3 +57,3 @@

var error = this._sort();
const error = this._sort();
Hoek.assert(!error, 'item', (group !== '?' ? 'added into group ' + group : ''), 'created a dependencies error');

@@ -68,7 +68,7 @@

others = [].concat(others);
for (var o = 0, ol = others.length; o < ol; ++o) {
var other = others[o];
for (let i = 0; i < others.length; ++i) {
const other = others[i];
if (other) {
for (var i = 0, il = other._items.length; i < il; ++i) {
var item = Hoek.shallow(other._items[i]);
for (let j = 0; j < other._items.length; ++j) {
const item = Hoek.shallow(other._items[j]);
this._items.push(item);

@@ -82,7 +82,7 @@ }

this._items.sort(internals.mergeSort);
for (i = 0, il = this._items.length; i < il; ++i) {
for (let i = 0; i < this._items.length; ++i) {
this._items[i].seq = i;
}
var error = this._sort();
const error = this._sort();
Hoek.assert(!error, 'merge created a dependencies error');

@@ -104,10 +104,10 @@

var groups = {};
var graph = {};
var graphAfters = {};
const groups = {};
const graph = {};
const graphAfters = {};
for (var i = 0, il = this._items.length; i < il; ++i) {
var item = this._items[i];
var seq = item.seq; // Unique across all items
var group = item.group;
for (let i = 0; i < this._items.length; ++i) {
const item = this._items[i];
const seq = item.seq; // Unique across all items
const group = item.group;

@@ -125,4 +125,4 @@ // Determine Groups

var after = item.after;
for (var j = 0, jl = after.length; j < jl; ++j) {
const after = item.after;
for (let j = 0; j < after.length; ++j) {
graphAfters[after[j]] = (graphAfters[after[j]] || []).concat(seq);

@@ -134,13 +134,13 @@ }

var graphNodes = Object.keys(graph);
for (i = 0, il = graphNodes.length; i < il; ++i) {
var node = graphNodes[i];
var expandedGroups = [];
let graphNodes = Object.keys(graph);
for (let i = 0; i < graphNodes.length; ++i) {
const node = graphNodes[i];
const expandedGroups = [];
var graphNodeItems = Object.keys(graph[node]);
for (j = 0, jl = graphNodeItems.length; j < jl; ++j) {
group = graph[node][graphNodeItems[j]];
const graphNodeItems = Object.keys(graph[node]);
for (let j = 0; j < graphNodeItems.length; ++j) {
const group = graph[node][graphNodeItems[j]];
groups[group] = groups[group] || [];
for (var k = 0, kl = groups[group].length; k < kl; ++k) {
for (let k = 0; k < groups[group].length; ++k) {

@@ -155,9 +155,9 @@ expandedGroups.push(groups[group][k]);

var afterNodes = Object.keys(graphAfters);
for (i = 0, il = afterNodes.length; i < il; ++i) {
group = afterNodes[i];
const afterNodes = Object.keys(graphAfters);
for (let i = 0; i < afterNodes.length; ++i) {
const group = afterNodes[i];
if (groups[group]) {
for (j = 0, jl = groups[group].length; j < jl; ++j) {
node = groups[group][j];
for (let j = 0; j < groups[group].length; ++j) {
const node = groups[group][j];
graph[node] = graph[node].concat(graphAfters[group]);

@@ -170,10 +170,10 @@ }

var children;
var ancestors = {};
let children;
const ancestors = {};
graphNodes = Object.keys(graph);
for (i = 0, il = graphNodes.length; i < il; ++i) {
node = graphNodes[i];
for (let i = 0; i < graphNodes.length; ++i) {
const node = graphNodes[i];
children = graph[node];
for (j = 0, jl = children.length; j < jl; ++j) {
for (let j = 0; j < children.length; ++j) {
ancestors[children[j]] = (ancestors[children[j]] || []).concat(node);

@@ -185,11 +185,11 @@ }

var visited = {};
var sorted = [];
const visited = {};
const sorted = [];
for (i = 0, il = this._items.length; i < il; ++i) {
var next = i;
for (let i = 0; i < this._items.length; ++i) {
let next = i;
if (ancestors[i]) {
next = null;
for (j = 0, jl = this._items.length; j < jl; ++j) {
for (let j = 0; j < this._items.length; ++j) {
if (visited[j] === true) {

@@ -203,6 +203,6 @@ continue;

var shouldSeeCount = ancestors[j].length;
var seenCount = 0;
for (var l = 0, ll = shouldSeeCount; l < ll; ++l) {
if (sorted.indexOf(ancestors[j][l]) >= 0) {
const shouldSeeCount = ancestors[j].length;
let seenCount = 0;
for (let k = 0; k < shouldSeeCount; ++k) {
if (sorted.indexOf(ancestors[j][k]) >= 0) {
++seenCount;

@@ -230,13 +230,12 @@ }

var seqIndex = {};
for (i = 0, il = this._items.length; i < il; ++i) {
item = this._items[i];
const seqIndex = {};
for (let i = 0; i < this._items.length; ++i) {
const item = this._items[i];
seqIndex[item.seq] = item;
}
var sortedNodes = [];
this._items = sorted.map(function (value) {
const sortedNodes = [];
this._items = sorted.map((value) => {
var sortedItem = seqIndex[value];
const sortedItem = seqIndex[value];
sortedNodes.push(sortedItem.node);

@@ -243,0 +242,0 @@ return sortedItem;

{
"name": "topo",
"description": "Topological sorting with grouping support",
"version": "1.1.0",
"version": "2.0.0",
"repository": "git://github.com/hapijs/topo",

@@ -14,10 +14,10 @@ "main": "lib/index.js",

"engines": {
"node": ">=0.10.40"
"node": ">=4.0.0"
},
"dependencies": {
"hoek": "2.x.x"
"hoek": "3.x.x"
},
"devDependencies": {
"lab": "6.x.x",
"code": "1.x.x"
"code": "2.x.x",
"lab": "7.x.x"
},

@@ -24,0 +24,0 @@ "scripts": {

@@ -0,7 +1,9 @@

'use strict';
// Load modules
var Code = require('code');
var Lab = require('lab');
var Hoek = require('hoek');
var Topo = require('..');
const Code = require('code');
const Lab = require('lab');
const Hoek = require('hoek');
const Topo = require('..');

@@ -11,3 +13,3 @@

var internals = {};
const internals = {};

@@ -17,16 +19,16 @@

var lab = exports.lab = Lab.script();
var describe = lab.describe;
var it = lab.it;
var expect = Code.expect;
const lab = exports.lab = Lab.script();
const describe = lab.describe;
const it = lab.it;
const expect = Code.expect;
describe('Topo', function () {
describe('Topo', () => {
var testDeps = function (scenario) {
const testDeps = function (scenario) {
var topo = new Topo();
scenario.forEach(function (record, i) {
const topo = new Topo();
scenario.forEach((record, i) => {
var options = record.before || record.after || record.group ? { before: record.before, after: record.after, group: record.group } : null;
const options = record.before || record.after || record.group ? { before: record.before, after: record.after, group: record.group } : null;
topo.add(record.id, options);

@@ -38,5 +40,5 @@ });

it('sorts dependencies', function (done) {
it('sorts dependencies', (done) => {
var scenario = [
const scenario = [
{ id: '0', before: 'a' },

@@ -58,5 +60,5 @@ { id: '1', after: 'f', group: 'a' },

it('sorts dependencies (before as array)', function (done) {
it('sorts dependencies (before as array)', (done) => {
var scenario = [
const scenario = [
{ id: '0', group: 'a' },

@@ -71,5 +73,5 @@ { id: '1', group: 'b' },

it('sorts dependencies (after as array)', function (done) {
it('sorts dependencies (after as array)', (done) => {
var scenario = [
const scenario = [
{ id: '0', after: ['a', 'b'] },

@@ -85,5 +87,5 @@ { id: '1', group: 'a' },

it('sorts dependencies (seq)', function (done) {
it('sorts dependencies (seq)', (done) => {
var scenario = [
const scenario = [
{ id: '0' },

@@ -99,16 +101,16 @@ { id: '1' },

it('sorts dependencies (explicitly using after or before)', function (done) {
it('sorts dependencies (explicitly using after or before)', (done) => {
var set = '0123456789abcdefghijklmnopqrstuvwxyz';
var groups = set.split('');
const set = '0123456789abcdefghijklmnopqrstuvwxyz';
const groups = set.split('');
// Use Fisher-Yates for shuffling
var fisherYates = function (array) {
const fisherYates = function (array) {
var i = array.length;
let i = array.length;
while (--i) {
var j = Math.floor(Math.random() * (i + 1));
var tempi = array[i];
var tempj = array[j];
const j = Math.floor(Math.random() * (i + 1));
const tempi = array[i];
const tempj = array[j];
array[i] = tempj;

@@ -119,13 +121,13 @@ array[j] = tempi;

var scenarioAfter = [];
var scenarioBefore = [];
for (var i = 0, il = groups.length; i < il; ++i) {
var item = {
const scenarioAfter = [];
const scenarioBefore = [];
for (let i = 0; i < groups.length; ++i) {
const item = {
id: groups[i],
group: groups[i]
};
var afterMod = {
const afterMod = {
after: i ? groups.slice(0, i) : []
};
var beforeMod = {
const beforeMod = {
before: groups.slice(i + 1)

@@ -146,5 +148,5 @@ };

it('throws on circular dependency', function (done) {
it('throws on circular dependency', (done) => {
var scenario = [
const scenario = [
{ id: '0', before: 'a', group: 'b' },

@@ -155,3 +157,3 @@ { id: '1', before: 'c', group: 'a' },

expect(function () {
expect(() => {

@@ -164,7 +166,7 @@ testDeps(scenario);

describe('merge()', function () {
describe('merge()', () => {
it('merges objects', function (done) {
it('merges objects', (done) => {
var topo = new Topo();
const topo = new Topo();
topo.add('0', { before: 'a' });

@@ -177,3 +179,3 @@ topo.add('2', { before: 'a' });

var other = new Topo();
const other = new Topo();
other.add('1', { after: 'f', group: 'a' });

@@ -191,5 +193,5 @@ other.add('3', { before: ['b', 'c'], group: 'a' });

it('merges objects (explicit sort)', function (done) {
it('merges objects (explicit sort)', (done) => {
var topo = new Topo();
const topo = new Topo();
topo.add('0', { before: 'a', sort: 1 });

@@ -202,3 +204,3 @@ topo.add('2', { before: 'a', sort: 2 });

var other = new Topo();
const other = new Topo();
other.add('1', { after: 'f', group: 'a', sort: 6 });

@@ -216,5 +218,5 @@ other.add('3', { before: ['b', 'c'], group: 'a', sort: 7 });

it('merges objects (mixed sort)', function (done) {
it('merges objects (mixed sort)', (done) => {
var topo = new Topo();
const topo = new Topo();
topo.add('0', { before: 'a', sort: 1 });

@@ -227,3 +229,3 @@ topo.add('2', { before: 'a', sort: 3 });

var other = new Topo();
const other = new Topo();
other.add('1', { after: 'f', group: 'a', sort: 2 });

@@ -241,5 +243,5 @@ other.add('3', { before: ['b', 'c'], group: 'a', sort: 4 });

it('merges objects (multiple)', function (done) {
it('merges objects (multiple)', (done) => {
var topo1 = new Topo();
const topo1 = new Topo();
topo1.add('0', { before: 'a', sort: 1 });

@@ -249,7 +251,7 @@ topo1.add('2', { before: 'a', sort: 3 });

var topo2 = new Topo();
const topo2 = new Topo();
topo2.add('6', { group: 'd', sort: 7 });
topo2.add('8', { before: 'd', sort: 9 });
var other = new Topo();
const other = new Topo();
other.add('1', { after: 'f', group: 'a', sort: 2 });

@@ -267,12 +269,12 @@ other.add('3', { before: ['b', 'c'], group: 'a', sort: 4 });

it('throws on circular dependency', function (done) {
it('throws on circular dependency', (done) => {
var topo = new Topo();
const topo = new Topo();
topo.add('0', { before: 'a', group: 'b' });
topo.add('1', { before: 'c', group: 'a' });
var other = new Topo();
const other = new Topo();
other.add('2', { before: 'b', group: 'c' });
expect(function () {
expect(() => {

@@ -279,0 +281,0 @@ topo.merge(other);

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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