npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

hamaca

v0.3.2

Published

A data-reactive library

Downloads

4

Readme

hamaca.js

A data-reactive library

Getting Started

Install

npm i hamaca

Usage

import $ from 'hamaca';

const name = $('World');
const message = name.to(name => `Hello, ${name}`);
console.log(message.get());
name.set('hamaca.js');
console.log(message.get());

Methods

get

Returns the current data's value. If within a syncable function (i.e. to, watch, $.calc, $.sync), this will cause the function to be called again any time the value changes.

const flag = $(true);
$.sync(() => console.log(flag.get() ? 'Flag is set' : 'Flag not set'));

set

Modifies the data, and triggers updates to any dependent syncable functions.

const flag = $(true);
flag.set(false);

modify

Pass a modifying function to modify the data

const items = $(['One', 'Two']);
items.modify(items => items.push('Three'));

watch

Calls function each time the value is changed

const count = $(0);
count.watch(n => console.log(`Count: ${n}`));
for (let n = 1; n < 3; n++) {
  count.set(n);
}
// Outputs
//   Count: 0
//   Count: 1
//   Count: 2

to

Converts one data to another

const n = $(2);
const squared = n.to(n => n * n);
squared.watch(nn => console.log(`Square: ${nn}`));
n.set(3);
// Outputs
//   Square: 4
//   Square: 9

Functions

These are functions on $

$.ensure

Ensures that a value is a data object

const squared = n => $.ensure(n).to(n => n * n);
const a = squared(2);.
const b = squared(a);
console.log(a.get(), b.get());  // Output: 4, 16

$.ensureAll

Converts an array of values that may or may not be data objects to an array of data objects

const sum = (...args) => {
  const datas = $.ensureAll(args);
  return $.calc(() => datas.reduce((sum, data) => sum + data.get(), 0));
};
const a = $(1);
const b = sum(a, 2);
const c = sum(a, b, 3);
console.log(a.get(), b.get(), c.get());  // Outputs: 1, 3, 7
a.set(2);
console.log(a.get(), b.get(), c.get()); // Outputs: 2, 4, 9

$.getAll

Resolves each data item in an array

const a = $(2);
const b = a.to(a => a + 1);
const c = $.calc(() => a.get() * b.get());
console.log($.getAll([a, b, c]));  // Outputs: [2, 3, 6]

$.calc

Calculates a data object based on other data objects

const n = $(2);
const exp = $(8);
const pow = $.calc(() => Math.pow(n.get(), exp.get()));
console.log(pow.get());  // Outputs: 256
n.set(9)
exp.set(2);
console.log(pow.get());  // Outputs: 81

$.sync

Calls function any time a used data object changes

const n = $(2);
const exp = $(8);
$.sync(() => {
  console.log(`${n.get()}^${exp.get()} = ${Math.pow(n.get(), exp.get())}`);
});
n.set(9)
exp.set(2);
// Outputs:
//   2^8 = 256
//   9^8 = 43046721
//   9^2 = 81