@rstacruz/nested-hamt
Nested HAMT implementation
Last updated 4 years ago by rstacruz .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @rstacruz/nested-hamt 
SYNC missed versions from official npm registry.

nested-hamt

Nested JSON structures in a HAMT tree

Based off of mini-hamt, but this handles nested JSON structures. I'll explain later.

Status

Install

npm install --save @rstacruz/nested-hamt

API

set

set(tree, keypath, value)

Sets data into a HAMT store.

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

var data = set(empty, 'user', { name: 'John' })
get(data, 'user.name') // => 'John'

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

// Both are equivalent
var data = set(empty, 'user.name', 'John')
var data = set(empty, ['user', 'name'], 'John')

get

get(tree, keypath)

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

del

del(tree, keypath)

Deletes data from a keypath.

keys

keys(tree)

Returns the available keys for tree.

fromJS

fromJS(object)

Converts JSON object into a HAMT tree. Inverse of toJS().

toJS

toJS(tree)

Converts HAMT tree into a JSON object. Inverse of fromJS().

empty

empty

Empty data.

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

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

extend

extend(tree, ...objects)

Extends HAMT tree with data from objects. Compare with Object.assign().

getType

getType(tree, keypath)

Checks for the type of data. Can return object, array, or anything typeof can return (string, number, boolean, and so on).

Thanks

nested-hamt © 2016+, Rico Sta. Cruz. Released under the MIT License.
Authored and maintained by Rico Sta. Cruz with help from contributors (list).

ricostacruz.com  ·  GitHub @rstacruz  ·  Twitter @rstacruz

Current Tags

  • 1.1.2                                ...           latest (4 years ago)

4 Versions

  • 1.1.2                                ...           4 years ago
  • 1.1.1                                ...           4 years ago
  • 1.1.0                                ...           4 years ago
  • 1.0.0                                ...           4 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (3)
Dev Dependencies (4)
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |