npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

json-item-selector

v1.1.3

Published

Selector of JSON items that used to be accessed recursivley

Downloads

3

Readme

json-item-selector

Tests

A package that allow you to create choice logic based on a json file. It helps with choice implementations which depend on an external json file and are heavily nested, mostly for use cases like location selection or game dialog mapping. A basic example below

// ESM
import {JsonItemSelector} from "json-item-selector";
// CommonJS
const {JsonItemSelector} = require("json-item-selector");


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(galaxy);

console.log(JIS.list(0)); // ["milky-way", "andromeda"] --> List options at 0 depth 

JIS.select("milky-way", 0); // --> Selects from options at 0 depth

console.log(JIS.list(1)); // ["earth", "venus"] --> List options at depth 1

JIS.select("earth", 1); // --> Selects from options at depth 1

console.log(JIS.list(2)); // ["africa", "asia", "europe"]

JIS.select("africa", 2);

console.log(JIS.get_all_selected()); // ["milky-way", "earth", "africa"]


CodePen Example

Installation

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 [] | | get_last_selected | Gets the last selected option | - | | string | | clear_last | Remove the last selected option and go back up a level/higher in depth | - | | boolean | | clear_all_selected | Remove all selection and return to the first level | - | | boolean |