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

enigmatic

v0.22.0

Published

**Enigmatic.js - Documentation**

Readme

Enigmatic.js - Documentation

Note: The code provided is a self-contained JavaScript file that defines a library named Enigmatic.js. The documentation below explains the functions and features available in the library.

1. Introduction

Enigmatic.js is a JavaScript library designed to provide utility functions and tools to simplify common tasks such as loading resources, working with custom elements, managing state, and handling data reactivity. The library aims to enhance web development productivity and offers the following features:

  • Resource Loading: Load JavaScript and CSS files dynamically.
  • Custom Element: Define custom web components with ease.
  • State Management: Easily manage and react to changes in application state.
  • Data Handling: Fetch data from remote sources and stream real-time data.

2. Helpers

Enigmatic.js provides several helper functions to simplify common tasks:

  • w.$(selector): Returns the first element matching the given CSS selector within the document.
  • w.$$(selector): Returns a list of all elements matching the given CSS selector within the document.
  • w.loadJS(src): Loads a JavaScript file dynamically by creating a script element in the document's head.
  • w.loadCSS(src): Loads a CSS file dynamically by creating a link element in the document's head.
  • w.wait(ms): Returns a Promise that resolves after the specified number of milliseconds.
  • w.ready(): Returns a Promise that resolves when the DOM is ready and the document has completed loading.

3. Template Flattening

Enigmatic.js provides the w.flatten(obj, text) function to template a string using placeholders. The placeholders can be in the form of {$key}, {_key_}, or {_val_}. The function recursively replaces the placeholders with the corresponding keys and values from the provided object.

4. Custom Element

Enigmatic.js simplifies the process of defining custom elements with the w.element(name, options) function. It takes the following parameters:

  • name (string): The name of the custom element.
  • options (object): An object containing configuration options for the custom element.
    • onMount: A function to be executed when the custom element is connected to the DOM.
    • beforeData: A function to preprocess the data before rendering the template.
    • style: A string containing CSS rules specific to the custom element.
    • template: A string representing the HTML template for the custom element.

5. State, Data, and Reactivity

Enigmatic.js introduces reactive state management with the w.state object. It is implemented using a Proxy to reactively update DOM elements when state changes. DOM elements with data attributes that match state keys will be automatically updated when the corresponding state changes.

  • w.state: An object acting as reactive state storage. Changes to this object trigger updates in associated DOM elements with matching data attributes.

  • w.save(obj, name): Saves a JavaScript object to the local storage under the specified name.

  • w.load(name): Loads a JavaScript object from local storage using the given name.

  • w.get(url, options, transform, key): Fetches data from a remote URL using the fetch API. Transforms the fetched data using the optional transform function and updates the state with the specified key.

  • w.stream(url, key): Sets up an EventSource to stream real-time data from the specified URL and updates the state with the specified key.

6. Startup

Enigmatic.js provides the w.start() function to kickstart the library and process elements on the page with special attributes like fetch, immediate, and stream.

7. Global Object

The code creates a global object w that holds all the utility functions and state management features.

8. Usage Example

To use Enigmatic.js, include the script in your HTML file and call its functions as needed. For example:

<script src="unpkg.com/enigmatic"></script>
<script>
  // Perform custom element registration
  w.element('custom-element', {
    template: '<div>{_key_}: {_val_}</div>',
  });

  // Initialize Enigmatic.js
  (async () => {
    await w.start();
    w.state.exampleData = { key1: 'value1', key2: 'value2' };
  })();
</script>

9. Support

For bug reports, feature requests, or general inquiries, please visit the GitHub repository of Enigmatic.js.