2021-03-29 00:02:43 -07:00
# Path
`Path` arrays are a list of indexes that describe a node's exact position in a Slate node tree. Although they are usually relative to the root `Editor` object, they can be relative to any `Node` object.
```typescript
type Path = number[]
```
## Static methods
2021-03-29 23:34:11 -07:00
- [Retrieval methods ](#retrieval-methods )
2021-03-29 23:21:54 -07:00
- [Check methods ](#check-methods )
- [Transform method ](#transform-method )
2021-03-29 23:34:11 -07:00
### Retrieval methods
2021-03-29 23:21:54 -07:00
2021-03-29 00:20:34 -07:00
###### `Path.ancestors(path: Path, options: { reverse?: boolean } = {}): Path[]`
2021-03-29 00:02:43 -07:00
Get a list of ancestor paths for a given path.
The paths are sorted from deepest to shallowest ancestor. However, if the
`reverse: true` option is passed, they are reversed.
2021-03-29 00:20:34 -07:00
###### `Path.common(path: Path, another: Path): Path`
2021-03-29 00:02:43 -07:00
Get the common ancestor path of two paths.
2021-03-29 00:20:34 -07:00
###### `Path.compare(path: Path, another: Path): -1 | 0 | 1`
2021-03-29 00:02:43 -07:00
Compare a path to another, returning an integer indicating whether the path
was before, at, or after the other.
Note: Two paths of unequal length can still receive a `0` result if one is
directly above or below the other. If you want exact matching, use
[[Path.equals]] instead.
2021-03-29 23:21:54 -07:00
###### `Path.levels(path: Path, options?): Path[]`
Get a list of paths at every level down to a path. Note: this is the same
as `Path.ancestors` , but including the path itself.
The paths are sorted from shallowest to deepest. However, if the `reverse: true` option is passed, they are reversed.
Options: `{reverse?: boolean}`
###### `Path.next(path: Path): Path`
Given a path, get the path to the next sibling node.
###### `Path.parent(path: Path): Path`
Given a path, return a new path referring to the parent node above it.
###### `Path.previous(path: Path): Path`
Given a path, get the path to the previous sibling node.
###### `Path.relative(path: Path, ancestor: Path): Path`
Get a path relative to an ancestor.
### Check methods
Check some attribute of a path. Always returns a boolean.
2021-03-29 00:20:34 -07:00
###### `Path.endsAfter(path: Path, another: Path): boolean`
2021-03-29 00:02:43 -07:00
Check if a path ends after one of the indexes in another.
2021-03-29 00:20:34 -07:00
###### `Path.endsAt(path: Path, another: Path): boolean`
2021-03-29 00:02:43 -07:00
Check if a path ends at one of the indexes in another.
2021-03-29 00:20:34 -07:00
###### `Path.endsBefore(path: Path, another: Path): boolean`
2021-03-29 00:02:43 -07:00
Check if a path ends before one of the indexes in another.
2021-03-29 00:20:34 -07:00
###### `Path.equals(path: Path, another: Path): boolean`
2021-03-29 00:02:43 -07:00
Check if a path is exactly equal to another.
2021-03-29 00:20:34 -07:00
###### `Path.hasPrevious(path: Path): boolean`
2021-03-29 00:02:43 -07:00
Check if the path of previous sibling node exists
2021-03-29 00:20:34 -07:00
###### `Path.isAfter(path: Path, another: Path): boolean`
2021-03-29 00:02:43 -07:00
Check if a path is after another.
2021-03-29 00:20:34 -07:00
###### `Path.isAncestor(path: Path, another: Path): boolean`
2021-03-29 00:02:43 -07:00
Check if a path is an ancestor of another.
2021-03-29 00:20:34 -07:00
###### `Path.isBefore(path: Path, another: Path): boolean`
2021-03-29 00:02:43 -07:00
Check if a path is before another.
2021-03-29 00:20:34 -07:00
###### `Path.isChild(path: Path, another: Path): boolean`
2021-03-29 00:02:43 -07:00
Check if a path is a child of another.
2021-03-29 00:20:34 -07:00
###### `Path.isCommon(path: Path, another: Path): boolean`
2021-03-29 00:02:43 -07:00
Check if a path is equal to or an ancestor of another.
2021-03-29 00:20:34 -07:00
###### `Path.isDescendant(path: Path, another: Path): boolean`
2021-03-29 00:02:43 -07:00
Check if a path is a descendant of another.
2021-03-29 00:20:34 -07:00
###### `Path.isParent(path: Path, another: Path): boolean`
2021-03-29 00:02:43 -07:00
Check if a path is the parent of another.
2021-03-29 00:20:34 -07:00
###### `Path.isPath(value: any): value is Path`
2021-03-29 00:02:43 -07:00
Check is a value implements the `Path` interface.
2021-03-29 00:20:34 -07:00
###### `Path.isSibling(path: Path, another: Path): boolean`
2021-03-29 00:02:43 -07:00
Check if a path is a sibling of another.
2021-03-29 23:21:54 -07:00
### Transform method
2021-03-29 00:02:43 -07:00
2021-03-29 00:20:34 -07:00
###### `Path.transform(path: Path, operation: Operation, options?): Path | null`
2021-03-29 00:02:43 -07:00
Transform a path by an operation.
Options: `{ affinity?: 'forward' | 'backward' | null }`