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

cnb

v1.2.4

Published

CLI tool for enforcing consistent Git branch naming conventions across teams and projects

Downloads

32,908

Readme

🚀 Create New Branch

cnb is a simple and customizable CLI tool that helps you create Git branches following naming conventions, and validates (lints) branch names to ensure they follow the configured conventions.

🎬 Demo

cnb

📦 Installation

Install the package as a dev dependency:

npm i -D cnb

🛠️ Usage

Creating a New Branch

  1. Add the following alias to your .gitconfig:
[alias]
cnb = "!npx cnb"
  1. Add the following script to your package.json:
"scripts": {
	"prepare": "git config --local include.path ../.gitconfig",
}
  1. Make sure the prepare script runs before trying the new git alias. You can do this by running (only once):
npm i

Or explicitly run the script:

npm run prepare
  1. Run the following command to create a new branch with naming conventions:
git cnb

This will prompt you with a set of options to choose from (e.g., feat, fix, chore, etc.). You'll also provide a short description that will be formatted into kebab-case.

Example:

  • Selected type: feat
  • Description: configure notifications

The branch created will be: feat/configure-notifications.

If your configuration requires a ticket ID (based on your config file), the flow will prompt you to enter that first.

Linting a Branch Name

You can also use cnb to lint and validate if the current branch name follows your configured conventions.

  1. Add the following script to your package.json:
"scripts": {
	"cnb:check": "cnb --check"
}
  1. Run the script to lint the current branch name:
npm run cnb:check

📁 Configuration

You can customize the behavior of cnb by creating a configuration file in your project root called cnb.config.ts (for ES6 environments) or cnb.config.cjs (for CommonJS environments).

Configuration Options

| Option | Type | Description | Default | | ---------------------- | ---------- | ----------------------------------------------------------------------------------------------- | ----------------------------------- | | branchTypes | string[] | The types of branches you can select (e.g., feat, fix, chore, style) | ['feat', 'fix', 'chore', 'style'] | | maxDescriptionLength | number | The maximum length allowed for the branch description. | 20 | | skipTicketId | boolean | Whether to skip the ticket ID prompt. | false | | ticketIdPrefix | string | The prefix to add to the ticket ID (e.g., JIRA-). | T- | | separator | string | The character(s) used to separate the ticket ID, branch type, and branch name (e.g., /, _). | / |

Example cnb.config.ts (ES6)

import type { CnbConfig } from 'cnb';

const config: CnbConfig = {
	branchTypes: ['feat', 'fix', 'chore', 'style'],
	maxDescriptionLength: 20,
	skipTicketId: false,
	ticketIdPrefix: 'JIRA-',
};

export default config;

Example cnb.config.cjs (CommonJS)

module.exports = {
	branchTypes: ['feat', 'fix', 'chore', 'style'],
	maxDescriptionLength: 20,
	skipTicketId: false,
	ticketIdPrefix: 'JIRA-',
};

🛠️ Note for ES6 vs. CommonJS Users

  • For ES6 users: Create your configuration file as cnb.config.ts and use export default.
  • For CommonJS users: Create your configuration file as cnb.config.cjs and use module.exports.

👥 Authors

📄 License

MIT