Skip to content

Commit

Permalink
docs: Updateed the readme
Browse files Browse the repository at this point in the history
  • Loading branch information
JosephVoid committed Dec 18, 2023
1 parent 9bde68f commit a16ab21
Showing 1 changed file with 41 additions and 27 deletions.
68 changes: 41 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,45 +8,57 @@ import {JsonItemSelector} from "json-item-selector";
// CommonJS
const {JsonItemSelector} = require("json-item-selector");
const json = {
"galaxy": {
"milky-way": {
"earth": [
"africa",
"asia",
"aurope",
],
"venus": [
"valnaes",
],
},
"andromeda": {
"pegasus":[],
"cassopia":[]
}
const galaxy = {
// Depth: 0
"milky-way": {
// Depth: 1
"earth": [
// Depth: 2
"africa",
"asia",
"aurope",
],
// Depth: 1
"venus": [
// Depth: 2
"valnaes",
],
},
// Depth: 0
"andromeda": {
// Depth: 1
"pegasus":[
// Depth: 2
"perg",
"gaort"
],
// Depth: 1
"cassopia":[
// Depth: 2
'epian',
'siltron'
]
}
}
const JIS = new JsonItemSelector(json);
const JIS = new JsonItemSelector(galaxy);
console.log(JIS.list_no_depth()); // ["galaxy"]
console.log(JIS.list(0)); // ["milky-way", "andromeda"] --> List options at 0 depth
JIS.select_no_depth("galaxy"); // returns true if successful
JIS.select("milky-way", 0); // --> Selects from options at 0 depth
console.log(JIS.list_no_depth()); // ["milky-way", "andromeda"]
console.log(JIS.list(1)); // ["earth", "venus"] --> List options at depth 1
JIS.select_no_depth("milky-way");
JIS.select("earth", 1); // --> Selects from options at depth 1
console.log(JIS.list_no_depth()); // ["earth", "venus"]
console.log(JIS.list(2)); // ["africa", "asia", "europe"]
JIS.select_no_depth("earth");
console.log(JIS.list_no_depth()); // ["africa", "asia", "europe"]
console.log(JIS.get_all_selected()); // ["galaxy", "milky-way", "earth"]
JIS.select("africa", 2);
console.log(JIS.get_all_selected()); // ["milky-way", "earth", "africa"]
```
[CodePen Example](https://codepen.io/Yoseph-Tenaw/pen/GRzVZzO)

# Installation
```
Expand All @@ -56,6 +68,8 @@ npm install json-item-selector
# Methods
| Name | Description | Params | Defaults | Returns |
| ------ | ------ | ------ | ------ | ------ |
| list | List all the possible options to select at a given depth in the object | `depth: number` | | `string []` |
| select | Choose from the available options from the given depth | `option: string` `deny_repeats?: boolean` `depth: number` | `deny_repeats: false`| `boolean` |
| list_no_depth | List all the possible options to select, starting from the first level/ highest depth | - | | `string []` |
| select_no_depth | Choose from the available options from the current level/depth, after selecting the next list of option will go to the next level/depth of properties | `option: string` `deny_repeats?: boolean` | `deny_repeats: false`| `boolean` |
| get_all_selected | Lists all the options selected so far | - | | `string []` |
Expand Down

0 comments on commit a16ab21

Please sign in to comment.