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

metalevel

v3.0.0

Published

🤪 Isomorphic meta-context for more efficient JS runtime performance

Downloads

1

Readme

🤪 Metalevel

Dude, i'm feeling like i've just transitioned to the meta level...

me, while hackatoning at Hogan Coffee with @m0rtyn

Metalevel is an alternative runtime for JavaScript. It basically stores the whole execution queue as an array, pulling out the first one in row, executing it and goes to the next one until there's no one left.

Speaking of conceptions, metalevel is an alternative JS runtime written in JS. So, get ready to push yourself up to the meta-level.

Usage

npm install metalevel --save

or

<script src="https://cdn.jsdelivr.net/gh/mvoloskov/metalevel/metalevel.min.js" type="module"></script>
<script type="module">
  import Metalevel from './metalevel.js'
  const meta = new Metalevel()

  meta.push(alert, ['Hello World!'])
</script>

Crash course

// options object is optional, here are the defaults

const meta = new Metalevel({
  interval: 20, // how much to wait in between executions, milliseconds
  bias: 50      // how much functions to execute in one async iteration
})

// schedule the function to run
meta.push(alert, ['hello!'])
// alerts 'hello!'

// if chains parameter is true, the function will receive the previous result as the first argument
meta.push(() => 4)
meta.push(console.log, true)
// prints out 4

meta.push(prompt, ['Enter your name'])
meta.push(alert, true)
// alerts whatever you've entered


meta.push(x => x + 3, [1])
// prev will be 4, that's the result of the previous execution which'll be passed as the first argument
meta.push((prev, x) => prev + x + 2, [4], true)
meta.push(console.log, true)
// prints out 10

Why?

Because it's faster. For example, if you need to render tons of DOM elements from, say, json, metalevel will render them in the background, fast and asynchronously, taking by 50 or by whatever you like.

Being used properly, Metalevel drastically reduces time to interactive.

Complete API guide

The meta-flow

Once in interval, metalevel unshifts the function tuple from the queue. It looks like this:

[fn, [args], false]

or this:

[fn, false]

The first element is a function to execute. The second is either its arguments or chaining flag. The third is chaining flag, passed explicitly when you want to chain a function call with arguments.

Chaining is disabled by default.

When enabled, arguments will transform from, say [a, b] to [prev, a, b] — the result of the previous execution will be passed as the first parameter.

Once the queue is empty, execution stops. If the queue was empty and a new execution was scheduled, execution starts immediately.

Runtime management

You can start and stop the execution explicitly:

meta.start()
meta.stop()

You can also clear the whole queue. It will stop the execution and the whole old queue will be lost%

meta.clear()

Getting execution context

You can get execution options and the queue itself:

meta.getOptions()
// returns something like { interval: 20, bias: 50 }

meta.getQueue()
// returns the queue

Events

You can subscribe to events like this:

meta.on('event', cb)

To unsubscribe, call off:

meta.off('event')

Events available:

  • tick — fired on every execution and receives the previous result and the next tuple as parameters
  • start — fired when execution starts. Receives nothing
  • stop — you guessed it. Receives true if the queue was empty when execution stopped, false otherwise
  • push — fired when new execution was scheduled. Receives the actual function scheduled and true if this specific push led to execution start. It happens when the queue was empty before, and this execution was first in line
  • clear— fired on queue wiping. Receives nothing

Cheatsheet

// standard parameters: interval is 20 ms, bias is 50
const meta = new Metalevel()

// passing options
const meta = new Metalevel({
  interval: 100,
  bias: 1
})

// scheduling function execution
meta.push(() => console.log('hi'))

// scheduling with parameters
meta.push(console.log, ['hello ', 'world!'])

// chaining functions — the latter will receive the result of previous execution as the first parameter
meta.push(x => x + 2, [1])
meta.push(alert, true) // that boolean argument

// chaining with parameters
meta.push(x => x + 2, [1])
meta.push((prev, x) => x + prev, [4], true)
// (prev, x) function will receive (1, 4) as parameters

// stopping
meta.stop()

// resuming
meta.start()

// clearing queue
meta.clear()

// getting options and queue
meta.getOptions()
meta.getQueue()

// subscribing to events
meta.on('start', () => console.log('started'))

// unsubscribing
meta.off('start')

Credits