Skip to content

Commit f9f4d00

Browse files
committed
Update docs and dependencies to version 2.1.14
1 parent bc9e9a2 commit f9f4d00

File tree

4 files changed

+121
-77
lines changed

4 files changed

+121
-77
lines changed

QWEN.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44

55
`flat-json-tree` is a TypeScript library that provides a simple way to manipulate JSON tree objects. The core idea is to transform a JSON tree object into a flat array, allowing standard array operations like `find`, `findIndex`, `filter`, `map`, and others. It's built as a Vue 3 composable function.
66

7-
The library is published as `@vuebro/flat-json-tree` with the current version being 2.1.12. It's designed to work with tree structures where each element has a unique identifier field.
8-
9-
The project follows the AGPL-3.0 license and is maintained by Jerry Bruwes.
7+
The library is published as `@vuebro/flat-json-tree` with the current version being 2.1.14. It's designed to work with tree structures where each element has a unique identifier field.
108

119
## Architecture and Implementation
1210

README.md

Lines changed: 41 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
# A dead simple way to manipulate JSON tree objects
1+
# flat-json-tree
22

3-
The core idea is to transform a JSON tree object into a flat array, allowing standard operations like find, findIndex, filter, map, and others.
3+
A dead simple way to manipulate JSON tree objects by transforming them into flat arrays for standard operations.
44

5-
A mandatory requirement for the algorithm is that each element in the JSON tree must have a field with a unique identifier.
5+
## Overview
6+
7+
The core idea is to transform a JSON tree object into a flat array, allowing standard operations like find, findIndex, filter, map, and others. A mandatory requirement for the algorithm is that each element in the JSON tree must have a field with a unique identifier.
68

79
To preserve the tree structure and enable manipulations, the following computed properties are added to each child object:
810

@@ -23,67 +25,45 @@ To preserve the tree structure and enable manipulations, the following computed
2325
}
2426
```
2527

26-
The transformation is performed using the `useFlatJsonTree` composable:
28+
## Installation
2729

28-
```ts
29-
function useFlatJsonTree(
30-
// The JSON tree object
31-
tree: Record<string, unknown>[],
32-
// Optional object to define alternative names for id, children, and computed properties
33-
{
34-
branch,
35-
children,
36-
id,
37-
index,
38-
next,
39-
parent,
40-
prev,
41-
siblings,
42-
}?: {
43-
branch?: string | undefined;
44-
children?: string | undefined;
45-
id?: string | undefined;
46-
index?: string | undefined;
47-
next?: string | undefined;
48-
parent?: string | undefined;
49-
prev?: string | undefined;
50-
siblings?: string | undefined;
51-
},
52-
);
30+
```bash
31+
npm i @vuebro/flat-json-tree
5332
```
5433

55-
The composable returns an object with the following properties:
34+
## API
5635

57-
```ts
58-
{
59-
// Computed flat array of objects (access via .value)
60-
nodes: ComputedRef<Record<string, unknown>[]>;
61-
// Reactive object with unique IDs as keys
62-
nodesMap: ComputedRef<{[id: string]: Record<string, unknown>;}>;
63-
// Service function to add an empty object to the siblings
64-
add: (pId: string) => string | undefined;
65-
// Service function to add an empty object to the children
66-
addChild: (pId: string) => string | undefined;
67-
// Service function to remove an object from the tree
68-
remove: (pId: string) => string | undefined;
69-
// Service function to move an object down by one position
70-
down: (pId: string) => void;
71-
// Service function to move an object left by one position
72-
left: (pId: string) => string | undefined;
73-
// Service function to move an object right by one position
74-
right: (pId: string) => string | undefined;
75-
// Service function to move an object up by one position
76-
up: (pId: string) => void;
77-
}
78-
```
36+
### `useFlatJsonTree(tree, options?)`
7937

80-
## Installation
38+
The main composable function that transforms a JSON tree into a flat array with tree navigation properties.
8139

82-
```bash
40+
#### Parameters:
8341

84-
npm i @vuebro/flat-json-tree
42+
- `tree` (Required): `Record<string, unknown>[]` - The JSON tree object
43+
- `options` (Optional): Configuration object to define alternative names for id, children, and computed properties
44+
- `branch`: Property name for the branch path (default: "branch")
45+
- `children`: Property name for child nodes (default: "children")
46+
- `id`: Property name for unique identifiers (default: "id")
47+
- `index`: Property name for index in siblings (default: "index")
48+
- `next`: Property name for next sibling (default: "next")
49+
- `parent`: Property name for parent object (default: "parent")
50+
- `prev`: Property name for previous sibling (default: "prev")
51+
- `siblings`: Property name for siblings array (default: "siblings")
8552

86-
```
53+
#### Returns:
54+
55+
An object with the following properties:
56+
57+
- `nodes`: `ComputedRef<Record<string, unknown>[]>` - Computed flat array of objects
58+
- `nodesMap`: `ComputedRef<{[id: string]: Record<string, unknown>}>` - Reactive object with unique IDs as keys
59+
- Manipulation methods:
60+
- `add(pId: string)`: Add an empty object to the siblings
61+
- `addChild(pId: string)`: Add an empty object to the children
62+
- `remove(pId: string)`: Remove an object from the tree
63+
- `down(pId: string)`: Move an object down by one position
64+
- `left(pId: string)`: Move an object left by one position
65+
- `right(pId: string)`: Move an object right by one position
66+
- `up(pId: string)`: Move an object up by one position
8767

8868
## Usage
8969

@@ -93,9 +73,7 @@ Assume we have a tree structure with elements like:
9373
{ id: number, name: string, children: [] }
9474
```
9575

96-
> [!WARNING] <!-- eslint-disable-line -- This should be fixed in https://github.com/eslint/markdown/issues/294 -->
97-
>
98-
> Elements can contain arbitrary fields, but must have a unique identifier
76+
Elements can contain arbitrary fields, but must have a unique identifier.
9977

10078
### Example using `useFlatJsonTree` composable
10179

@@ -323,10 +301,8 @@ As a result, the objects named "1.2.5" and "1.2.6" have swapped positions:
323301
]
324302
```
325303

326-
> [!NOTE] <!-- eslint-disable-line -- This should be fixed in https://github.com/eslint/markdown/issues/294 -->
327-
>
328-
> <img src="https://vuebro.ru/images/drakkar.svg" alt="drakkar" width="250"/>
329-
>
330-
> Made on the shores of the Baltic Sea
304+
## License
305+
306+
This project is licensed under the AGPL-3.0-only license.
331307

332-
License: [AGPL](https://choosealicense.com/licenses/agpl-3.0)
308+
Made on the shores of the Baltic Sea 🚢

0 commit comments

Comments
 (0)