GithubHelp home page GithubHelp logo

idanielbot / glob-json-path Goto Github PK

View Code? Open in Web Editor NEW

This project forked from anttiviljami/glob-json-path

0.0 0.0 0.0 548 KB

Bash-like globbing for JSON objects.

License: MIT License

TypeScript 100.00%

glob-json-path's Introduction

glob-json-path

CI npm version bundle size License Buy me a coffee

Bash-like globbing for JSON objects.

npm i glob-json-path
import { globValues, globPaths } from "glob-json-path";

globValues("a.b", { a: { b: 1 } }); // [1]
globValues("a.b.c", { a: { b: { c: 1 }}}); // [1]
globValues("a.b", { a: { b: { c: 1 }}}); // [{ c: 1 }]
globValues("a.*", { a: { b: 2, c: 3 }}}); // [2, 3]
globValues("a.*.c", { a: [{ b: 3, c: 4 }, { c: 5 }] }); // [4, 5]
globValues("**.c", { a: { c: 6, b: { c: 7 }}}); // [6, 7]
globValues("a*", { ab: 7, abc: 8, ba: 9, bc: 10 }); // [7, 8]
globValues("b?", { ab: 7, abc: 8, ba: 9, bc: 10 }); // [9, 10]

globPaths("a.*", { a: { b: 2, c: 3 }}); // ["a.b", "a.c"]
globPaths("a.*.c", { a: { b: { c: 3 }, { d: { c: 3 }}}}); // ["a.b.c", "a.d.c"]
globPaths("a.*.c", { a: [{ b: 3, c: 4 }, { c: 5 }] }); // ["a.0.c", "a.1.c"]
globPaths("**.c", { a: { c: 6, b: { c: 7 } } }); // ["a.c", "a.b.c"]
globPaths("a*", { ab: 7, abc: 8, ba: 9, bc: 10 }); // ["ab", "abc"]
globPaths("b?", { ab: 7, abc: 8, ba: 9, bc: 10 }); // ["ba", "bc"]

Features

  • Minimum number of dependencies. Tiny package size.
  • Return matching values or paths for bash-like globs
  • Support for wildcards *, ?
  • Support for double wildcards ** (globstar)
  • Support for arrays and all JSON primitives
  • Relies on glob-to-regexp package for converting globs to regex.

Examples

See tests for more use cases.

Contributing

glob-json-path is Free and Open Source Software. Issues and pull requests are more than welcome!

glob-json-path's People

Contributors

anttiviljami avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.