URI.js icon indicating copy to clipboard operation
URI.js copied to clipboard

[Feature request] Support for nested objects inside template builder.

Open sunnysonx opened this issue 5 years ago • 0 comments

Feature request

Please describe your feature request

Add support for nested objects inside the template builder.

Example

let page = {
    "id": "1",
    "page_title": "My test page",
    "page_body": "some text here",
    "page_slug":"my-test-page",
    "menu_item":{
        "name":"Homepage",
        "slug":"homepage"
    }
}

let template = new URITemplate("http://example.org/{menu_item.slug}/{page_slug}");
let result = template.expand(page);

// result = http://example.org/homepage/my-test-page

Why is it needed?

  • Because it's nice to have such a feature, simplifies things.
  • Avoids the necessity to manually expand the template and allows you to directly provide the object.

Suggested solution(s)

  • A solution would be to use the same approach as lodash uses for get() https://lodash.com/docs/4.17.15#get, as it returns the value based on the path, for current example, _.get(page,'menu_item.slug') will return the homepage

sunnysonx avatar Jan 07 '21 09:01 sunnysonx