nd-point
Find the points objects should occupy in an n-dimensional array.
Example
var Point =var point = Point'division''level''style'// [0,0,0]// [0,1,0]// [1,0,0]// [0,2,1]
Usage
var point = Point(properties, options={})
Returns a new point
function that takes json objects as input and returns the
point path (an array of integers) based on the object's properties.
How it works
With a new point
function, the first time a value is seen for a property, it
is assigned the next consecutive integer for that property. Properties are added
to the point path in the order they were passed in.
var point = Point'division''level''style'// for the first doc, all properties are making their first appearance.// [0,0,0]// 'intermediate' is a new level// [0,1,0]// '' (empty) is a new level// [0,2,0]
Notes
You can use sortable-object-hash
to order objects based on their properties before assigning them an nd-point
.
What can I use this for?
For interface elements that are represented nicely as a multidimensional array,
you can find which node an element belongs in via its point path. nd-point
allows you to find an object's n-dimensional point based on an its properties.
page
└─┬ tabbed-pane [0]
├─┬ table [0,0]
│ ├─┬ row [0,0,0]
│ │ ├── column [0,0,0,0]
│ │ └── column [0,0,0,1]
│ └─┬ row [0,0,1]
│ └── column [0,0,1,0]
├ tabbed-pane [1]
└─┬ table [1,0]
├─┬ row [1,0,0]
│ └── column [1,0,0,0]
├─┬ row [1,0,1]
│ └── column [1,0,1,0]
├ table [1,1]
└─┬ row [1,1,0]
└── column [1,1,0,0]
License
MIT