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

@ones-design/utils

Package Overview
Dependencies
Maintainers
0
Versions
35
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ones-design/utils

ONES Design

  • 1.11.0-beta.2
  • npm
  • Socket score

Version published
Weekly downloads
341
decreased by-3.94%
Maintainers
0
Weekly downloads
 
Created
Source

import { Meta } from '@storybook/blocks'

Utils

在 ONES Design 中,工具函数是独立维护的。在使用它们之前,你需要先进行安装:

npm install @ones-design/utils

Array 数组

moveNode

移动列表节点的位置,返回更新后的新数组。

function moveNode<NodeType extends Record<string, any>>(
  nodes: NodeType[],
  source: number | string,
  target: number | string,
): NodeType[]
Params
参数说明
nodes节点数组
source原位置
target目标位置

moveTreeNode

移动树节点的位置,返回更新后的新数组。

function moveTreeNode<NodeType extends Record<string, any>>(
  nodes: NodeType[],
  source: number | string | (number | string)[],
  target: number | string | (number | string)[],
  pos: -1 | 0 | 1,
  childrenName?: string,
): NodeType[]
Params
参数说明默认值
nodes节点数组
source原位置
target目标位置
pos相对目标的位置,-1 为上面,0 为里面,1 为下面
childrenName存放子节点的字段名'children'

insertTreeNode

在指定位置插入节点,返回更新后的新数组。

function insertTreeNode<NodeType extends Record<string, any>>(
  nodes: NodeType[],
  target: number | string | (number | string)[],
  node: NodeType,
  pos: -1 | 0 | 1,
  childrenName?: string,
): NodeType[]
Params
参数说明默认值
nodes节点数组
target目标位置
node要插入的节点
pos相对目标的位置,-1 为上面,0 为里面,1 为下面
childrenName存放子节点的字段名'children'

removeTreeNode

移除指定位置的节点,返回移除的节点和更新后的新数组。

function removeTreeNode<NodeType extends Record<string, any>>(
  nodes: NodeType[],
  pos: number | string | (number | string)[],
  childrenName?: string,
): {
  node: NodeType | null
  nodes: NodeType[]
}
Params
参数说明默认值
nodes节点数组
pos节点位置
childrenName存放子节点的字段名'children'

getTreeNode

获取指定位置的节点。

function getTreeNode<NodeType extends Record<string, any>>(
  nodes: NodeType[],
  pos: number | string | (number | string)[],
  childrenName?: string,
): NodeType | null
Params
参数说明默认值
nodes节点数组
pos节点位置
childrenName存放子节点的字段名'children'

Keywords

FAQs

Package last updated on 02 Sep 2024

Did you know?

Socket

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.

Install

Related posts

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