
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
lm-react-tools
Advanced tools
一个集合了高质量 React 组件、实用 Hook 和工具方法的工具库。
🌐 官网地址: https://gongliming-qd.github.io/lm-react-tools
# 使用 npm
npm install lm-react-tools
# 使用 yarn
yarn add lm-react-tools
# 使用 pnpm
pnpm add lm-react-tools
treeUtils 是一个功能强大的树形结构操作工具集,提供完整的树形数据遍历、查找、删除、层级调整等功能。该工具集专为处理复杂的树形数据结构而设计,支持各种树形操作场景。
核心功能特性:
主要方法详解:
completeTreeFunc - 树形结构遍历函数
nodeInfo 包含以下属性:
node - 当前节点对象floor - 层级路径数组(从 1 开始)parentIndex - 父节点索引路径数组(从 0 开始)leaf - 是否为叶子节点parentNodes - 父节点链数组nearestNode - 最近节点(前一个兄弟节点或父节点)getTreeIdInfo - 根据节点 ID 获取节点详细信息
removeTreeNodeById - 根据节点 ID 删除指定节点
promoteTreeNodeById - 提升节点层级(上移)
demoteTreeNodeById - 降低节点层级(下移)
使用场景:
注意事项:
import { completeTreeFunc } from 'lm-react-tools';
const treeData = [
{
id: '1',
name: '节点1',
children: [
{ id: '1-1', name: '节点1-1' },
{ id: '1-2', name: '节点1-2' },
],
},
{
id: '2',
name: '节点2',
children: [{ id: '2-1', name: '节点2-1' }],
},
];
// 遍历所有节点并打印信息
completeTreeFunc(treeData, (nodeInfo) => {
console.log(`节点ID: ${nodeInfo.node.id}, 层级: ${nodeInfo.floor.join('-')}`);
});
import { getTreeIdInfo } from 'lm-react-tools';
const treeData = [
{
id: '1',
name: '根节点',
children: [
{ id: '1-1', name: '子节点1' },
{ id: '1-2', name: '子节点2' },
],
},
];
// 查找指定ID的节点信息
const nodeInfo = getTreeIdInfo({ treeData, id: '1-1' });
if (nodeInfo) {
console.log('找到节点:', nodeInfo.node.name);
console.log('层级路径:', nodeInfo.floor);
console.log('是否是叶子节点:', nodeInfo.leaf);
}
import { removeTreeNodeById } from 'lm-react-tools';
const treeData = [
{
id: '1',
name: '父节点',
children: [
{ id: '1-1', name: '子节点1' },
{ id: '1-2', name: '子节点2' },
{ id: '1-3', name: '子节点3' },
],
},
];
// 删除指定ID的节点
const result = removeTreeNodeById({ treeData, id: '1-2' }, { clone: true });
if (result.success) {
console.log('删除成功');
console.log('删除后的树结构:', result.treeData);
console.log('最近节点:', result.nearestNode?.name);
}
import { promoteTreeNodeById } from 'lm-react-tools';
const treeData = [
{
id: '1',
name: '祖父节点',
children: [
{
id: '1-1',
name: '父节点',
children: [
{ id: '1-1-1', name: '子节点1' },
{ id: '1-1-2', name: '子节点2' },
{ id: '1-1-3', name: '子节点3' },
],
},
],
},
];
// 提升子节点2的层级
const result = promoteTreeNodeById({ treeData, id: '1-1-2' }, { clone: true });
if (result.success) {
console.log(result.message);
console.log('提升后的树结构:', result.treeData);
}
import { demoteTreeNodeById } from 'lm-react-tools';
const treeData = [
{
id: '1',
name: '父节点',
children: [
{ id: '1-1', name: '子节点1' },
{ id: '1-2', name: '子节点2' },
{ id: '1-3', name: '子节点3' },
],
},
];
// 降级子节点2的层级
const result = demoteTreeNodeById({ treeData, id: '1-2' }, { clone: true });
if (result.success) {
console.log(result.message);
console.log('降级后的树结构:', result.treeData);
}
import React, { useState } from 'react';
import { getTreeIdInfo, removeTreeNodeById } from 'lm-react-tools';
const TreeDemo = () => {
const [treeData, setTreeData] = useState([
{
id: '1',
name: '根节点',
children: [
{ id: '1-1', name: '子节点1' },
{ id: '1-2', name: '子节点2' },
],
},
]);
const handleDelete = (id) => {
const result = removeTreeNodeById({ treeData, id }, { clone: true });
if (result.success) {
setTreeData(result.treeData);
}
};
return (
<div>
{treeData.map((node) => (
<div key={node.id}>
<span>{node.name}</span>
<button onClick={() => handleDelete(node.id)}>删除</button>
{node.children?.map((child) => (
<div key={child.id} style={{ marginLeft: '20px' }}>
<span>{child.name}</span>
<button onClick={() => handleDelete(child.id)}>删除</button>
</div>
))}
</div>
))}
</div>
);
};
export default TreeDemo;
如有问题,请通过以下方式联系:
FAQs
集合组件、hook、公共方法于一身的工具集合
The npm package lm-react-tools receives a total of 4 weekly downloads. As such, lm-react-tools popularity was classified as not popular.
We found that lm-react-tools demonstrated a healthy version release cadence and project activity because the last version was released less than 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
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.