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

@silexlabs/silex-plugins

v1.0.10

Published

Open architecture for Silex plugins

Downloads

146

Readme

Silex plugins

Environment agnostic (node.js, browser, commonjs, esnext...) open architecture (plugin system) inspired by 11ty.dev config

In a nutshell

Plugins can be added as a function or loaded from absolute path, relative path or URL

A plugin takes a Config object and returns an object which will be merged into the initial Config object. The config object emits events and has a method addPlugin to attach other plugins from a plugin on specific events.

How it works

  1. Install with npm i @silexlabs/silex-plugins
  2. Use in your app to add a plugin system
  3. Create plugins for your app

Example

In your app

app.js

import config from '@silexlabs/silex-plugins'

// Create a config instance
const userConfig = config()

// Add a first plugin which is the main config
userConfig.addPlugin('.myapp.js')

// Notify plugins of important events
userConfig.emit('ready')

.myapp.js: This is a config file and a plugin

export default (config) => {
  config.on('ready', () => 'do something')
  config.addPlugin('myplugin.js', {
    text: 'some options',
  })
  return {
    defaultOption: 'value',
  }
}

myplugin.js: This is a plugin

export default (config, options) => {
  config.on('ready', () => `do something else with ${ options.text }`)

  return {
    defaultOption: 'override config',
  }
}

The many ways to add a plugin from a config object

It can be done from a plugin or your app which creates the config object

  1. A plugin which is just a simple function
function plugin(config, options) { console.log(options.anoption) } // This will log "a value"
export default(config, _) {
  config.addPlugin(plugin, { anoption: "a value" })
}
  1. A plugin from npm
export default(config, _) {
  config.addPlugin('https://unpkg.com/some-plugin', { anoption: "a value" })
}
  1. A plugin you import yourself
import plugin from 'a-plugin'
export default(config, _) {
  config.addPlugin(plugin, { anoption: "a value" })
}
  1. Multiple plugins at once
// Define a function
// The return value will be merged in the config object
function namedFunction(config, options) {
  return {
    text: 'returns some options to merge into the config',
    other: `this is the ${options} object`,
  }
}
export default(config, _) {
  // Add a multiple plugins at once
  // Path or URL
  config.addPugin([
    'https://unpkg.com/some-plugin',
    'node_modules/some-plugin',
    '.myappconfig',
    namedFunction,
  ], { // Here is how to pass options to the plugins
    'https://unpkg.com/some-plugin': {},
    'node_modules/some-plugin': {},
    '.myappconfig': {},
    [namedFunction]: {},
  })
}