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

data-sget

v1.0.3

Published

`sget` is a lightweight library that provides a convenient and intuitive way to extract values from complex nested data structures using a simplified syntax. With `sget`, you can easily navigate through deeply nested objects and arrays, apply conditional

Downloads

15

Readme

sget - Simplified Property Getter

sget is a lightweight library that provides a convenient and intuitive way to extract values from complex nested data structures using a simplified syntax. With sget, you can easily navigate through deeply nested objects and arrays, apply conditional operations, and retrieve values efficiently.

Key Features:

  • Navigate through nested objects and arrays using dot and bracket notation.
  • Apply conditional operators such as >, >=, <, <=, ==, and != to perform value comparisons.
  • Supports wildcard notation for flexible and dynamic property extraction.
  • Retrieve multiple properties from a data structure using sgetAll function.
  • Handle default values for cases where a property is undefined or inaccessible.

Whether you're working with deeply nested JSON structures, configuration objects, or any other complex data, sget simplifies the process of extracting specific values with a user-friendly syntax.

Installation

Install the library using your preferred package manager:

npm install data-sget

Syntax

Example data:

const data = {
    key: { level: 0, index: [0], str: '0' },
    children: [
        {
            key: { level: 1, index: [0, 0], str: '0.0' },
            children: [
                { key: { level: 2, index: [0, 0, 0], str: '0.0.0' }, children: [] },
                { key: { level: 2, index: [0, 0, 1], str: '0.0.1' }, children: [] },
                { key: { level: 2, index: [0, 0, 2], str: '0.0.2' }, children: [] },
                { key: { level: 2, index: [0, 0, 3], str: '0.0.3' }, children: [] },
                { key: { level: 2, index: [0, 0, 4], str: '0.0.4' }, children: [] }
            ]
        },
        {
            key: { level: 1, index: [0, 1], str: '0.1' },
            children: [
                { key: { level: 2, index: [0, 1, 0], str: '0.1.0' }, children: [] },
                { key: { level: 2, index: [0, 1, 1], str: '0.1.1' }, children: [] },
                { key: { level: 2, index: [0, 1, 2], str: '0.1.2' }, children: [] },
                { key: { level: 2, index: [0, 1, 3], str: '0.1.3' }, children: [] },
                { key: { level: 2, index: [0, 1, 4], str: '0.1.4' }, children: [] }
            ]
        },
        {
            key: { level: 1, index: [0, 2], str: '0.2' },
            children: [
                { key: { level: 2, index: [0, 2, 0], str: '0.2.0' }, children: [] },
                { key: { level: 2, index: [0, 2, 1], str: '0.2.1' }, children: [] },
                { key: { level: 2, index: [0, 2, 2], str: '0.2.2' }, children: [] },
                { key: { level: 2, index: [0, 2, 3], str: '0.2.3' }, children: [] },
                { key: { level: 2, index: [0, 2, 4], str: '0.2.4' }, children: [] }
            ]
        },
        {
            key: { level: 1, index: [0, 3], str: '0.3' },
            children: [
                { key: { level: 2, index: [0, 3, 0], str: '0.3.0' }, children: [] },
                { key: { level: 2, index: [0, 3, 1], str: '0.3.1' }, children: [] },
                { key: { level: 2, index: [0, 3, 2], str: '0.3.2' }, children: [] },
                { key: { level: 2, index: [0, 3, 3], str: '0.3.3' }, children: [] },
                { key: { level: 2, index: [0, 3, 4], str: '0.3.4' }, children: [] }
            ]
        },
        {
            key: { level: 1, index: [0, 4], str: '0.4' },
            children: [
                { key: { level: 2, index: [0, 4, 0], str: '0.4.0' }, children: [] },
                { key: { level: 2, index: [0, 4, 1], str: '0.4.1' }, children: [] },
                { key: { level: 2, index: [0, 4, 2], str: '0.4.2' }, children: [] },
                { key: { level: 2, index: [0, 4, 3], str: '0.4.3' }, children: [] },
                { key: { level: 2, index: [0, 4, 4], str: '0.4.4' }, children: [] }
            ]
        }
    ]
};

Query Examples and Results

You can utilize sget to retrieve data from nested structures in a concise manner. The following table demonstrates some query examples and their corresponding results:

const result = sget(data, query);
console.log(result);

| query | result | |------------------------------------------------------------------------|---------| | 'children.1.children.2.key.str' | '0.1.2' | | 'children[3].children[4].key.str' | '0.3.4' | | 'children..children..key.str' | '0.0.0' | | 'children[].children[].key.str' | '0.0.0' | | 'children[.key.str:0.2].key.str' | '0.2' | | 'children[.children[].key.str:0.3.4].children[.key.index.2:2].key.str' | '0.3.2' | | 'children[.key.index.1>3].key.str' | '0.4' | | 'children[.key.index.1>=3].key.str' | '0.3' | | 'children[.key.index.1>1][.key.index.1<3].key.str' | '0.2' |

Usage

Here are some examples of how to use the library:

import sget from 'data-sget';
import {sgetAll} from 'data-sget';

const data = {
    // ...
};

// Example usage of sget
const result1 = sget(data, 'children[.key.str:0.2].key.str');
console.log(result1); // Output: '0.2'

// Example usage of sgetAll
const spmap = {
    first: 'children[.children[].key.str:0.3.4].children[.key.index.2:2].key.str',
    second: 'children[.key.index.1>=3].key.str',
    third: 'children[.key.str:0.2].key.str'
};
const result2 = sgetAll(data, spmap);
console.log(result2.first); // Output: '0.3.2'
console.log(result2.second); // Output: '0.3'
console.log(result2.third); // Output: '0.2'

License

This project is licensed under the MIT License - see the LICENSE file for details.