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 🙏

© 2026 – Pkg Stats / Ryan Hefner

replace-hardcoded-domain

v1.0.0

Published

Angular migration tool to replace hardcoded localStorage domain lookups with SiteService injection. Compatible across Angular 8 to 19+ with zero runtime dependencies.

Readme

replace-hardcoded-domain

An automated, zero-dependency Angular migration codemod to replace hardcoded localStorage.getItem('domain') calls with SiteService dependency injection.

Supports all Angular versions from Angular 8 to Angular 19+ with zero external dependencies (ts-morph has been completely eliminated).


🚀 Quick Start (No Installation Needed)

Any developer can run this tool in their Angular project directory with zero installation:

npx replace-hardcoded-domain

Or preview changes safely without writing to disk:

npx replace-hardcoded-domain --dry-run

✨ Features

  • ⚡ Zero Dependencies: No ts-morph, no bloated node_modules, package size is only ~7 KB.
  • 🔄 Universal Compatibility: Works seamlessly with Angular 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19+.
  • 🔍 Smart SiteService Detection:
    1. Automatically checks if SiteService is located at src/app/global/services/site/site.service.
    2. If not found, interactively prompts you in the terminal to paste the path to your SiteService.
    3. You can also bypass the prompt via the --service flag.
  • 🛡️ Preserves Existing Injections: If SiteService is already injected in a constructor under any alias (e.g., private siteSvc: SiteService), it reuses that alias and does not add duplicate parameters or imports.
  • 📐 Clean Formatting & Relative Imports: Automatically computes correct relative imports (e.g. ../../global/services/site/site.service), preserving formatting, single/double quotes, and trailing commas.
  • 🧪 Safe & Dry-Run Capable: Supports --dry-run to simulate and preview modifications before touching any files.

🛠️ How It Works (Before & After)

Before:

import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'app-header',
  templateUrl: './header.component.html'
})
export class HeaderComponent implements OnInit {
  domain: string;

  constructor(
    private router: Router,
    private http: HttpClient
  ) {}

  ngOnInit() {
    this.domain = localStorage.getItem('domain');
  }
}

After:

import { Component, OnInit } from '@angular/core';
import { SiteService } from '../../global/services/site/site.service';

@Component({
  selector: 'app-header',
  templateUrl: './header.component.html'
})
export class HeaderComponent implements OnInit {
  domain: string;

  constructor(
    private router: Router,
    private http: HttpClient,
    private siteService: SiteService
  ) {}

  ngOnInit() {
    this.domain = this.siteService.getDomain();
  }
}

💻 CLI Usage & Options

npx replace-hardcoded-domain [options]

| Option | Shorthand | Description | Default | |---|---|---|---| | --service <path> | -s | Path to SiteService file (bypasses prompt if valid) | src/app/global/services/site/site.service | | --dir <path> | -d | Directory to scan for .ts files | src | | --dry-run | | Simulate and preview changes without modifying files | false | | --verbose | -v | Show detailed skipped files breakdown | false | | --help | -h | Display help menu | | | --version | | Display package version | |

Examples:

# Interactive run (default)
npx replace-hardcoded-domain

# Specify a custom SiteService location directly
npx replace-hardcoded-domain --service src/app/core/services/site.service.ts

# Test run without touching disk
npx replace-hardcoded-domain --dry-run

# Run only on a specific feature directory
npx replace-hardcoded-domain --dir src/app/features/dashboard

📦 Programmatic Usage (Node.js API)

You can also use this library programmatically in your own scripts:

const { runMigration, transformTsContent } = require('replace-hardcoded-domain');

// Run the full migration programmatically
async function main() {
  const result = await runMigration({
    scanDir: 'src',
    servicePath: 'src/app/global/services/site/site.service.ts',
    dryRun: false
  });
  console.log('Modified files:', result.modifiedFiles);
}
main();

🧪 Testing

Run the built-in test suite:

npm test

📄 License

MIT