UNPKG

@estarlincito/utils

Version:

A collection of utility functions designed to simplify and speed up development tasks in JavaScript and TypeScript projects.

63 lines (42 loc) • 1.62 kB
# šŸ“œ Copyright Utility Function The `copyright` function generates a dynamic copyright statement based on the year a project was built and the current year. ## šŸ“Œ Features āœ”ļø Automatically appends the current year to the copyright range. āœ”ļø Prevents invalid build years (greater than the current year). āœ”ļø Simple and reusable for various projects. ## šŸš€ Installation If this utility is part of a package, install it using: ```bash pnpm add @estarlincito/utils # or npm install @estarlincito/utils # or yarn add @estarlincito/utils ``` Then import it into your project: ```ts import { copyright } from '@estarlincito/utils'; ``` ## ⚔ Usage ### Example 1: Standard Copyright Statement ```ts const result = copyright(2022); console.log(result); // Output: "Copyright Ā© 2022-2025" (if current year is 2025) ``` ### Example 2: Single-Year Copyright (Same Build Year & Current Year) ```ts const result = copyright('2025'); console.log(result); // Output: "Copyright Ā© 2025" (if current year is 2025) ``` ### Example 3: Handling an Invalid Year ```ts const result = copyright(2030); // Throws an error if current year is 2025 ``` ## šŸ›  How It Works - The function retrieves the current year. - If the `buildYear` is greater than the current year, it triggers an error using `handleError()`. - If the `buildYear` matches the current year, it returns `"Copyright Ā© {year}"`. - Otherwise, it returns `"Copyright Ā© {buildYear}-{currentYear}"`. ## šŸ“ License This utility is provided under the MIT License. **Author:** Estarlin R ([estarlincito.com](https://estarlincito.com))