Showing how to write awesome JS API doc in GFM, copied from: https://github.com/rstacruz/nested-hamt/blob/master/API.md
set(tree, keypath, val) → Tree
| Param | Type | Description |
|---|---|---|
tree | Tree | The HAMT tree to operate on |
keypath | string[] | 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(tree, keypath?) → *
| Param | Type | Description |
|---|---|---|
tree | Tree | The HAMT tree to operate on |
keypath | string[], optional | List 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(tree) → Tree
| Param | Type | Description |
|---|---|---|
tree | Tree | The HAMT tree to operate on |
Deletes from a given keypath. Returns the resulting HAMT tree.
keys(tree) → string[]
| Param | Type | Description |
|---|---|---|
tree | Tree | The HAMT tree to operate on |
Returns keys in a given HAMT tree. Returns a list of keys.
fromJS(data) → Tree | *
| Param | Type | Description | |
|---|---|---|---|
data | object | * | 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(tree) → object | *
| Param | Type | Description | |
|---|---|---|---|
tree | Tree | * | 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(tree) → Tree
| Param | Type | Description |
|---|---|---|
tree | Tree | The HAMT tree to operate on |
...sources | object | Objects to extend the tree with |
Extends a HAMT tree with data from objects. Returns the resulting HAMT tree.
isHamt(tree) → boolean
| Param | Type | Description | |
|---|---|---|---|
tree | Tree | * | A HAMT tree or anything |
Checks if a given data object is a HAMT object.
len(tree) → number
| Param | Type | Description |
|---|---|---|
tree | Tree | The HAMT tree to operate on |
Returns the number of keys in a HAMT tree.
An empty HAMT tree.
import { set, get, empty } from 'nested-hamt'
var tree = set(empty, 'hello', 'world')
get(tree, 'hello') // => 'world'
{ type, mask, key?, value?, children }
| Param | Type | Description |
|---|---|---|
type | string | |
mask | number | |
key | string, optional | |
value | *, optional | |
children | Tree[] |
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.