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

headright

v0.1.1

Published

Add headers to files. Suitable for Copyright and License Notices

Downloads

12

Readme

Headright

Headright lets you add and update headers in files. It is especially suitable for adding legal information such as copyright and license notices.

Installation

Add Headright to your package as a devDependency:

<npm|pnpm|yarn> add -D headright

To use Headright in multiple projects, install globally using -g flag in lieu of the -D flag.

Initialization

Initialization is automatically done during local installations. However, it can also be run later.

CLI

When installed locally, commands must be preceded by npx, pnpx or yarn as appropriate.

Initialize Headright with the hr-init command:

hr-init

This creates a configuration file .headrightrc.js with sensible defaults. To create the configuration file with another name use the --config or -c flag.

hr-init -c hr.config.js

You shall be prompted before overwriting an existing configuration file. To avoid the prompt, use:

  • --force or -f flag to overwrite without asking, or
  • --ignore or -i flag to skip without asking.

Using both options together will result in an error.

API

You can create the configuration file programmatically:

import { configuration } from 'headright';

await configuration.initialize('path/to/new/config/file');

Usage

Before using Headright, edit the configuration file as needed. All the options are explained in the comments within the configuration file itself.

CLI

When installed locally, commands must be preceded by npx, pnpx or yarn as appropriate.

Run Headright from the command line using hr command:

hr [options] <files¹>

API

To run Headright from a script, you need to load the configuration file and pass it to headright along with other options.

import { configuration, headright } from 'headright';

// Load the Configuration File
const config = await configuration.load(/* optional path/to/config/file */);
// or create you own config

// Invoke Headright with minimum options
const result = await headright({
  config,
  files: ['**'],
});

// List the files modified
console.log(results.filter(result.hasChanged && result.file).join('\n');

Options

  • Files (Mandatory): List of files or glob patterns to modify.
    API: files Array of files/glob strings
    CLI: <files¹> List of files/glob strings

    ¹Remember to quote or escape any globs to prevent the shell from expanding them before they are passed to Headright.

  • Dry Run: Report the files that shall be changed. Does not mutate files.
    API: dry Boolean
    CLI²: -d, --dry

    ²When using --dry without --verbose on the command line, Headright will exit with code 1 when it detects that files would be modified. This is suitable for use, for example, with git precommit hooks

  • Add Only³: Only add new headers in files where one does not previously exist.
    API: addOnly Boolean
    CLI: -a, --add-only

  • Update Only³: Only update notices in files (where they previously exist).
    API: updateOnly Boolean
    CLI: -u, --update-only

    ³Using both --add-only and --update-only together is the same as not specifying either, that is, both add and update will be carried out.

Options (CLI only)

  • Verbose: List file changes
    CLI: -v, --verbose

  • Help: Show command line options
    CLI: -h, --help

Results (API)

The output is an array of objects with a list of files examined and if they were modified:

[
  {
    "file": "path/to/files/file1.html",
    "hasChanged": true
  },
  {
    "file": "path/to/files/file2.html",
    "hasChanged": false
  },
]

Copyright & License

Copyright © 2021, Rahul Gupta and Headright Contributors.

Headright is distributed under the terms of the Mozilla Public License, v. 2.0.