JSPM

@koenbrouwer/find-path-by-value

1.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1
  • Score
    100M100P100Q14524F
  • License MIT

A little NodeJS package with a single function that returns the path inside a haystack object where a needle as value was found.

Package Exports

  • @koenbrouwer/find-path-by-value

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@koenbrouwer/find-path-by-value) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

🙋‍♂️ Made by @koenbrouwer.


Welcome to find-path-by-value 👋

Version

This package contains a single function that returns the path inside a haystack object where a needle as value was found.

This is a Node.js package available through the npm registry.
You can install find-path-by-value with the npm install command.

Install

npm install --save @koenbrouwer/find-path-by-value

Usage

It's really straight forward, you will need a JS(ON) object as the haystack and a string as the needle, findPathByValue will find the path(s) in the haystack where the needle was found:

const data = {
    rootBad: "bad",
    level0: {
        whatever: "good",
        bad: "bad",
        level1: {
            good: "good",
            bad: "bad",
            some: {
                good: "good",
                other: {
                    good: "good",
                    deep: {
                        good: "good",
                        nested: {
                            key: {
                                that: {
                                    isBad: "bad",
                                },
                            },
                        },
                    },
                },
            },
        },
    },
};

const paths = findPathsByValue(haystack, needle);

The result of paths is:

[
    'rootBad',
    'level0.bad',
    'level0.level1.bad',
    'level0.level1.some.other.deep.nested.key.that.isBad'
]

Author

👤 Koen Brouwer

🤝 Contributing

Feel free to open an issue on the issues page or a pull request in the repo on GitHub!

Show your support

Give a ⭐️ if this project helped you!

License

MIT

Contributions, issues and feature requests are welcome!