G
YouTube TikTok Games
Skip to content

About

Create a tree hierarchy from an array using paths/urls

Topics

Resources

Stars

2 stars

Watchers

1 watching

Forks

Latest commit

 

History

28 Commits

Folders and files

Repository files navigation

Urlploader

Converts back and forth flat arrays to and from tree structured arrays. It uses the urls to establish the tree structure and hierarchy.

Build Status

Installation

npm install urlploader

Usage

var urlPloader = require('urlploader');
var up = new urlPloader(options);

var flatArray = up.toFlat(myTree);
var treeArray = up.toTree(flatArray);

Options

var options = {
    subItemsKey: 'items',
    urlKey : 'uri',
    ignoreProtocol: true
}
  • subItemsKey
    default pages
    type string
    The key name which identifies sub items
  • urlKey
    default url
    type string
    The key name which identifies the url
  • ignoreProtocol
    default false
    type boolean
    If true, http, https, //, of urls will be ignored

Data-example

Converts this flat array...

[
  {
    "url": "mydomain.com/blog",
    "title": "Blog"
  },
  {
    "url": "mydomain.com/contact",
    "title": "Contact"
  },
  {
    "url": "mydomain.com/info/sub",
    "data": {
      "key": "value1"
    }
  },
  {
    "url": "mydomain.com/info",
    "title": "Info"
  },
  {
    "url": "mydomain.com",
    "title": "my start page"
  }
]

...to a tree:

[{
  "pages": [
    {
      "url": "mydomain.com",
      "title": "my start page",
      "pages": [
        {
          "url": "mydomain.com/blog",
          "title": "Blog"
        },
        {
          "url": "mydomain.com/contact",
          "title": "Contact"
        },
        {
          "url": "mydomain.com/info",
          "title": "Info",
          "pages": [
            {
              "url": "mydomain.com/info/sub",
              "data": {
                "key": "value1"
              }
            }
          ]
        }
      ]
    }
  ]
}]

About

Create a tree hierarchy from an array using paths/urls

Topics

Resources

Stars

2 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages