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

secret-guardian-ts

v1.0.2

Published

Plug-and-play pre-commit & pre-push secret scanner that blocks secrets (TypeScript compatible).

Downloads

19

Readme

🔐 secret-guardian-ts

npm version License: MIT

A plug-and-play TypeScript-compatible pre-commit & pre-push secret scanner that helps prevent accidentally committing secrets to your repository. Automatically installs git hooks during npm install and warns or blocks commits/pushes when potential secrets are detected.

✨ Features

  • 🔒 Auto-installs pre-commit and pre-push hooks during npm install
  • 🔍 Scans staged files for common secret patterns (AWS keys, private keys, passwords, JWT tokens, API keys)
  • 🎯 Two modes:
    • strict - Automatically blocks commits with secrets
    • prompt - Asks user to proceed (default)
  • 📦 TypeScript source with compiled dist/ for publishing
  • 🎨 Configurable banner to print contact info during installation
  • Zero configuration - works out of the box
  • 🧪 Fully tested with Jest

📦 Installation

npm install secret-guardian-ts --save-dev

That's it! The git hooks will be automatically installed.

🚀 Usage

After installation, the package automatically:

  1. Installs pre-commit and pre-push hooks in your .git/hooks/ directory
  2. Scans your staged files before each commit
  3. Alerts you if potential secrets are detected

Basic Workflow

# Make changes to your code
echo "API_KEY='sk-1234567890abcdef'" > config.js

# Try to commit
git add config.js
git commit -m "Add config"

# Secret Guardian will detect the API key and warn you!

⚙️ Configuration

Mode Configuration

You can configure the behavior by adding a secretGuardian section to your package.json:

{
  "secretGuardian": {
    "mode": "prompt",
    "contact": {
      "name": "Your Name",
      "email": "[email protected]",
      "whatsapp": "+1234567890",
      "country": "Your Country"
    },
    "banner": {
      "enabled": true,
      "message": "Custom installation message"
    }
  }
}

Modes

  • prompt (default): Asks for confirmation when secrets are detected
  • strict: Automatically blocks commits/pushes with secrets

You can also set the mode via environment variable:

export SECRET_GUARDIAN_MODE=strict

🔍 Detected Patterns

Secret Guardian currently detects:

| Pattern | Example | Regex | |---------|---------|-------| | AWS Access Key | AKIAIOSFODNN7EXAMPLE | AKIA[0-9A-Z]{16} | | Private Key | -----BEGIN RSA PRIVATE KEY----- | -----BEGIN (RSA )?PRIVATE KEY----- | | Generic Password | password: "secret123" | password\s*[:=]\s*["'][^"']+["'] | | JWT Token | eyJhbGciOiJIUz... | eyJ[A-Za-z0-9_-]+?\..* | | API Key | api_key: "abcd1234..." | api[_-]?key\s*[:=]\s*["'][A-Za-z0-9-_]{16,}["'] |

🧪 Testing Locally

You can test the scanner manually:

# Install the package
npm install secret-guardian-ts --save-dev

# Create a test file with a secret
echo "AWS_KEY=AKIAIOSFODNN7EXAMPLE" > test.txt

# Stage and try to commit
git add test.txt
git commit -m "test"

# Secret Guardian will detect the AWS key!

🛠️ Development

# Clone the repository
git clone https://github.com/aunjum/secret-guardian-ts.git
cd secret-guardian-ts

# Install dependencies
npm install

# Build
npm run build

# Run tests
npm test

# Run tests in watch mode
npm run test:watch

# Type checking
npm run lint

📝 Scripts

  • npm run build - Compile TypeScript to JavaScript
  • npm test - Run Jest tests
  • npm run test:watch - Run tests in watch mode
  • npm run lint - Run TypeScript type checking
  • npm run prepare - Auto-runs on npm install (builds the project)
  • npm run prepublishOnly - Runs before publishing (builds and tests)

🔧 Manual Hook Installation

If hooks aren't installed automatically, you can install them manually:

npx secret-guardian install-hooks

Or using the Node CLI:

node ./node_modules/secret-guardian-ts/dist/index.js --install-hooks

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

🐛 Known Issues

  • On Windows, you might need to run chmod +x .git/hooks/pre-commit if hooks don't execute
  • Large repositories (>1000 files) might experience slower scan times

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

👤 Author

Tanvir Aunjum

🙏 Acknowledgments

📚 Related Projects

⭐ Show Your Support

If this project helped you, please consider giving it a ⭐️!

📮 Contact

Looking for opportunities! If you have a position or project that needs:

  • TypeScript/JavaScript development
  • Security tooling
  • CLI applications
  • NPM package development

Feel free to reach out!


Made with ❤️ and TypeScript