1
1
mirror of https://github.com/theoludwig/theoludwig.git synced 2025-05-29 22:37:44 +02:00

perf!: monorepo setup + fully static + webp images

BREAKING CHANGE: minimum supported Node.js >= 22.0.0 and pnpm >= 9.5.0
This commit is contained in:
2024-07-30 23:59:06 +02:00
parent 0f44e64c0c
commit 7bde328b96
336 changed files with 22933 additions and 26923 deletions

View File

@ -0,0 +1,14 @@
{
"root": true,
"extends": ["@repo/eslint-config"],
"overrides": [
{
"files": ["*.ts", "*.tsx"],
"plugins": ["@typescript-eslint"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": true
}
}
]
}

View File

@ -0,0 +1,28 @@
{
"name": "@repo/utils",
"version": "3.3.2",
"private": true,
"type": "module",
"exports": {
"./constants": "./src/constants.ts",
"./dates": "./src/dates.ts",
"./strings": "./src/strings.ts"
},
"scripts": {
"lint:eslint": "eslint src --max-warnings 0 --report-unused-disable-directives",
"lint:typescript": "tsc --noEmit",
"test": "vitest run",
"test:ui": "vitest --ui --no-open"
},
"devDependencies": {
"@repo/eslint-config": "workspace:*",
"@repo/config-typescript": "workspace:*",
"@types/node": "catalog:",
"@total-typescript/ts-reset": "catalog:",
"@vitest/coverage-istanbul": "catalog:",
"@vitest/ui": "catalog:",
"eslint": "catalog:",
"typescript": "catalog:",
"vitest": "catalog:"
}
}

View File

@ -0,0 +1,17 @@
import packageJSON from "../package.json"
export const VERSION =
process.env["NODE_ENV"] === "development"
? "0.0.0-development"
: packageJSON.version
export const GIT_REPO_LINK = "https://github.com/theoludwig/theoludwig"
export const BIRTH_DATE_DAY = "31"
export const BIRTH_DATE_MONTH = "03"
export const BIRTH_DATE_YEAR = "2003"
export const BIRTH_DATE_STRING =
`${BIRTH_DATE_DAY}/${BIRTH_DATE_MONTH}/${BIRTH_DATE_YEAR}` as const
export const BIRTH_DATE_ISO_8601 =
`${BIRTH_DATE_YEAR}-${BIRTH_DATE_MONTH}-${BIRTH_DATE_DAY}` as const
export const BIRTH_DATE = new Date(BIRTH_DATE_ISO_8601)

View File

@ -0,0 +1,24 @@
/**
* Returns a date as a string value in ISO 8601 format (without time information).
*
* @param date
* @returns
* @example getISODate(new Date("2012-05-23")) // "2012-05-23"
*/
export const getISODate = (date: Date): string => {
return date.toISOString().slice(0, 10)
}
/**
* Calculates the age of a person based on their birth date.
* @param birthDate
*/
export const getAge = (birthDate: Date): number => {
const today = new Date()
let age = today.getFullYear() - birthDate.getFullYear()
const month = today.getMonth() - birthDate.getMonth()
if (month < 0 || (month === 0 && today.getDate() < birthDate.getDate())) {
age--
}
return age
}

View File

@ -0,0 +1,3 @@
export const capitalize = (string: string): string => {
return string.charAt(0).toUpperCase() + string.slice(1)
}

View File

@ -0,0 +1,36 @@
import { afterEach, describe, expect, it, vi } from "vitest"
describe("VERSION", () => {
afterEach(() => {
vi.unstubAllEnvs()
vi.resetModules()
vi.restoreAllMocks()
})
it('should return "0.0.0-development" when NODE_ENV is development', async () => {
// Arrange - Given
vi.stubEnv("NODE_ENV", "development")
// Act - When
const { VERSION } = await import("../constants.js")
// Assert - Then
const expected = "0.0.0-development"
expect(VERSION).toEqual(expected)
})
it("should return the version from package.json when NODE_ENV is not development", async () => {
// Arrange - Given
vi.stubEnv("NODE_ENV", "production")
vi.mock("../../package.json", () => {
return { default: { version: "1.0.0" } }
})
// Act - When
const { VERSION } = await import("../constants.js")
// Assert - Then
const expected = "1.0.0"
expect(VERSION).toEqual(expected)
})
})

View File

@ -0,0 +1,79 @@
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"
import { getAge, getISODate } from "../dates.js"
describe("getISODate", () => {
it("should return the correct date in ISO format (e.g: 2012-05-23)", () => {
// Arrange - Given
const input = new Date("2012-05-23")
// Act - When
const output = getISODate(input)
// Assert - Then
const expected = "2012-05-23"
expect(output).toEqual(expected)
})
})
describe("getAge", () => {
beforeEach(() => {
vi.useFakeTimers()
})
afterEach(() => {
vi.useRealTimers()
})
it("should return the correct age based on the birth date", () => {
// Arrange - Given
vi.setSystemTime(new Date("2018-03-20"))
const birthDate = new Date("1980-02-20")
// Act - When
const output = getAge(birthDate)
// Assert - Then
const expected = 38
expect(output).toEqual(expected)
})
it("should return the correct age based on the birth date when the birthday has not happened yet", () => {
// Arrange - Given
vi.setSystemTime(new Date("2018-03-20"))
const birthDate = new Date("1980-07-20")
// Act - When
const output = getAge(birthDate)
// Assert - Then
const expected = 37
expect(output).toEqual(expected)
})
it("should return the correct age based on the birth date when the birthday is today", () => {
// Arrange - Given
vi.setSystemTime(new Date("2018-03-20"))
const birthDate = new Date("1980-03-20")
// Act - When
const output = getAge(birthDate)
// Assert - Then
const expected = 38
expect(output).toEqual(expected)
})
it("should return the correct age based on the birth date when the birthday has not happened yet, but will happen this month", () => {
// Arrange - Given
vi.setSystemTime(new Date("2018-03-20"))
const birthDate = new Date("1980-03-25")
// Act - When
const output = getAge(birthDate)
// Assert - Then
const expected = 37
expect(output).toEqual(expected)
})
})

View File

@ -0,0 +1,41 @@
import { describe, expect, it } from "vitest"
import { capitalize } from "../strings.js"
describe("capitalize", () => {
it("should capitalize the first letter of a string", () => {
// Arrange - Given
const input = "hello, world!"
// Act - When
const output = capitalize(input)
// Assert - Then
const expected = "Hello, world!"
expect(output).toEqual(expected)
})
it("should return an empty string when the input is an empty string", () => {
// Arrange - Given
const input = ""
// Act - When
const output = capitalize(input)
// Assert - Then
const expected = ""
expect(output).toEqual(expected)
})
it("should return the same string when the first letter is already capitalized", () => {
// Arrange - Given
const input = "Hello, world!"
// Act - When
const output = capitalize(input)
// Assert - Then
const expected = "Hello, world!"
expect(output).toEqual(expected)
})
})

View File

@ -0,0 +1,13 @@
{
"extends": "@repo/config-typescript/tsconfig.json",
"compilerOptions": {
"target": "ESNext",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"resolveJsonModule": true,
"lib": ["ESNext"],
"types": ["@types/node", "@total-typescript/ts-reset"],
"noEmit": true
}
}

View File

@ -0,0 +1,10 @@
import { defineConfig } from "vitest/config"
export default defineConfig({
test: {
coverage: {
enabled: true,
provider: "istanbul",
},
},
})