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

core-stack

v0.2.0

Published

The base of a core object. Create an object implementing a plugin system, a stack handler and an event emitter + some useful methods for a core object.

Downloads

4

Readme

core-stack

Create an object implementing:

  • An event emitter (Evemit, only 1 kb).
  • A plugin system that handles the asynchronous loading.
  • A stack handler.
  • And some useful methods for handling a core and config object.

core-stack was implemented with performance and lightness in mind.

Install

npm install core-stack

or with Yarn:

yarn add core-stack

Usage

See the source code for the JS doc.

Create a core

import CoreStack from 'core-stack';

// or const CoreStack = require('core-stack');
const core = new CoreStack();

// adds what do you need in the `core`...
core.foo = {};
core.bar = 'bar';

export default core;
// or module.exports = core;

Plugins

Create a plugin

/**
 * My plugin
 *
 * @param  {CoreStack}   core
 * @param  {*}           [args]
 * @param  {function}    done
 */
export default function myPlugin(core, args, done) {
  // add some feature to the core
  // ...

  // `done` function indicate that the plugin is loaded
  done(args);
};

Use a plugin

On the fly:

core.use(plugin, pluginArgs, function(done /*, doneArgs */) {
  console.log('plugin loaded!');
  done(/* doneArgs */);
});

or a reusable plugin:

import myPlugin from './plug/myPlugin';

core.use(myPlugin);
// or core.use(require('./plug/myPlugin'));

Example, create a simple logger plugin (reusable):

export default function loggerPlugin(core, args, done) {
  core.log = function() {
    console.log(...arguments);
  };

  core.logWarn = function() {
    console.warn(...arguments);
  };

  core.logError = function() {
    console.error(...arguments);
  };

  done();
};

Load and use the logger plugin:

import logger from './plug/logger';

// load the logger plugin
core.use(logger);

// use the logger plugin when the core was booted
core.boot(function() {
  core.log('Hello');
  core.logWarn('Warning!');
  core.logError('Ooops! An error occurred.');
})

Full example

import CoreStack from 'core-stack';

// Plugins
import logger from './plug/logger/';
import config from './plug/config/';
import router from './plug/router/';
import react from './plug/react/'; // or another lib / framework to initialize

const app = new CoreStack();

app
  .use(logger)
  .use(config)
  .use(router)
  .use(react)
  .boot(function() {
    app.log('all plugins are loaded');

    // you can emit any events with the builtin event emitter
    // see evemit package
    app.emit('app.booted');

    // init the routes and a router (e.g: routux package)
    router.init();
  })
;

LICENSE

MIT (c) 2016, Nicolas Tallefourtane.

Author

| Nicolas Tallefourtane - Nicolab.net | |---| | Nicolas Talle |