Migrate to npm-workspaces monorepo (#294)

* spec update

* update md files

* add plan: monorepo

* feat: add empty apps and packages directories

* Add shared tsconfig.base.json

* feat add workspaces

* feat: move hudozka-writer into apps/

* feat: move migrate-to-pocketbase into apps/

* feat: split package.json for apps/hudozka workspace

* feat: extend tsconfig.base.json in apps/hudozka

* add dockerfile path

* feat: verify Phase 3 monorepo migration of Next app

* feat: scaffold @hudozka/utils package

* feat: add utils barrel export

* feat: extract utilities into hudozka-utils package

* feat: extract hooks into hudozka-hooks package

* Extract Box/Button/Panel/Title/Overlay into @hudozka/ui

* Scope Next ESLint rules to apps/hudozka in root flat config

* Update README and CLAUDE.md for monorepo layout

* disable image optimisation
This commit is contained in:
tmshv authored and GitHub committed 2026-04-25 01:33:06 +03:00
1 parent 0665fa7ae7
commit f874b58dd9
258 files changed
+3793 -214

No files matched your search

+37
View File
@@ -0,0 +1,37 @@
import { describe, it, expect } from "vitest"
import { insertBetween, tail } from "./array"
describe("insertBetween", () => {
it("should return empty array for empty input", () => {
expect(insertBetween([], () => ",")).toEqual([])
})
it("should return single item without separator", () => {
expect(insertBetween(["a"], () => ",")).toEqual(["a"])
})
it("should insert separators between items", () => {
expect(insertBetween(["a", "b", "c"], () => ",")).toEqual([
"a", ",", "b", ",", "c",
])
})
it("should pass index to separator function", () => {
const result = insertBetween(["a", "b", "c"], (i) => i)
expect(result).toEqual(["a", 0, "b", 1, "c"])
})
})
describe("tail", () => {
it("should return empty array for empty input", () => {
expect(tail([])).toEqual([])
})
it("should return empty array for single item", () => {
expect(tail(["a"])).toEqual([])
})
it("should return all items except first", () => {
expect(tail([1, 2, 3])).toEqual([2, 3])
})
})
+19
View File
@@ -0,0 +1,19 @@
export type InsertBetweenFunction<T> = (i: number) => T
export function insertBetween<T, I = T>(items: T[], fn: InsertBetweenFunction<I>): Array<T | I> {
return items.reduce<Array<T | I>>((acc, x, i) => {
acc.push(x)
if (i < items.length - 1) {
acc.push(fn(i))
}
return acc
}, [])
}
export function tail<T>(items: T[]): T[] {
const [_, ...rest] = items
return rest
}
+14
View File
@@ -0,0 +1,14 @@
import { describe, it, expect } from "vitest"
import { dateFormat } from "./date"
describe("dateFormat", () => {
it("should format a Date object in Russian locale", () => {
const result = dateFormat(new Date(2024, 0, 15))
expect(result).toBe("15 января 2024")
})
it("should format a date string in Russian locale", () => {
const result = dateFormat("2024-06-01T00:00:00.000Z")
expect(result).toBe("1 июня 2024")
})
})
+15
View File
@@ -0,0 +1,15 @@
import { format } from "date-fns/format"
import { ru } from "date-fns/locale"
/**
*
* Date -> D MMMM yyyy
*
* @param date
*/
export const dateFormat = (date: string | Date) => {
const value = typeof date === "string" ? new Date(date) : date
return format(value, "d MMMM yyyy", {
locale: ru,
})
}
+51
View File
@@ -0,0 +1,51 @@
import { describe, it, expect } from "vitest"
import { ext, size } from "./file"
describe("ext", () => {
it("should return ПДФ for application/pdf", () => {
expect(ext("application/pdf")).toBe("ПДФ")
})
it("should return ЖПГ for image/jpeg", () => {
expect(ext("image/jpeg")).toBe("ЖПГ")
})
it("should return ПНГ for image/png", () => {
expect(ext("image/png")).toBe("ПНГ")
})
it("should return raw MIME type for unknown types", () => {
expect(ext("text/plain")).toBe("text/plain")
})
})
describe("size", () => {
it("should return empty string for NaN", () => {
expect(size(NaN)).toBe("")
})
it("should return empty string for non-finite values", () => {
expect(size(Infinity)).toBe("")
expect(size(-Infinity)).toBe("")
})
it("should format bytes", () => {
expect(size(500)).toBe("500.0 байт")
})
it("should format kilobytes", () => {
expect(size(1024)).toBe("1.0 КБ")
})
it("should format megabytes", () => {
expect(size(1024 * 1024)).toBe("1.0 МБ")
})
it("should format gigabytes", () => {
expect(size(1024 * 1024 * 1024)).toBe("1.0 ГБ")
})
it("should respect precision parameter", () => {
expect(size(1536, 2)).toBe("1.50 КБ")
})
})
+24
View File
@@ -0,0 +1,24 @@
const units = ["байт", "КБ", "МБ", "ГБ", "ТБ", "ПБ"]
const mime = new Map([
["application/pdf", "ПДФ"],
["image/jpeg", "ЖПГ"],
["image/png", "ПНГ"],
])
export function ext(mimeType: string): string {
if (mime.has(mimeType)) {
return mime.get(mimeType)!
}
return mimeType
}
export function size(bytes: number, precision = 1): string {
if (Number.isNaN(bytes) || !Number.isFinite(bytes)) return ""
const number = Math.floor(Math.log(bytes) / Math.log(1024))
const size = (bytes / Math.pow(1024, Math.floor(number))).toFixed(precision)
return `${size} ${units[number]}`
}
+25
View File
@@ -0,0 +1,25 @@
import { describe, it, expect } from "vitest"
import { getResizedUrl } from "./image"
describe("getResizedUrl", () => {
it("should construct resize URL with default n", () => {
const result = getResizedUrl("example.com/img.jpg", {
width: 800,
height: 600,
})
expect(result).toBe(
"https://images.weserv.nl/?url=example.com/img.jpg&w=800&h=600&n=1",
)
})
it("should use custom n parameter", () => {
const result = getResizedUrl("example.com/img.jpg", {
width: 400,
height: 300,
n: -1,
})
expect(result).toBe(
"https://images.weserv.nl/?url=example.com/img.jpg&w=400&h=300&n=-1",
)
})
})
+11
View File
@@ -0,0 +1,11 @@
export type ResizeOptions = {
width: number
height: number
n?: number
}
export function getResizedUrl(src: string, options: ResizeOptions): string {
const n = options.n ?? 1
return `https://images.weserv.nl/?url=${src}&w=${options.width}&h=${options.height}&n=${n}`
}
+7
View File
@@ -0,0 +1,7 @@
export * from "./array"
export * from "./string"
export * from "./url"
export * from "./math"
export * from "./image"
export * from "./file"
export * from "./date"
+30
View File
@@ -0,0 +1,30 @@
import { describe, it, expect } from "vitest"
import { clamp } from "./math"
describe("clamp", () => {
it("should return value when within range", () => {
expect(clamp(5, 0, 10)).toBe(5)
})
it("should return min when value is below range", () => {
expect(clamp(-1, 0, 10)).toBe(0)
})
it("should return max when value is above range", () => {
expect(clamp(15, 0, 10)).toBe(10)
})
it("should return min when value equals min", () => {
expect(clamp(0, 0, 10)).toBe(0)
})
it("should return max when value equals max", () => {
expect(clamp(10, 0, 10)).toBe(10)
})
it("should work with negative ranges", () => {
expect(clamp(-5, -10, -1)).toBe(-5)
expect(clamp(-15, -10, -1)).toBe(-10)
expect(clamp(0, -10, -1)).toBe(-1)
})
})
+9
View File
@@ -0,0 +1,9 @@
export function clamp(val: number, min: number, max: number): number {
if (val < min) {
return min
}
if (val > max) {
return max
}
return val
}
+20
View File
@@ -0,0 +1,20 @@
import { describe, it, expect } from "vitest"
import { titleCase } from "./string"
describe("titleCase", () => {
it("should capitalize first letter of lowercase string", () => {
expect(titleCase("hello")).toBe("Hello")
})
it("should keep already capitalized string", () => {
expect(titleCase("Hello")).toBe("Hello")
})
it("should handle empty string", () => {
expect(titleCase("")).toBe("")
})
it("should capitalize single character", () => {
expect(titleCase("a")).toBe("A")
})
})
+3
View File
@@ -0,0 +1,3 @@
export function titleCase(str: string) {
return str.charAt(0).toUpperCase() + str.slice(1)
}
+18
View File
@@ -0,0 +1,18 @@
import { describe, it, expect } from "vitest"
import { queryList } from "./url"
describe("queryList", () => {
it("should return empty string for empty values", () => {
expect(queryList("tag", [])).toBe("")
})
it("should return single key=value pair", () => {
expect(queryList("tag", ["art"])).toBe("tag=art")
})
it("should join multiple values with &", () => {
expect(queryList("tag", ["art", "music", "photo"])).toBe(
"tag=art&tag=music&tag=photo",
)
})
})
+9
View File
@@ -0,0 +1,9 @@
export function queryList(key: string, values: string[]): string {
if (values.length === 0) {
return ""
}
return values
.map(value => `${key}=${value}`)
.join("&")
}