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

de-document-examples

v1.0.0

Published

Automatically update markdown documentation with examples.

Downloads

5

Readme

Overview

Automatically update markdown documentation with examples.

Setup

npm i -g de-document-examples

document path/template.md path/readme.md

to exclude the footer signature this markdown was generated by de-document-examples, include the -no-sig flag

document -no-sig path/template.md path/readme.md

Markdown Syntax Summary

basic js snippet

!example[path/fileName.js flag]

e.g. !example[case1.js given]

paths are relative unless beginning with a /

omitting flags

!example[path/fileName.js]

is a shorter equivilent to:

## !example[path/fileName.js title]

### Given

!example[path/fileName.js given]

### When

!example[path/fileName.js when]

### Then

!example[path/fileName.js then]

if title is missing from fileName.js, the title line will be omitted from the generated doc

markdown snippet

!example[path/fileName.md]

will inject the result of recursively generating fileName.md

markdown paramaters

## case 1

!example[path/fileName.md case1.js]

any words following the file will be passed in as parameters when generating fileName.md

to use these paramaters, add [paramaterIndex] to your markdown file

## !example[[0] title]

other file types

other files will default to being processed as markdown files. effectively, their contents will be inserted without the special processing that is applied to .js files. if the same behavior is desired for a .js file, append an _ when specifying their file names in the example tag

!example[path/fileName.html]
!example[path/fileName.js_]

The .js example file

the .js files used should include a modules.export of format

module.exports = {
    functionExample: {func: () => {}, excludeReturn: true | false},
    objectExample: {obj: {}},
    textExample: {text: ''}
};

example .js example file

let given = () => {
    let list = [1, 2, 3, 4];
    return list;
};

let quadruple = list => {
    let result = list.map(num => num * 4);
    return result;
};

let add4 = list => {
    let result = list.map(num => num + 4);
    return result;
};

module.exports = {
    description: {text: 'multiplies by 4 and adds 4 to each element of an array'},
    given: {func: given, excludeReturn: true},
    step1: {func: quadruple, excludeReturn: true},
    step2: {func: add4, excludeReturn: true},
    final: {obj: add4(quadruple(given()))}
};

the then flag

the then flag is special, in that if it's missing in the .js file, but accessed in the markdown, then documenter will attempt to default it as then: {obj: when.func(given.func())}

Example 1 - using !example[.js flag] syntax

example .js

template .md

Double

this is a simple exampe

Given

let's say we have an array such as:

let list = [1, 2, 3, 4];

When we do a map

let's say we do a map

let result = list.map(num => num * 2);

Then we get

[
  2,
  4,
  6,
  8
]

Example 2 - using !example[.js] syntax

example .js

template .md

Less than 3

Given

let list = [1, 2, 3, 4];

when

let result = list.filter(num => num < 3);

then

[
  1,
  2
]

Example 3 - using !example[.md paramater] syntax

first example .js

second example .js

template .md

child template .md

Injectable, Reusable, & Paramterized Markdowns

Case 1

Description

multiplies by 3 and adds 10 to each element of an array

Given

let list = [1, 2, 3, 4];

First we

let result = list.map(num => num * 3);

Then we

let result = list.map(num => num + 10);

And we get

[
  13,
  16,
  19,
  22
]

Case 2, reusing same template

Description

multiplies by 4 and adds 4 to each element of an array

Given

let list = [1, 2, 3, 4];

First we

let result = list.map(num => num * 4);

Then we

let result = list.map(num => num + 4);

And we get

[
  8,
  12,
  16,
  20
]

Example 4 - using !example[.js_] syntax

example .js

template .md

let add1 = a => a + 1;

this markdown was generated by de-document-examples