Security News
The Push to Ban Ransom Payments Is Gaining Momentum
Ransomware costs victims an estimated $30 billion per year and has gotten so out of control that global support for banning payments is gaining momentum.
@fsdk/tree-utils
Advanced tools
Readme
A set of utility functions frequently used while working with tree-like structures
Thare are 2 tree generation utility functions here:
generateTree
- Helper function. Provided with options, it returns flat array of tree items. Works on top of the generator.treeGenerator
- Generator function. Provided with options, allows to generate random tree, yielding each tree item.Usage Example:
itemCreator
- Both generateTree
and treeGenerator
rely on creator function used to generate particular tree item.
import { defaultItemCreatorFactory, TreeItemMeta } from '@fsdk/tree-utils';
import { nanoid } from 'nanoid'
type FlatTreeItem = {
id: string;
parentId?: string;
name: string;
depth: number;
}
const flatItemCreator = (parent: FlatTreeItem | undefined, meta: TreeItemMeta) => ({
id: nanoid(),
parentId: parent?.id,
name: `Item ${id}`,
depth: meta.level,
});
type NestedTreeItem = {
id: string;
children: NestedTreeItem[];
}
const nestedItemCreator = (parent: NestedTreeItem | undefined, meta: TreeItemMeta) => {
const item: NestedTreeItem = {
id: nanoid(),
children: [],
};
parent?.children.push(item);
return item;
};
// alternatively you can use built-in item creator factory to produce `flatItemCreator` above
const itemCreator = defaultItemCreatorFactory();
generateTree
:
import { generateTree } from '@fsdk/tree-utils';
const treeItems = generateTree({
itemCreator, // Required. Provides function used to create tree item object
maxDepth: 5, // Optional. Provides maximum depth of the randomly generated tree. Defults to 10
minSiblings: 2, // Optional. Provides minimum nested items count used by randomzier. Defaults to 3
maxSiblings: 15, // Optional. Provides maximum nested items count used by randomizer. Defaults to 7
maxItems: 1000, // Optional. Limits total items generated in case generation exceeds specified distribution. Defaults to 1000
});
// if you use nested tree object structure it is handy to get `root` as all other items are accessible via children property
const [root] = generateTree({
itemCreator: nestedItemCreator,
});
treeGenerator
:
import { treeGenerator } from '@fsdk/tree-utils';
const generator = treeGenerator({
itemCreator, // Required. Provides function used to create tree item object
maxDepth: 10, // Required. Provides maximum depth of the randomly generated tree.
minSiblings: 3, // Required. Provides minimum nested items count used by randomzier.
maxSiblings: 7, // Required. Provides maximum nested items count used by randomizer.
});
// Start generate items by calling `next`
const treeItem = generator.next().value;
FAQs
Utilities for tree-like structures
We found that @fsdk/tree-utils demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Ransomware costs victims an estimated $30 billion per year and has gotten so out of control that global support for banning payments is gaining momentum.
Application Security
New SEC disclosure rules aim to enforce timely cyber incident reporting, but fear of job loss and inadequate resources lead to significant underreporting.
Security News
The Python Software Foundation has secured a 5-year sponsorship from Fastly that supports PSF's activities and events, most notably the security and reliability of the Python Package Index (PyPI).