@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
Markdown
The `copyright` function generates a dynamic copyright statement based on the year a project was built and the current year.
āļø 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';
```
```ts
const result = copyright(2022);
console.log(result); // Output: "Copyright Ā© 2022-2025" (if current year is 2025)
```
```ts
const result = copyright('2025');
console.log(result); // Output: "Copyright Ā© 2025" (if current year is 2025)
```
```ts
const result = copyright(2030); // Throws an error if current year is 2025
```
- 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}"`.
This utility is provided under the MIT License.
**Author:** Estarlin R ([estarlincito.com](https://estarlincito.com))