Tree.

addNextPrevious(map)

Given a map-like object, addNextPrevious returns a new object extending the map’s values with nextKey and previousKey properties. These properties will indicate the keys of the next and previous entries in the tree. This information can then be used to, for example, add links below a blog post that take the reader to the next or previous post.

Example application of addNextPrevious to a map of strings:

$ cat letters.yaml
a: The letter A
b: The letter B
c: The letter C
$ ori Tree.addNextPrevious letters.yaml
a:
  value: The letter A
  nextKey: b
b:
  value: The letter B
  nextKey: c
  previousKey: a
c:
  value: The letter C
  previousKey: b
g a The letter A ->a a b The letter B ->b b c The letter C ->c c
g a ->a a b ->b b c ->c c a/value The letter A a->a/value value a/nextKey b a->a/nextKey nextKey b/value The letter B b->b/value value b/nextKey c b->b/nextKey nextKey b/previousKey a b->b/previousKey previousKey c/value The letter C c->c/value value c/previousKey b c->c/previousKey previousKey
Input map
Result of addNextPrevious

If the values in the given tree aren’t objects, they will be transformed to plain objects as follows:

  • A value which is a map-like will be resolved to a plain object.
  • Any other value (e.g., a string) will become a plain object with a value property containing the value.

See also paginate, which groups a set of items into fixed-size pages.