
Product
Introducing Immutable Scans
Scan results now load faster and remain consistent over time, with stable URLs and on-demand rescans for fresh security data.
@rstacruz/nested-hamt
Advanced tools
Nested JSON structures in a HAMT tree
Based off of mini-hamt, but this handles nested JSON structures. I'll explain later.
npm install --save @rstacruz/nested-hamt
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(tree, keypath)
Returns data from a HAMT store. If keypath is not given, it returns the entire store as a JSON object.
del(tree, keypath)
Deletes data from a keypath.
keys(tree)
Returns the available keys for tree.
fromJS(object)
Converts JSON object into a HAMT tree. Inverse of toJS().
toJS(tree)
Converts HAMT tree into a JSON object. Inverse of fromJS().
empty
Empty data.
import { set, get, empty } from 'nested-hamt'
var tree = set(empty, 'hello', 'world')
get(tree, 'hello') // => 'world'
extend(tree, ...objects)
Extends HAMT tree with data from objects. Compare with Object.assign().
getType(tree, keypath)
Checks for the type of data. Can return object, array, or anything typeof can return (string, number, boolean, and so on).
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
FAQs
Nested HAMT implementation
The npm package @rstacruz/nested-hamt receives a total of 3 weekly downloads. As such, @rstacruz/nested-hamt popularity was classified as not popular.
We found that @rstacruz/nested-hamt demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
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.

Product
Scan results now load faster and remain consistent over time, with stable URLs and on-demand rescans for fresh security data.

Product
Socket's new Alert Details page is designed to surface more context, with a clearer layout, reachability dependency chains, and structured review.

Product
Campaign-level threat intelligence in Socket now shows when active supply chain attacks affect your repositories and packages.