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

@jakeburch/pyrite

v0.1.6

Published

[@jakeburch/pyrite on GitHub](https://github.com/JakeBurchCR/pyrite)

Downloads

2

Readme

Pyrite

@jakeburch/pyrite on GitHub

Examples

Pyrite provides a framework for managing the DOM via Javascript.

Example:

In HTML

<div class="container">
  <h1 style="color: blue;">Hello</h1>
  <p>Thanks for looking at Pyrite!</p>
  <button type="button" onclick="alert('thanks lol')">Click me!</button>
</div>

With Pyrite:

const styles = {
  h1: {
    color: 'blue'
  }
};

pyrite.element('div')
  .withClasses(['container'])
  .withChildren([
    pyrite.element('h1')
      .withStyles(styles.h1)
      .withText('Hello'),
    pyrite.element('p').withText('Thanks for looking at Pyrite!'),
    pyrite.element('button')
      .withProps({ type: 'button' })
      .withClickEffect(() => alert('thanks lol'))
      .withText('Click me!')
  ]);

In this example, the Pyrite version is much more verbose. But in a scenario like this:

<ul>
  <li onclick="alert('Wake up')">Wake up</li>
  <li onclick="alert('Grab a brush and put a little makeup')">Grab a brush and put a little makeup</li>
  <li onclick="alert('Hide the scars to fade away the shakeup')">Hide the scars to fade away the shakeup</li>
  <li onclick="alert('Why'd you leave the keys upon the table?')">Why'd you leave the keys upon the table?</li>
  <li onclick="alert('Here you go create another fable')">Here you go create another fable</li>
</ul>

Pyrite gives us a tidy method of adding repeated content to the DOM:

const phrases = [
  'Wake up',
  'Grab a brush and put a little makeup',
  'Hide the scars to fade away the shakeup',
  'Why\'d you leave the keys upon the table?',
  'Here you go create another fable'
];

pyrite.element('ul')
  .withChildren(
    phrases.map(phrase => pyrite.element('li').wihText(phrase).withClickEffect(() => alert(phrase))
  );

Pyrite is meant to be used as a single entry point, single page application framework, but you can use Pyrite anywhere you find it useful. For example:

<body>
  <h1>An interesting title</h1>
  <p>Four score and seven years ago, a guy did a thing. Big mistake.</p>
  <img src="rabid-badger.jpg" />
  <iframe href="much.better.website.com"></iframe>
  <p>My favorite cereals</p>
  <ul>
    <li>The kind with loops</li>
    <li>The kind with bunches of oats</li>
    <li>Chocolate Vampire</li>
    <li>Total</li>
  </ul>
</body>

Maybe you have a simple, static DOM structure, and you don't really benefit from describing it with JS. Except you decide you want to pull your favorite cereals from a database.

With Pyrite, we can not only programmatically build DOM structure fragments, but also watch for changes to the backing property and live-rebuild accordingly:

class CerealTime extends PyriteElement {
  cereals;
  
  constructor() {
    document.body.appendChild(this.native);
  }
  
  detectChanges(prop) {
    if (prop === 'cereals') {
      this.buildFavoriteCereals();
    }
  }

  buildFavoriteCereals() {
    this.clearChildren();
    this.withChildren( 
      this.cereals.map(cereal => new pyrite.element('li').withText(cereal));
    );
  }
}

const cerealTime = new CerealTime();

Usage

Some day this will be an importable module, but for now:

yarn add @jakeburch/pyrite
<script src="node_modules/@jakeburch/pyrite/index.js" type="text/javascript"></script>

Thanks

I made Pyrite for fun. It should not be considered practical, stable, or even useful for actual products.