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

cocy

v1.0.0-alpha.2

Published

The main Cocy package.

Readme

Cocy

The main Cocy package.

Usage

const cocy = new Cocy(options?);

Options

See CocyOptions.ts.

Files

Files are stored as a map at cocy.files. You can for example get a file by its absolute path using cocy.files.get(absolutePath).

The properties of each file object are described here.

// it's a map - don't forget `values`
for (const file of cocy.files.values()) {
	console.log(file.attributes.title);
}

Methods

cocy.use()

cocy.use(plugin, ...options?)

The plugin function will be invoked, allowing it to register hooks on the instance. The cocy instance will be passed as the first parameter, followed by all specified options.

cocy.find()

Search for files and add them. Promise is fulfilled, once all files have been found and transformed by registered plugins.

cocy.resolveAsset()

cocy.resolveAsset(asset, file, key?)

Resolve an asset using the asset resolver. If a key is specified, it will be added to the file's asset map and can be retrieved by using file.assets.get(key). See Assets below for more.

cocy.startWatcher()

Start watching for file-system changes.

cocy.stopWatcher()

Stop watching for file-system changes.

Events

You can hook into events on the instance. See the Houk API docs for more info on event listeners.

cocy.on('fileAdded', (file: CocyFile) => {
	// we got a new file!
	console.log(file.slug);
});

| Event | Parameters | Description | | ------------- | --------------------------------------- | ------------------------------------------------- | | fileAdded | CocyFile | A new file was added. | | fileRemoved | CocyFile | A file was removed. | | fileUpdated | CocyFile | A file's content was changed. | | fileChanged | CocyFile | Any of the upper events occured to a file. | | assetAdded | CocyAsset, CocyFile, CocyAssetKey | A new asset was added. See Assets below for more. |

Assets

Allowing files to reference assets is often a basic requirement for content-based sites. For example, you might have a blog post like this in Markdown format:

I went to Hamburg last summer:

![Proof](./hamburg.jpg)

Let's use the image tag as an example. By default, the file URLs will be kept, resulting in <img src="./hamburg.jpg">. Depending on your environment, this might not be desirable. To transform the file URLs, you can listen for assetAdded events:

import path from 'path';

cocy.on('assetAdded', async (resolve, asset, file) => {
	// here, asset is "./hamburg.jpg"
	// file is the Cocy File object

	if (asset.startsWith('./')) {
		// it's a relative file path!
		// use the file's path as a base

		const absolute = path.join(file.path.absolute, '..', asset);

		// in this example, we might want to use an image cdn
		const url = await myCdn.upload(absolute);

		// url might be https://cdn.photos/hamburg.jpg
		resolve(url);
	}
});

This would result in <img src="https://cdn.photos/hamburg.jpg">.