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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@kingjs/expand-readme

v1.0.9

Published

Expands `README.t.md` into `README.md`.

Downloads

1,483

Readme

@kingjs/expand-readme

Expands README.t.md into README.md.

Usage

Give a package.json like this:

{
  "name": "@kingjs/ns0.ns1.example",
  "version": "1.0.1",
  "description": "Example description.",
  "main": "index.js",
  "repository": {
    "url": "https://repository.kingjs.net/ns0.ns1.example"
  },
  "license": "MIT",
  "dependencies": {}
}

And a index.js like this:

/**
 * @this any This comment
 * 
 * @param callback Callback comment.
 * @param foo Foo comment.
 * @param [bar] Bar comment.
 * @param [baz] Baz comment.
 * 
 * @returns The return comment.
 * Return comment that spans a line.
 * 
 * @remarks Remarks comment
 * that spans lines.
 * @remarks - Remarks comment on new line.
 * 
 * @callback
 * @param pop Default callback.
 * 
 * @callback foo
 * @param moo Moo comment.
 * @param [boo] Boo comment
 */
function example(callback, foo, bar, baz) { }

And a README.t.md like this:

# @[kingjs][@kingjs]/${join('[${value}][ns${i}]', segments, '.')}
${description}
${canInclude('./test/readme.js') ? expand('./md/USAGE.t.md') : ''}
${api ? expand('./md/API.t.md') : ''}
${remarks ? expand('./md/REMARKS.t.md') : ''}
${expand('./md/FOOTER.t.md')}

[@kingjs]: ${npmjs}kingjs
${join('[ns${i}]: ${npmjs}@kingjs/${value}', namespaces, '\n')}

And a md/USAGE.t.md like this:

## Usage
```js
${include('./test/readme.js').replace('..', name)}
```

And a test/readme.js like this:

var assert = require('assert')

var test = require('..');

function readMe() {
  // example code here
}
readMe();

And a md/API.t.md like this:

## API
```ts
${api}
```
### Parameters
${join('- `${key}`: ${value}${join("  - `${key}`: ${value}", value.callback.parameters, "\\n", "\\n")}', parameters, '\n')}
${returns ? expand('./RETURNS.t.md') : ''}

And a md/RETURNS.t.md like this:

### Returns
${returns}

And a md/REMARKS.t.md like this:

### Remarks
${remarks}

And a md/FOOTER.t.md like this:

## Install
With [npm](https://npmjs.org/) installed, run
```
$ npm install ${name}
```
## Source
${repository}
## License
${license}

![Analytics](https://analytics.kingjs.net/${join('${value}', segments, '/')})

Running $erm will produce a README.md like this:


# @[kingjs][@kingjs]/[ns0][ns0].[ns1][ns1].[example][ns2]
Example description.
## Usage
```js
var assert = require('assert')

var test = require('@kingjs/ns0.ns1.example');

function readMe() {
  // example code here
}
readMe();
```

## API
```ts
example(this, callback(pop), foo(moo[, boo])[, bar[, baz]])
```
### Parameters
- `this`: This comment
- `callback`: Callback comment.
  - `pop`: Default callback.
- `foo`: Foo comment.
  - `moo`: Moo comment.
  - `boo`: Boo comment
- `bar`: Bar comment.
- `baz`: Baz comment.
### Returns
The return comment. Return comment that spans a line.
### Remarks
Remarks comment that spans lines.
- Remarks comment on new line.
## Install
With [npm](https://npmjs.org/) installed, run
```
$ npm install @kingjs/ns0.ns1.example
```
## Source
https://repository.kingjs.net/ns0.ns1.example
## License
MIT

![Analytics](https://analytics.kingjs.net/ns0/ns1/example)

[@kingjs]: https://www.npmjs.com/package/kingjs
[ns0]: https://www.npmjs.com/package/@kingjs/ns0
[ns1]: https://www.npmjs.com/package/@kingjs/ns0.ns1
[ns2]: https://www.npmjs.com/package/@kingjs/ns0.ns1.example

API

expandReadme(templateRelPath)

Parameters

  • templateRelPath: The relative path to the template. Default will search pwd for README.t.md.

Returns

Writes README.md in pwd.

Remarks

The tool takes no command line arguments. Instead:

  • The tool expects to find a project.json in the directory from which it's launched.
  • It then looks for a readmeTemplate element in the package.json and tries to load that value as a relative path or as a package for use as the readme template.
    • If a package, it expects that package's main to be a t.md template file.
  • If no readmeTemplate is found then it searches the current directory for README.t.md.
  • Once the template is found, it's expanded into a README.md file in the current directory.

Expansion is preformed by treating the README.t.md files a js template literal that has the following variables in scope:

Variables

The following variables are in scope as the template expands:

  • npmjs -- https://www.npmjs.com/package/

From package.json:

  • name
  • version
  • description
  • license
  • repository

From the package name:

  • namespaces: Array of namespaces.
    • E.g. @kingjs/foo-bar.baz.moo -> [foo-bar, foo-bar.baz];
  • segments: Array of the segments comprising the namespace.
    • E.g. @kingjs/foo-bar.baz.moo -> [foo-bar, baz];

From the first JSDoc comment found in the file pointed at by the main element of the package.json (typically index.js):

  • parameters[name] -- @param comment for name and @this comment. Inserted in source order.
  • returns -- @returns comment
  • remarks -- @remarks comment
  • api -- Mozilla signature
    • E.g. foo(bar[, [baz[, moo]]]).
    • Optional parameters names are enclosed in square brackets.
      • E.g. /** @params [baz] My baz comment. */

Functions:

  • include(relPath) -- Include the content of the file at relPath using the directory of project.json as the base path.
  • canInclude(relPath) -- Test if include(relPath) will find a file.
  • expand(relPath) -- Includes and expands the content of the file at the relPath using the directory of the readme template as the base path.
  • canExpand(relPath) -- Test if expand(relPath) will find a file.
  • join(template, source[, separator[, prefix[, suffix]]]) -- Joins the expansions of template for each key/value pair of source with optional separator, prefix, and suffix while also introducing loop iteration variable i.

Install

With npm installed, run

$ npm install -g @kingjs/expand-readme
$ erm

Execute

With npx installed, run

$ npx @kingjs/expand-readme

License

MIT

Analytics