Socket
Socket
Sign inDemoInstall

nd-point

Package Overview
Dependencies
0
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    nd-point

find the points objects should occupy in a multidimensional array


Version published
Maintainers
1
Install size
5.03 kB
Created

Readme

Source

nd-point build status

Find the points objects should occupy in an n-dimensional array.

testling badge

Example

var Point = require('nd-point')
var point = Point(['division','level','style'])

point({division: 'doubles', level: 'beginner', style: 'freestyle'}) // [0,0,0]
point({division: 'doubles', level: 'intermediate', style: 'freestyle'}) // [0,1,0]
point({division: 'singles', level: 'beginner', style: 'freestyle'}) // [1,0,0]
point({division: 'doubles', level: 'advanced', style: 'compulsory'}) // [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.
point({division: 'doubles', level: 'beginner', style: 'freestyle'})
// [0,0,0]

// 'intermediate' is a new level
point({division: 'doubles', level: 'intermediate', style: 'freestyle'})
// [0,1,0]

// '' (empty) is a new level
point({division: 'doubles', style: 'freestyle'})
// [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

Keywords

FAQs

Last updated on 18 Jul 2014

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc