Action

Type

Resolved On

Move slugging function to str.ts to eliminate duplication refactoring - - -

Move slugging function to str.ts to eliminate duplication

Description

The slugging function is duplicated in both monthly.ts and yearly.ts. Move it to src/lib/str.ts which already contains string utilities.

Current Duplication

src/lib/monthly.ts:310-312

function slugging(str: string) {
  return String(str).replaceAll(".", "-").replaceAll(" ", "-").toLowerCase();
}

src/lib/yearly.ts:105-107

function slugging(str: string) {
  return String(str).replaceAll(".", "-").replaceAll(" ", "-").toLowerCase();
}

Solution

  1. Add to src/lib/str.ts:
export function slugging(str: string): string {
  return String(str).replaceAll(".", "-").replaceAll(" ", "-").toLowerCase();
}
  1. Update monthly.ts:
import { slugging } from "./str";
// Remove local function definition
  1. Update yearly.ts:
import { slugging } from "../str";
// Remove local function definition

Affected Files

  • src/lib/str.ts (add function)
  • src/lib/monthly.ts (import and remove local)
  • src/lib/yearly.ts (import and remove local)