Skip to content

wapitea/telepath

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Telepath

Master status

Official documentation: hexdocs.

Installation

Add the following lib to your mix.exs.

def deps do
  [
    {:telepath, "~> 0.1.0"}
  ]
end

Quickstart

Telepath allows you to easily reach data from any elixir struct given a path (like you do in jsonpath or xpath).

Importing Telepath allows you to use the sigil ~t to generate the struct path.

e.g.

~t/hello.world[0]/
# ["hello", "world", 0]

With the a modifier, you can exctract atoms instead of strings.

e.g.

~t/hello.world[0]/a
# [:hello, :world, 0]

When your struct path is generated, you can use the &Telepath.get/2 function to access the data.

e.g.

import Telepath # for `~t` sigil

data = %{
   node: [%{attr: "value"}, %{attr: "value"}]
}

Telepath.get(data, ~t/node/a)
# [%{node: "value"}, %{node: "value}]

Telepath.get(data, ~t/node.attr/a)
# ["value", "value"]

Telepath.get(data, ~t/node[0]/a)
# %{node: "value"}

Telepath.get(data, ~t/node[0].attr/a)
# "value"

Telepath.get(%{"string_key" => "value"}, ~t/string_key/)
# "value"

About

Telepath is the xPath/JsonPath of elixir's struct

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages