# headright

> Add headers to files. Suitable for Copyright and License Notices

Latest version **0.3.0** (published 2025-10-03) · MPL-2.0 license · 0 weekly downloads

## Install

```sh
npm install headright
pnpm add headright
yarn add headright
bun add headright
```

Provides the commands `hr`, `hr-init`.

## Health

**Score 30/100 (F)** — status: maintenance-mode.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.0 |
| Published | 2025-10-03 |
| First published | 2021-04-02 |
| Weekly downloads | 0 |
| License | MPL-2.0 |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 6 |
| Unpacked size | 43.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | yes |
| Author | Rahul Gupta |
| Maintainers | cxres |
| Keywords | license, licence, copyright, notice, header, preamble, banner, CLI |

## Links

- npm: https://www.npmjs.com/package/headright
- Repository: https://gitlab.com/CxRes/headright
- Homepage: https://gitlab.com/CxRes/headright#readme
- Issues: https://gitlab.com/CxRes/headright/issues
- npm.io page: https://npm.io/package/headright

## Dependencies (6)

- [prompts](https://npm.io/package/prompts.md) ^2.4.2
- [minimist](https://npm.io/package/minimist.md) ^1.2.8
- [lilconfig](https://npm.io/package/lilconfig.md) ^3.1.3
- [lodash-es](https://npm.io/package/lodash-es.md) ^4.17.21
- [read-package-up](https://npm.io/package/read-package-up.md) ^11.0.0
- [replace-in-file](https://npm.io/package/replace-in-file.md) ^8.3.0

## Alternatives

- [@salesforce/cli](https://npm.io/package/@salesforce/cli.md) — 389.7K weekly downloads
- [@mintlify/cli](https://npm.io/package/@mintlify/cli.md) — 208.9K weekly downloads
- [@grafana/e2e-selectors](https://npm.io/package/@grafana/e2e-selectors.md) — 128.7K weekly downloads
- [mintlify](https://npm.io/package/mintlify.md) — 112.0K weekly downloads
- [@intlayer/cli](https://npm.io/package/@intlayer/cli.md) — 22.8K weekly downloads

## Recent versions

- 0.3.0 (latest) — 2025-10-03
- 0.2.1 — 2025-10-01
- 0.2.0 — 2025-09-30
- 0.1.1 — 2022-01-06
- 0.1.0 — 2021-04-02

## README

# Headright

> [!WARNING]
> Upgrade immediately to v0.2.0 or above, due to security vulnerabilities in dependencies.

**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`:

```sh
<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:

```sh
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.

```sh
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:

```js
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:

```sh
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.

```js
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:

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

## Copyright & License

Copyright (c) 2021, 2025, Rahul Gupta and Headright Contributors.

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

---
_Source: https://npm.io/package/headright · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
