UNPKG

js2flowchart

Version:

> Why? While I've been working on [Under-the-hood-ReactJS](https://github.com/Bogdan-Lyashenko/Under-the-hood-ReactJS) I spent enormous amount of time on creating schemes. Each change in code or flowchart affects all entire scheme instantly, forcing you t

51 lines (50 loc) 1.76 kB
import stringWidth from 'string-width'; export var generateId = function generateId() { return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { var r = Math.random() * 16 | 0, v = c === 'x' ? r : r & 0x3 | 0x8; return v.toString(16); }); }; export var getPathId = function getPathId(node) { var queue = [node]; var id = "node-id:|".concat(node.name, "|"); while (queue.length) { var item = queue.shift(); if (item) { id += item.name ? item.name[0] : '-'; if (item.parent) { queue.push(item.parent); } } } return id.replace(/\s/g, '').toUpperCase(); }; export var splitNameString = function splitNameString(str, maxLineLength, nameSplitterTokensIterator) { var strLength = str.length; if (strLength <= maxLineLength) return [str]; return [str.slice(0, maxLineLength) + '...']; //TODO: fix var parts = [], currentPositionIndex = 0, splitter = nameSplitterTokensIterator.getNext(); while (currentPositionIndex < strLength) { var splitterIndex = str.indexOf(splitter, currentPositionIndex); if (splitterIndex !== -1) { parts.push(str.slice(currentPositionIndex, splitterIndex + splitter.length)); currentPositionIndex += splitterIndex + splitter.length; } else { //TODO: try other splitters then //splitter = nameSplitterTokensIterator.getNext(), parts.push(str.slice(currentPositionIndex, str.length)); currentPositionIndex = str.length; } } return parts; }; export var getMaxStringLengthFromList = function getMaxStringLengthFromList(list) { return list.reduce(function (max, current) { var currentLength = stringWidth(current); return currentLength >= max ? currentLength : max; }, 0); };