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

orcajs

v1.1.5

Published

orchestrate your javascript

Downloads

640

Readme

orca

Build Status Coverage Status


A code wrapper for real-world javascript separation.

Usage

Install from npm:

npm install --save orcajs

Import that wrapper for use throughout your application:

import app from 'orcajs';
app.registerAction('*', () => { console.log("test"); });
app.run(); // => test

What the hell does that mean

In a perfect world, you'd have a small, perfect javascript bundle, built of magic and rainbows. It would be fast, efficient, with full test coverage, and compatible with every browser.

But we know that's not the world you live in. If you're working on anything like any of the web apps we've seen over the past 5 years, you've got some frankenstein monster that's half legacy jQuery and half "I learned this in a weekend" Angular --- and worse, you've probably got something like this:

if ($('body').hasClass('special-page')) {
    // execute code that only works on this page here.
    // Don't execute it anywhere else or everything
    // will break.
}

if ( $('#special-div').length > 0 ) {
    // this will break if #special-div is not present
}

If that looks familiar, then orca is for you.

What it does

orca lets you set up ordered an ordered system of callbacks for dividing your code into discretely executing chunks. This lets you bundle all your code into a single JS file, but limit code to just to the pages they're used on.

import app from 'orcajs';

// Define Callbacks
function all() { console.log("All"); }
function foo() { console.log("Foo"); }
function bar() { console.log("Bar"); }

// Register Actions
app.registerGlobalAction(all);
app.registerAction('foo', foo);
app.registerAction('bar', bar);

app.run('foo'); // => log All, Foo

Namespacing

Namespacing allows you to run code in a structured way. Calling run with a namespace will run only the actions in that namespace.

app.registerGlobalAction(all);   // global namespace
app.registerAction('foo', foo);  // foo namespace
app.registerAction('bar', bar);  // bar namespace

app.run('foo');    // runs `all` and `foo`, but not `bar`

Nesting

Namespaces can be nested with the . character:

app.registerAction('foo.bar', fooBar);
app.registerAction('foo.baz', fooBaz);

app.run('foo');     // runs `fooBar` and `fooBaz`
app.run('foo.bar'); // runs `fooBar`, but not `fooBaz`

Executing Multiple Namespaces

Multiple namespaces can be run at once:

app.run(['foo', 'bar']);

Excluding Callbacks from Namespaces

Callbacks can be excluded from specific namespaces:

app.registerGlobalAction(foo, {excludes: ['bar']});

app.run();          // runs `foo`
app.run('foo');     // runs `foo`
app.run('bar');     // does not run `foo`

If you'd like to run a namespace, but exclude global actions, you can pass a second argument to run:

app.registerGlobalAction(foo);
app.registerAction('bar', baz);

app.run();                           // runs `foo`
app.run('bar', {runGlobals: false}); // does not run `foo`

Priority

Sometimes sequencing can be important when executing discrete blocks of code. There's an optional third parameter which can be passed to registerAction, which will set the priority. Actions will be run in priority order from high to low.

app.registerGlobalAction(foo, {priority: 0});
app.registerGlobalAction(bar, {priority: 5});   // this will run before foo