reorx
10/7/2016 - 8:31 AM

Showing how to write awesome JS API doc in GFM, copied from: https://github.com/rstacruz/nested-hamt/blob/master/API.md

Showing how to write awesome JS API doc in GFM, copied from: https://github.com/rstacruz/nested-hamt/blob/master/API.md

nested-hamt

set()

set(tree, keypath, val)Tree

ParamTypeDescription
treeTreeThe HAMT tree to operate on
keypathstring[]List of keys
val*Value to be set

Sets data into a HAMT tree.

The keypaths can be given as an array or a dot-separated string. This applies to get() and del() as well.

import { set, get, empty } from 'nested-hamt'

var tree = set(empty, 'user', { name: 'John' })
get(tree, 'user.name') // => 'John'
// Keypaths example
// Both are equivalent
var tree = set(empty, 'user.name', 'John')
var  = set(empty, ['user', 'name'], 'John')

get()

get(tree, keypath?)*

ParamTypeDescription
treeTreeThe HAMT tree to operate on
keypathstring[], optionalList of keys

Returns data from a HAMT store. If keypath is not given, it returns the entire store as a JSON object. Returns the value in the given keypath.

del()

del(tree)Tree

ParamTypeDescription
treeTreeThe HAMT tree to operate on

Deletes from a given keypath. Returns the resulting HAMT tree.

keys()

keys(tree)string[]

ParamTypeDescription
treeTreeThe HAMT tree to operate on

Returns keys in a given HAMT tree. Returns a list of keys.

fromJS()

fromJS(data)Tree | *

ParamTypeDescription
dataobject*The JSON data to be set

Converts a JSON tree into a HAMT tree. If the given data isn't an object, it'll be returned as is. Inverse of toJS(). Returns the resulting HAMT tree.

toJS()

toJS(tree)object | *

ParamTypeDescription
treeTree*The HAMT tree

Converts a HAMT tree to a JSON object. If the given tree is not a HAMT tree, it'll be returned as is. Inverse of fromJS(). Returns the resulting object.

extend()

extend(tree)Tree

ParamTypeDescription
treeTreeThe HAMT tree to operate on
...sourcesobjectObjects to extend the tree with

Extends a HAMT tree with data from objects. Returns the resulting HAMT tree.

isHamt()

isHamt(tree)boolean

ParamTypeDescription
treeTree*A HAMT tree or anything

Checks if a given data object is a HAMT object.

len()

len(tree)number

ParamTypeDescription
treeTreeThe HAMT tree to operate on

Returns the number of keys in a HAMT tree.

empty

empty

An empty HAMT tree.

import { set, get, empty } from 'nested-hamt'

var tree = set(empty, 'hello', 'world')
get(tree, 'hello') // => 'world'

Tree

{ type, mask, key?, value?, children }

ParamTypeDescription
typestring
masknumber
keystring, optional
value*, optional
childrenTree[]

A HAMT tree represents a nested JSON data structure, much like regular JSON. It's been optimized for faster updating times for larger trees.

To generate a HAMT tree, first start with empty and use operations on it like set(). You may also use fromJS() to create a HAMT tree from a JSON data structure.