From 576b98157b87b4821419b142898329d02a74c052 Mon Sep 17 00:00:00 2001 From: m10rten Date: Sun, 18 Aug 2024 15:40:19 +0200 Subject: [PATCH] add basic node example --- examples/i4n-node/main.ts | 30 +++ examples/i4n-node/package.json | 20 ++ examples/i4n-node/pnpm-lock.yaml | 362 +++++++++++++++++++++++++++++++ 3 files changed, 412 insertions(+) create mode 100644 examples/i4n-node/main.ts create mode 100644 examples/i4n-node/package.json create mode 100644 examples/i4n-node/pnpm-lock.yaml diff --git a/examples/i4n-node/main.ts b/examples/i4n-node/main.ts new file mode 100644 index 0000000..f966848 --- /dev/null +++ b/examples/i4n-node/main.ts @@ -0,0 +1,30 @@ +import { I4n } from "i4n"; + +interface LanguageData { + hello: string; + key?: string; +} +type Language = "en" | "nl"; +type TranslationSet = { + [lang in Language]?: LanguageData; +}; + +export const translations = { + en: { + hello: "Hello World!", + key: "Somehow we do", + }, + nl: { + hello: "Hallo Wereld!", + }, +} satisfies TranslationSet; + +const i4n = new I4n({ translations, language: "en", fallbackLanguage: "en" }); + +console.log(i4n.t("hello")); // "Hello" + +console.log("Swapping", i4n.switch("nl")); + +console.log(i4n.t("hello")); + +console.log(i4n.t("key")); diff --git a/examples/i4n-node/package.json b/examples/i4n-node/package.json new file mode 100644 index 0000000..2d6bf21 --- /dev/null +++ b/examples/i4n-node/package.json @@ -0,0 +1,20 @@ +{ + "name": "i4n-node", + "version": "1.0.0", + "description": "", + "main": "main.ts", + "scripts": { + "start": "tsx main.ts" + }, + "keywords": [], + "author": "", + "license": "", + "devDependencies": { + "@types/node": "^22.4.0", + "tsx": "^4.17.0", + "typescript": "^5.5.4" + }, + "dependencies": { + "i4n": "^0.3.2" + } +} diff --git a/examples/i4n-node/pnpm-lock.yaml b/examples/i4n-node/pnpm-lock.yaml new file mode 100644 index 0000000..ab7121a --- /dev/null +++ b/examples/i4n-node/pnpm-lock.yaml @@ -0,0 +1,362 @@ +lockfileVersion: "9.0" + +settings: + autoInstallPeers: true + excludeLinksFromLockfile: false + +importers: + .: + dependencies: + i4n: + specifier: ^0.3.2 + version: 0.3.2 + devDependencies: + "@types/node": + specifier: ^22.4.0 + version: 22.4.0 + tsx: + specifier: ^4.17.0 + version: 4.17.0 + typescript: + specifier: ^5.5.4 + version: 5.5.4 + +packages: + "@esbuild/aix-ppc64@0.23.1": + resolution: + { integrity: sha512-6VhYk1diRqrhBAqpJEdjASR/+WVRtfjpqKuNw11cLiaWpAT/Uu+nokB+UJnevzy/P9C/ty6AOe0dwueMrGh/iQ== } + engines: { node: ">=18" } + cpu: [ppc64] + os: [aix] + + "@esbuild/android-arm64@0.23.1": + resolution: + { integrity: sha512-xw50ipykXcLstLeWH7WRdQuysJqejuAGPd30vd1i5zSyKK3WE+ijzHmLKxdiCMtH1pHz78rOg0BKSYOSB/2Khw== } + engines: { node: ">=18" } + cpu: [arm64] + os: [android] + + "@esbuild/android-arm@0.23.1": + resolution: + { integrity: sha512-uz6/tEy2IFm9RYOyvKl88zdzZfwEfKZmnX9Cj1BHjeSGNuGLuMD1kR8y5bteYmwqKm1tj8m4cb/aKEorr6fHWQ== } + engines: { node: ">=18" } + cpu: [arm] + os: [android] + + "@esbuild/android-x64@0.23.1": + resolution: + { integrity: sha512-nlN9B69St9BwUoB+jkyU090bru8L0NA3yFvAd7k8dNsVH8bi9a8cUAUSEcEEgTp2z3dbEDGJGfP6VUnkQnlReg== } + engines: { node: ">=18" } + cpu: [x64] + os: [android] + + "@esbuild/darwin-arm64@0.23.1": + resolution: + { integrity: sha512-YsS2e3Wtgnw7Wq53XXBLcV6JhRsEq8hkfg91ESVadIrzr9wO6jJDMZnCQbHm1Guc5t/CdDiFSSfWP58FNuvT3Q== } + engines: { node: ">=18" } + cpu: [arm64] + os: [darwin] + + "@esbuild/darwin-x64@0.23.1": + resolution: + { integrity: sha512-aClqdgTDVPSEGgoCS8QDG37Gu8yc9lTHNAQlsztQ6ENetKEO//b8y31MMu2ZaPbn4kVsIABzVLXYLhCGekGDqw== } + engines: { node: ">=18" } + cpu: [x64] + os: [darwin] + + "@esbuild/freebsd-arm64@0.23.1": + resolution: + { integrity: sha512-h1k6yS8/pN/NHlMl5+v4XPfikhJulk4G+tKGFIOwURBSFzE8bixw1ebjluLOjfwtLqY0kewfjLSrO6tN2MgIhA== } + engines: { node: ">=18" } + cpu: [arm64] + os: [freebsd] + + "@esbuild/freebsd-x64@0.23.1": + resolution: + { integrity: sha512-lK1eJeyk1ZX8UklqFd/3A60UuZ/6UVfGT2LuGo3Wp4/z7eRTRYY+0xOu2kpClP+vMTi9wKOfXi2vjUpO1Ro76g== } + engines: { node: ">=18" } + cpu: [x64] + os: [freebsd] + + "@esbuild/linux-arm64@0.23.1": + resolution: + { integrity: sha512-/93bf2yxencYDnItMYV/v116zff6UyTjo4EtEQjUBeGiVpMmffDNUyD9UN2zV+V3LRV3/on4xdZ26NKzn6754g== } + engines: { node: ">=18" } + cpu: [arm64] + os: [linux] + + "@esbuild/linux-arm@0.23.1": + resolution: + { integrity: sha512-CXXkzgn+dXAPs3WBwE+Kvnrf4WECwBdfjfeYHpMeVxWE0EceB6vhWGShs6wi0IYEqMSIzdOF1XjQ/Mkm5d7ZdQ== } + engines: { node: ">=18" } + cpu: [arm] + os: [linux] + + "@esbuild/linux-ia32@0.23.1": + resolution: + { integrity: sha512-VTN4EuOHwXEkXzX5nTvVY4s7E/Krz7COC8xkftbbKRYAl96vPiUssGkeMELQMOnLOJ8k3BY1+ZY52tttZnHcXQ== } + engines: { node: ">=18" } + cpu: [ia32] + os: [linux] + + "@esbuild/linux-loong64@0.23.1": + resolution: + { integrity: sha512-Vx09LzEoBa5zDnieH8LSMRToj7ir/Jeq0Gu6qJ/1GcBq9GkfoEAoXvLiW1U9J1qE/Y/Oyaq33w5p2ZWrNNHNEw== } + engines: { node: ">=18" } + cpu: [loong64] + os: [linux] + + "@esbuild/linux-mips64el@0.23.1": + resolution: + { integrity: sha512-nrFzzMQ7W4WRLNUOU5dlWAqa6yVeI0P78WKGUo7lg2HShq/yx+UYkeNSE0SSfSure0SqgnsxPvmAUu/vu0E+3Q== } + engines: { node: ">=18" } + cpu: [mips64el] + os: [linux] + + "@esbuild/linux-ppc64@0.23.1": + resolution: + { integrity: sha512-dKN8fgVqd0vUIjxuJI6P/9SSSe/mB9rvA98CSH2sJnlZ/OCZWO1DJvxj8jvKTfYUdGfcq2dDxoKaC6bHuTlgcw== } + engines: { node: ">=18" } + cpu: [ppc64] + os: [linux] + + "@esbuild/linux-riscv64@0.23.1": + resolution: + { integrity: sha512-5AV4Pzp80fhHL83JM6LoA6pTQVWgB1HovMBsLQ9OZWLDqVY8MVobBXNSmAJi//Csh6tcY7e7Lny2Hg1tElMjIA== } + engines: { node: ">=18" } + cpu: [riscv64] + os: [linux] + + "@esbuild/linux-s390x@0.23.1": + resolution: + { integrity: sha512-9ygs73tuFCe6f6m/Tb+9LtYxWR4c9yg7zjt2cYkjDbDpV/xVn+68cQxMXCjUpYwEkze2RcU/rMnfIXNRFmSoDw== } + engines: { node: ">=18" } + cpu: [s390x] + os: [linux] + + "@esbuild/linux-x64@0.23.1": + resolution: + { integrity: sha512-EV6+ovTsEXCPAp58g2dD68LxoP/wK5pRvgy0J/HxPGB009omFPv3Yet0HiaqvrIrgPTBuC6wCH1LTOY91EO5hQ== } + engines: { node: ">=18" } + cpu: [x64] + os: [linux] + + "@esbuild/netbsd-x64@0.23.1": + resolution: + { integrity: sha512-aevEkCNu7KlPRpYLjwmdcuNz6bDFiE7Z8XC4CPqExjTvrHugh28QzUXVOZtiYghciKUacNktqxdpymplil1beA== } + engines: { node: ">=18" } + cpu: [x64] + os: [netbsd] + + "@esbuild/openbsd-arm64@0.23.1": + resolution: + { integrity: sha512-3x37szhLexNA4bXhLrCC/LImN/YtWis6WXr1VESlfVtVeoFJBRINPJ3f0a/6LV8zpikqoUg4hyXw0sFBt5Cr+Q== } + engines: { node: ">=18" } + cpu: [arm64] + os: [openbsd] + + "@esbuild/openbsd-x64@0.23.1": + resolution: + { integrity: sha512-aY2gMmKmPhxfU+0EdnN+XNtGbjfQgwZj43k8G3fyrDM/UdZww6xrWxmDkuz2eCZchqVeABjV5BpildOrUbBTqA== } + engines: { node: ">=18" } + cpu: [x64] + os: [openbsd] + + "@esbuild/sunos-x64@0.23.1": + resolution: + { integrity: sha512-RBRT2gqEl0IKQABT4XTj78tpk9v7ehp+mazn2HbUeZl1YMdaGAQqhapjGTCe7uw7y0frDi4gS0uHzhvpFuI1sA== } + engines: { node: ">=18" } + cpu: [x64] + os: [sunos] + + "@esbuild/win32-arm64@0.23.1": + resolution: + { integrity: sha512-4O+gPR5rEBe2FpKOVyiJ7wNDPA8nGzDuJ6gN4okSA1gEOYZ67N8JPk58tkWtdtPeLz7lBnY6I5L3jdsr3S+A6A== } + engines: { node: ">=18" } + cpu: [arm64] + os: [win32] + + "@esbuild/win32-ia32@0.23.1": + resolution: + { integrity: sha512-BcaL0Vn6QwCwre3Y717nVHZbAa4UBEigzFm6VdsVdT/MbZ38xoj1X9HPkZhbmaBGUD1W8vxAfffbDe8bA6AKnQ== } + engines: { node: ">=18" } + cpu: [ia32] + os: [win32] + + "@esbuild/win32-x64@0.23.1": + resolution: + { integrity: sha512-BHpFFeslkWrXWyUPnbKm+xYYVYruCinGcftSBaa8zoF9hZO4BcSCFUvHVTtzpIY6YzUnYtuEhZ+C9iEXjxnasg== } + engines: { node: ">=18" } + cpu: [x64] + os: [win32] + + "@types/node@22.4.0": + resolution: + { integrity: sha512-49AbMDwYUz7EXxKU/r7mXOsxwFr4BYbvB7tWYxVuLdb2ibd30ijjXINSMAHiEEZk5PCRBmW1gUeisn2VMKt3cQ== } + + esbuild@0.23.1: + resolution: + { integrity: sha512-VVNz/9Sa0bs5SELtn3f7qhJCDPCF5oMEl5cO9/SSinpE9hbPVvxbd572HH5AKiP7WD8INO53GgfDDhRjkylHEg== } + engines: { node: ">=18" } + hasBin: true + + fsevents@2.3.3: + resolution: + { integrity: sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw== } + engines: { node: ^8.16.0 || ^10.6.0 || >=11.0.0 } + os: [darwin] + + get-tsconfig@4.7.6: + resolution: + { integrity: sha512-ZAqrLlu18NbDdRaHq+AKXzAmqIUPswPWKUchfytdAjiRFnCe5ojG2bstg6mRiZabkKfCoL/e98pbBELIV/YCeA== } + + i4n@0.3.2: + resolution: + { integrity: sha512-rw074HCtfTNqFoogQ2Yg2ESAZbydBcTfn4R9R7vjhWovQgH9eyOWfRtUi5ScEvlVG7RjdNHEh+EEqxTBmUvTfQ== } + engines: { node: ">=20.11.x < 22.x" } + + resolve-pkg-maps@1.0.0: + resolution: + { integrity: sha512-seS2Tj26TBVOC2NIc2rOe2y2ZO7efxITtLZcGSOnHHNOQ7CkiUBfw0Iw2ck6xkIhPwLhKNLS8BO+hEpngQlqzw== } + + tsx@4.17.0: + resolution: + { integrity: sha512-eN4mnDA5UMKDt4YZixo9tBioibaMBpoxBkD+rIPAjVmYERSG0/dWEY1CEFuV89CgASlKL499q8AhmkMnnjtOJg== } + engines: { node: ">=18.0.0" } + hasBin: true + + typescript@5.5.4: + resolution: + { integrity: sha512-Mtq29sKDAEYP7aljRgtPOpTvOfbwRWlS6dPRzwjdE+C0R4brX/GUyhHSecbHMFLNBLcJIPt9nl9yG5TZ1weH+Q== } + engines: { node: ">=14.17" } + hasBin: true + + undici-types@6.19.6: + resolution: + { integrity: sha512-e/vggGopEfTKSvj4ihnOLTsqhrKRN3LeO6qSN/GxohhuRv8qH9bNQ4B8W7e/vFL+0XTnmHPB4/kegunZGA4Org== } + +snapshots: + "@esbuild/aix-ppc64@0.23.1": + optional: true + + "@esbuild/android-arm64@0.23.1": + optional: true + + "@esbuild/android-arm@0.23.1": + optional: true + + "@esbuild/android-x64@0.23.1": + optional: true + + "@esbuild/darwin-arm64@0.23.1": + optional: true + + "@esbuild/darwin-x64@0.23.1": + optional: true + + "@esbuild/freebsd-arm64@0.23.1": + optional: true + + "@esbuild/freebsd-x64@0.23.1": + optional: true + + "@esbuild/linux-arm64@0.23.1": + optional: true + + "@esbuild/linux-arm@0.23.1": + optional: true + + "@esbuild/linux-ia32@0.23.1": + optional: true + + "@esbuild/linux-loong64@0.23.1": + optional: true + + "@esbuild/linux-mips64el@0.23.1": + optional: true + + "@esbuild/linux-ppc64@0.23.1": + optional: true + + "@esbuild/linux-riscv64@0.23.1": + optional: true + + "@esbuild/linux-s390x@0.23.1": + optional: true + + "@esbuild/linux-x64@0.23.1": + optional: true + + "@esbuild/netbsd-x64@0.23.1": + optional: true + + "@esbuild/openbsd-arm64@0.23.1": + optional: true + + "@esbuild/openbsd-x64@0.23.1": + optional: true + + "@esbuild/sunos-x64@0.23.1": + optional: true + + "@esbuild/win32-arm64@0.23.1": + optional: true + + "@esbuild/win32-ia32@0.23.1": + optional: true + + "@esbuild/win32-x64@0.23.1": + optional: true + + "@types/node@22.4.0": + dependencies: + undici-types: 6.19.6 + + esbuild@0.23.1: + optionalDependencies: + "@esbuild/aix-ppc64": 0.23.1 + "@esbuild/android-arm": 0.23.1 + "@esbuild/android-arm64": 0.23.1 + "@esbuild/android-x64": 0.23.1 + "@esbuild/darwin-arm64": 0.23.1 + "@esbuild/darwin-x64": 0.23.1 + "@esbuild/freebsd-arm64": 0.23.1 + "@esbuild/freebsd-x64": 0.23.1 + "@esbuild/linux-arm": 0.23.1 + "@esbuild/linux-arm64": 0.23.1 + "@esbuild/linux-ia32": 0.23.1 + "@esbuild/linux-loong64": 0.23.1 + "@esbuild/linux-mips64el": 0.23.1 + "@esbuild/linux-ppc64": 0.23.1 + "@esbuild/linux-riscv64": 0.23.1 + "@esbuild/linux-s390x": 0.23.1 + "@esbuild/linux-x64": 0.23.1 + "@esbuild/netbsd-x64": 0.23.1 + "@esbuild/openbsd-arm64": 0.23.1 + "@esbuild/openbsd-x64": 0.23.1 + "@esbuild/sunos-x64": 0.23.1 + "@esbuild/win32-arm64": 0.23.1 + "@esbuild/win32-ia32": 0.23.1 + "@esbuild/win32-x64": 0.23.1 + + fsevents@2.3.3: + optional: true + + get-tsconfig@4.7.6: + dependencies: + resolve-pkg-maps: 1.0.0 + + i4n@0.3.2: {} + + resolve-pkg-maps@1.0.0: {} + + tsx@4.17.0: + dependencies: + esbuild: 0.23.1 + get-tsconfig: 4.7.6 + optionalDependencies: + fsevents: 2.3.3 + + typescript@5.5.4: {} + + undici-types@6.19.6: {}