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 🙏

© 2025 – Pkg Stats / Ryan Hefner

mos-plugin-example

v1.1.2

Published

A mos plugin that combines example code files with their output

Downloads

365

Readme

mos-plugin-example

A mos plugin that combines example code files with their output

NPM version Build status for master Test coverage for master

Installation

This module is installed via npm:

npm install mos-plugin-example --save

Usage

There is an example/index.js file in this module. Its content is:

'use strict'
console.log('Hello world!')

function sum (a, b) {
  return a + b
}

console.log(sum(1, 2))

//! Comments that start with an exclamation will be inserted into the markdown outside the code block.

function printEachLetter (text) {
  for (let i = 0; i < text.length; i++) {
    console.log(text[i])
  }
}

printEachLetter('Hello world!')

We can load this file via the example plugin. The mos plugin will execute the code in the file and combine the output of the console.logs with the code.

In the current README.md we have this code snippet:

<!--@example('./example/index.js')-->
<!--/@-->

It produces this code block, with the outputs written under the console.logs inside comments:

'use strict'
console.log('Hello world!')
//> Hello world!

function sum (a, b) {
  return a + b
}

console.log(sum(1, 2))
//> 3

Comments that start with an exclamation will be inserted into the markdown outside the code block.

function printEachLetter (text) {
  for (let i = 0; i < text.length; i++) {
    console.log(text[i])
    //> H
    //> e
    //> l
    //> l
    //> o
    //>  
    //> w
    //> o
    //> r
    //> l
    //> d
    //> !
  }
}

printEachLetter('Hello world!')

ES6

example/ can be written in ES6, but they have to be loaded with example.es6.

Mos uses rollup and babel to transpile the example written ES6. However, babel is not installed with mos, so you'll have to install babel manually. Put a .babelrc file in your example folder and configure babel the way it is described here.

Here is an example that is using ES6 in the current package:

const sum = (a, b) => a + b

const numbers = [1, 2]
console.log(sum(...numbers))
//> 3

API

  • example(relativePathToFile)
  • example.es6(relativePathToFile) - process an example written in ES6

License

MIT © Zoltan Kochan


Dependencies Dependency status for master

Dev Dependencies devDependency status for master