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 🙏

© 2025 – Pkg Stats / Ryan Hefner

datem

v0.1.4

Published

Represent a value and a flag indicating if the value has been set. Presents a constant object whose actual value may be changing. Emits change events.

Downloads

7

Readme

datem

Datem provides abstract datum types. Datum types represent a value and an additional flag indicating if the value has been set. They present constant objects whose actual values may be changing.

Datum objects are event emitters - listeners can be notified whenever the value changes or an error is handled.

Datum Types

  • SET_EVENT ( datum, value )
  • CHANGE_EVENT ( datum, value )
  • ERROR_EVENT ( datum, error )

Datum

Datum extends EventEmitter.

new Datum( value )

Sets the value.

bool hasValue { get; }

Indicates if a value is set.

any value { get; }

Value that is set. Undefined if not set.

any getValue()

Value that is set. Throws NO VALUE DatumError if not set.

any getValueOrDefault( any defaultValue )

Value that is set. Returns defaultValue if not set.

MutableDatum

MutableDatum extends Datum. Provides the ability to change the value.

  • Emits SET_EVENT when value is set.
  • Emits CHANGE_EVENT when value is changed. Only actually changes if differs.
  • Emits ERROR_EVENT when an error happens but is caught.

new MutableDatum( value )

Sets an intial value.

any value { get; set; }

Value that is set. Undefined if not set.

this clearValue()

Clears the set value. When cleared hasValue is false. Returns itself.

this setValue( any value )

Sets the value. Returns itself.

RefreshableDatum

RefreshableDatum extends MutableDatum. Provides the ability to update with a refresh function. Trying to set, clear, or refresh while a refresh is pending will throw PENDING REFRESH DatumError.

  • Emits SET_EVENT when value is set.
  • Emits CHANGE_EVENT when value is changed. Only actually changes if differs.
  • Emits ERROR_EVENT when an error happens but is caught.

new RefreshableDatum( refreshFunction, value )

Sets an initial value and registers a function to be used in refreshing.

bool pendingRefresh { get; }

Indicates if a refresh is in progress.

this refreshValue()

Runs the refresh function and updates the value. Returns itself.

refresh function

any refreshFunction ( RefreshableDatum datum )

Refresh function will be used to update the value of a RefreshableDatum. The return value will be set as the new value of the datum. If an error is thrown then an ERROR_EVENT will be emitted by the datum. If the return value is a promise then will try to resolve it.

DatumError

DatumError extends Error.

  • NO VALUE
  • PENDING REFRESH

error original { get; }

If wrapping another error then the original error. Otherwise undefined.

Example

const RefreshableDatum = require('datem').RefreshableDatum;
const CHANGE_EVENT = require('datem').CHANGE_EVENT;

function refreshFunction( selfDatum ) {
 return selfDatum.value + 1;
}

let datum = new RefreshableDatum( refreshFunction, 123 );
datum.on( CHANGE_EVENT,
 ( selfDatum, value ) => {
  console.log ( selfDatum.valueOf(), value );
  // { hasValue: bool, value: value } value
 }
);
datum.value = 100;
datum.refreshValue();

License

ISC