katanakit-js 2.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +96 -0
- package/LICENSE +22 -0
- package/README.md +446 -0
- package/dist/adapters/astro/astro.service.d.ts +18 -0
- package/dist/adapters/astro/astro.service.d.ts.map +1 -0
- package/dist/adapters/astro/astro.service.js +83 -0
- package/dist/adapters/astro/astro.service.js.map +1 -0
- package/dist/adapters/astro/index.d.ts +4 -0
- package/dist/adapters/astro/index.d.ts.map +1 -0
- package/dist/adapters/astro/index.js +4 -0
- package/dist/adapters/astro/index.js.map +1 -0
- package/dist/adapters/astro/rss.service.d.ts +115 -0
- package/dist/adapters/astro/rss.service.d.ts.map +1 -0
- package/dist/adapters/astro/rss.service.js +231 -0
- package/dist/adapters/astro/rss.service.js.map +1 -0
- package/dist/adapters/express/app.d.ts +4 -0
- package/dist/adapters/express/app.d.ts.map +1 -0
- package/dist/adapters/express/app.js +4 -0
- package/dist/adapters/express/app.js.map +1 -0
- package/dist/adapters/express/index.d.ts +5 -0
- package/dist/adapters/express/index.d.ts.map +1 -0
- package/dist/adapters/express/index.js +5 -0
- package/dist/adapters/express/index.js.map +1 -0
- package/dist/adapters/express/main.d.ts +2 -0
- package/dist/adapters/express/main.d.ts.map +1 -0
- package/dist/adapters/express/main.js +3 -0
- package/dist/adapters/express/main.js.map +1 -0
- package/dist/adapters/express/products.controller.d.ts +10 -0
- package/dist/adapters/express/products.controller.d.ts.map +1 -0
- package/dist/adapters/express/products.controller.js +53 -0
- package/dist/adapters/express/products.controller.js.map +1 -0
- package/dist/adapters/express/router.d.ts +3 -0
- package/dist/adapters/express/router.d.ts.map +1 -0
- package/dist/adapters/express/router.js +14 -0
- package/dist/adapters/express/router.js.map +1 -0
- package/dist/adapters/express/server.d.ts +15 -0
- package/dist/adapters/express/server.d.ts.map +1 -0
- package/dist/adapters/express/server.js +59 -0
- package/dist/adapters/express/server.js.map +1 -0
- package/dist/adapters/index.d.ts +2 -0
- package/dist/adapters/index.d.ts.map +1 -0
- package/dist/adapters/index.js +2 -0
- package/dist/adapters/index.js.map +1 -0
- package/dist/adapters/nuxt/index.d.ts +2 -0
- package/dist/adapters/nuxt/index.d.ts.map +1 -0
- package/dist/adapters/nuxt/index.js +2 -0
- package/dist/adapters/nuxt/index.js.map +1 -0
- package/dist/adapters/nuxt/nuxt.service.d.ts +83 -0
- package/dist/adapters/nuxt/nuxt.service.d.ts.map +1 -0
- package/dist/adapters/nuxt/nuxt.service.js +104 -0
- package/dist/adapters/nuxt/nuxt.service.js.map +1 -0
- package/dist/config/index.d.ts +3 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +3 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/seo.service.d.ts +72 -0
- package/dist/config/seo.service.d.ts.map +1 -0
- package/dist/config/seo.service.js +190 -0
- package/dist/config/seo.service.js.map +1 -0
- package/dist/config/site.config.d.ts +89 -0
- package/dist/config/site.config.d.ts.map +1 -0
- package/dist/config/site.config.js +59 -0
- package/dist/config/site.config.js.map +1 -0
- package/dist/core/index.d.ts +13 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +13 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/services/dates.service.d.ts +24 -0
- package/dist/core/services/dates.service.d.ts.map +1 -0
- package/dist/core/services/dates.service.js +64 -0
- package/dist/core/services/dates.service.js.map +1 -0
- package/dist/core/services/error.service.d.ts +25 -0
- package/dist/core/services/error.service.d.ts.map +1 -0
- package/dist/core/services/error.service.js +39 -0
- package/dist/core/services/error.service.js.map +1 -0
- package/dist/core/services/formatter.service.d.ts +36 -0
- package/dist/core/services/formatter.service.d.ts.map +1 -0
- package/dist/core/services/formatter.service.js +64 -0
- package/dist/core/services/formatter.service.js.map +1 -0
- package/dist/core/services/generator.service.d.ts +34 -0
- package/dist/core/services/generator.service.d.ts.map +1 -0
- package/dist/core/services/generator.service.js +83 -0
- package/dist/core/services/generator.service.js.map +1 -0
- package/dist/core/services/geometry.service.d.ts +45 -0
- package/dist/core/services/geometry.service.d.ts.map +1 -0
- package/dist/core/services/geometry.service.js +100 -0
- package/dist/core/services/geometry.service.js.map +1 -0
- package/dist/core/services/http.service.d.ts +22 -0
- package/dist/core/services/http.service.d.ts.map +1 -0
- package/dist/core/services/http.service.js +124 -0
- package/dist/core/services/http.service.js.map +1 -0
- package/dist/core/services/logger.service.d.ts +36 -0
- package/dist/core/services/logger.service.d.ts.map +1 -0
- package/dist/core/services/logger.service.js +60 -0
- package/dist/core/services/logger.service.js.map +1 -0
- package/dist/core/services/reactive.service.d.ts +22 -0
- package/dist/core/services/reactive.service.d.ts.map +1 -0
- package/dist/core/services/reactive.service.js +167 -0
- package/dist/core/services/reactive.service.js.map +1 -0
- package/dist/core/services/timing.service.d.ts +23 -0
- package/dist/core/services/timing.service.d.ts.map +1 -0
- package/dist/core/services/timing.service.js +217 -0
- package/dist/core/services/timing.service.js.map +1 -0
- package/dist/core/services/utils.service.d.ts +44 -0
- package/dist/core/services/utils.service.d.ts.map +1 -0
- package/dist/core/services/utils.service.js +143 -0
- package/dist/core/services/utils.service.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/infrastructure/dom/dom.service.d.ts +49 -0
- package/dist/infrastructure/dom/dom.service.d.ts.map +1 -0
- package/dist/infrastructure/dom/dom.service.js +133 -0
- package/dist/infrastructure/dom/dom.service.js.map +1 -0
- package/dist/infrastructure/index.d.ts +11 -0
- package/dist/infrastructure/index.d.ts.map +1 -0
- package/dist/infrastructure/index.js +11 -0
- package/dist/infrastructure/index.js.map +1 -0
- package/dist/infrastructure/observer/observer.service.d.ts +34 -0
- package/dist/infrastructure/observer/observer.service.d.ts.map +1 -0
- package/dist/infrastructure/observer/observer.service.js +145 -0
- package/dist/infrastructure/observer/observer.service.js.map +1 -0
- package/dist/infrastructure/sensors/sensors.service.d.ts +25 -0
- package/dist/infrastructure/sensors/sensors.service.d.ts.map +1 -0
- package/dist/infrastructure/sensors/sensors.service.js +133 -0
- package/dist/infrastructure/sensors/sensors.service.js.map +1 -0
- package/dist/infrastructure/storage/storage.service.d.ts +48 -0
- package/dist/infrastructure/storage/storage.service.d.ts.map +1 -0
- package/dist/infrastructure/storage/storage.service.js +108 -0
- package/dist/infrastructure/storage/storage.service.js.map +1 -0
- package/dist/infrastructure/theme/theme.service.d.ts +30 -0
- package/dist/infrastructure/theme/theme.service.d.ts.map +1 -0
- package/dist/infrastructure/theme/theme.service.js +104 -0
- package/dist/infrastructure/theme/theme.service.js.map +1 -0
- package/dist/infrastructure/viewport/viewport.service.d.ts +38 -0
- package/dist/infrastructure/viewport/viewport.service.d.ts.map +1 -0
- package/dist/infrastructure/viewport/viewport.service.js +145 -0
- package/dist/infrastructure/viewport/viewport.service.js.map +1 -0
- package/dist/infrastructure/worker/worker.service.d.ts +42 -0
- package/dist/infrastructure/worker/worker.service.d.ts.map +1 -0
- package/dist/infrastructure/worker/worker.service.js +151 -0
- package/dist/infrastructure/worker/worker.service.js.map +1 -0
- package/dist/prisma/db.d.ts +4 -0
- package/dist/prisma/db.d.ts.map +1 -0
- package/dist/prisma/db.js +12 -0
- package/dist/prisma/db.js.map +1 -0
- package/dist/prisma/schema.json +411 -0
- package/dist/types/index.d.ts +436 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +2 -0
- package/dist/types/index.js.map +1 -0
- package/package.json +117 -0
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Site-wide configuration for KatanaKit-powered Astro projects.
|
|
3
|
+
*
|
|
4
|
+
* Import this in your layouts, RSS endpoint, and SEO components
|
|
5
|
+
* to keep everything consistent.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* // astro.config.mjs
|
|
10
|
+
* import { siteConfig } from "./src/config/site.config.js";
|
|
11
|
+
* export default defineConfig({ site: siteConfig.site });
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* Default site configuration. Override in your project.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* // src/config/site.config.ts
|
|
20
|
+
* import { type SiteConfig } from "katanakit";
|
|
21
|
+
*
|
|
22
|
+
* export const siteConfig: SiteConfig = {
|
|
23
|
+
* site: "https://myblog.com",
|
|
24
|
+
* title: "My Blog",
|
|
25
|
+
* description: "A blog about TypeScript",
|
|
26
|
+
* lang: "en",
|
|
27
|
+
* author: "John Doe",
|
|
28
|
+
* ogImage: "/og-default.png",
|
|
29
|
+
* twitter: "johndoe",
|
|
30
|
+
* rss: { enabled: true, path: "/rss.xml", limit: 20 },
|
|
31
|
+
* seo: { noindex: false, canonical: true, openGraph: true, twitterCard: true, jsonLd: true },
|
|
32
|
+
* nav: [
|
|
33
|
+
* { label: "Home", href: "/" },
|
|
34
|
+
* { label: "Blog", href: "/blog" },
|
|
35
|
+
* { label: "GitHub", href: "https://github.com/...", external: true },
|
|
36
|
+
* ],
|
|
37
|
+
* };
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export const siteConfig = {
|
|
41
|
+
site: "https://example.com",
|
|
42
|
+
title: "My Site",
|
|
43
|
+
description: "A site built with KatanaKit and Astro",
|
|
44
|
+
lang: "en",
|
|
45
|
+
author: "Author",
|
|
46
|
+
rss: {
|
|
47
|
+
enabled: true,
|
|
48
|
+
path: "/rss.xml",
|
|
49
|
+
limit: 20,
|
|
50
|
+
},
|
|
51
|
+
seo: {
|
|
52
|
+
noindex: false,
|
|
53
|
+
canonical: true,
|
|
54
|
+
openGraph: true,
|
|
55
|
+
twitterCard: true,
|
|
56
|
+
jsonLd: true,
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
//# sourceMappingURL=site.config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"site.config.js","sourceRoot":"","sources":["../../src/config/site.config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAmDH;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,CAAC,MAAM,UAAU,GAAe;IACrC,IAAI,EAAE,qBAAqB;IAC3B,KAAK,EAAE,SAAS;IAChB,WAAW,EAAE,uCAAuC;IACpD,IAAI,EAAE,IAAI;IACV,MAAM,EAAE,QAAQ;IAChB,GAAG,EAAE;QACJ,OAAO,EAAE,IAAI;QACb,IAAI,EAAE,UAAU;QAChB,KAAK,EAAE,EAAE;KACT;IACD,GAAG,EAAE;QACJ,OAAO,EAAE,KAAK;QACd,SAAS,EAAE,IAAI;QACf,SAAS,EAAE,IAAI;QACf,WAAW,EAAE,IAAI;QACjB,MAAM,EAAE,IAAI;KACZ;CACD,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export * from "./services/error.service.js";
|
|
2
|
+
export * from "./services/formatter.service.js";
|
|
3
|
+
export * from "./services/generator.service.js";
|
|
4
|
+
export { default as GeneratorService } from "./services/generator.service.js";
|
|
5
|
+
export * from "./services/geometry.service.js";
|
|
6
|
+
export * from "./services/http.service.js";
|
|
7
|
+
export * from "./services/logger.service.js";
|
|
8
|
+
export * from "./services/reactive.service.js";
|
|
9
|
+
export { default as ReactiveService } from "./services/reactive.service.js";
|
|
10
|
+
export * from "./services/timing.service.js";
|
|
11
|
+
export { default as TimingService } from "./services/timing.service.js";
|
|
12
|
+
export * from "./services/utils.service.js";
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,cAAc,6BAA6B,CAAC;AAC5C,cAAc,iCAAiC,CAAC;AAChD,cAAc,iCAAiC,CAAC;AAChD,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AAC9E,cAAc,gCAAgC,CAAC;AAC/C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,gCAAgC,CAAC;AAC/C,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,gCAAgC,CAAC;AAC5E,cAAc,8BAA8B,CAAC;AAC7C,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,8BAA8B,CAAC;AACxE,cAAc,6BAA6B,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export * from "./services/error.service.js";
|
|
2
|
+
export * from "./services/formatter.service.js";
|
|
3
|
+
export * from "./services/generator.service.js";
|
|
4
|
+
export { default as GeneratorService } from "./services/generator.service.js";
|
|
5
|
+
export * from "./services/geometry.service.js";
|
|
6
|
+
export * from "./services/http.service.js";
|
|
7
|
+
export * from "./services/logger.service.js";
|
|
8
|
+
export * from "./services/reactive.service.js";
|
|
9
|
+
export { default as ReactiveService } from "./services/reactive.service.js";
|
|
10
|
+
export * from "./services/timing.service.js";
|
|
11
|
+
export { default as TimingService } from "./services/timing.service.js";
|
|
12
|
+
export * from "./services/utils.service.js";
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,cAAc,6BAA6B,CAAC;AAC5C,cAAc,iCAAiC,CAAC;AAChD,cAAc,iCAAiC,CAAC;AAChD,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AAC9E,cAAc,gCAAgC,CAAC;AAC/C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,gCAAgC,CAAC;AAC/C,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,gCAAgC,CAAC;AAC5E,cAAc,8BAA8B,CAAC;AAC7C,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,8BAA8B,CAAC;AACxE,cAAc,6BAA6B,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Temporal } from "@js-temporal/polyfill";
|
|
2
|
+
import type { DatesServiceTypes, Locale, TemporalInput } from "../../types/index.js";
|
|
3
|
+
/**
|
|
4
|
+
* Facade + Adapter + Singleton over the Temporal polyfill.
|
|
5
|
+
*/
|
|
6
|
+
export declare class DatesService implements DatesServiceTypes {
|
|
7
|
+
private static instance;
|
|
8
|
+
private constructor();
|
|
9
|
+
static getInstance(): DatesService;
|
|
10
|
+
private TO_PLAIN_DATE;
|
|
11
|
+
useDiff: (start: string | Temporal.PlainDate, end: string | Temporal.PlainDate) => string;
|
|
12
|
+
useFormat: (dateInput: TemporalInput, locale?: Locale, options?: Intl.DateTimeFormatOptions) => string;
|
|
13
|
+
useNow: () => string;
|
|
14
|
+
useNowDateTime: () => string;
|
|
15
|
+
useAddDays: (date: string | Temporal.PlainDate, days: number) => string;
|
|
16
|
+
useSubtractDays: (date: string | Temporal.PlainDate, days: number) => string;
|
|
17
|
+
useIsEqual: (date1: string | Temporal.PlainDate, date2: string | Temporal.PlainDate) => boolean;
|
|
18
|
+
useIsBefore: (date1: string | Temporal.PlainDate, date2: string | Temporal.PlainDate) => boolean;
|
|
19
|
+
useIsAfter: (date1: string | Temporal.PlainDate, date2: string | Temporal.PlainDate) => boolean;
|
|
20
|
+
useFirstDayOfMonth: (date?: string | Temporal.PlainDate) => string;
|
|
21
|
+
useLastDayOfMonth: (date?: string | Temporal.PlainDate) => string;
|
|
22
|
+
}
|
|
23
|
+
export declare const useDiff: (start: string | Temporal.PlainDate, end: string | Temporal.PlainDate) => string, useFormat: (dateInput: TemporalInput, locale?: Locale, options?: Intl.DateTimeFormatOptions) => string, useNow: () => string, useNowDateTime: () => string, useAddDays: (date: string | Temporal.PlainDate, days: number) => string, useSubtractDays: (date: string | Temporal.PlainDate, days: number) => string, useIsEqual: (date1: string | Temporal.PlainDate, date2: string | Temporal.PlainDate) => boolean, useIsBefore: (date1: string | Temporal.PlainDate, date2: string | Temporal.PlainDate) => boolean, useIsAfter: (date1: string | Temporal.PlainDate, date2: string | Temporal.PlainDate) => boolean, useFirstDayOfMonth: (date?: string | Temporal.PlainDate) => string, useLastDayOfMonth: (date?: string | Temporal.PlainDate) => string;
|
|
24
|
+
//# sourceMappingURL=dates.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dates.service.d.ts","sourceRoot":"","sources":["../../../src/core/services/dates.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEjD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAErF;;GAEG;AACH,qBAAa,YAAa,YAAW,iBAAiB;IACrD,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAe;IAEtC,OAAO,eAAiB;IAExB,OAAc,WAAW,IAAI,YAAY,CAKxC;IAGD,OAAO,CAAC,aAAa,CAC4C;IAE1D,OAAO,UACN,MAAM,GAAG,QAAQ,CAAC,SAAS,OAC7B,MAAM,GAAG,QAAQ,CAAC,SAAS,KAC9B,MAAM,CAMP;IAEK,SAAS,cACJ,aAAa,WAChB,MAAM,YACL,IAAI,CAAC,qBAAqB,KACjC,MAAM,CA6BP;IAEK,MAAM,QAAO,MAAM,CAA2C;IAE9D,cAAc,QAAO,MAAM,CAA+C;IAE1E,UAAU,SAAU,MAAM,GAAG,QAAQ,CAAC,SAAS,QAAQ,MAAM,KAAG,MAAM,CAC1B;IAE5C,eAAe,SAAU,MAAM,GAAG,QAAQ,CAAC,SAAS,QAAQ,MAAM,KAAG,MAAM,CAC1B;IAEjD,UAAU,UACT,MAAM,GAAG,QAAQ,CAAC,SAAS,SAC3B,MAAM,GAAG,QAAQ,CAAC,SAAS,KAChC,OAAO,CAC8E;IAEjF,WAAW,UACV,MAAM,GAAG,QAAQ,CA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al/polyfill";
|
|
2
|
+
/**
|
|
3
|
+
* Facade + Adapter + Singleton over the Temporal polyfill.
|
|
4
|
+
*/
|
|
5
|
+
export class DatesService {
|
|
6
|
+
static instance;
|
|
7
|
+
constructor() { }
|
|
8
|
+
static getInstance() {
|
|
9
|
+
if (!DatesService.instance) {
|
|
10
|
+
DatesService.instance = new DatesService();
|
|
11
|
+
}
|
|
12
|
+
return DatesService.instance;
|
|
13
|
+
}
|
|
14
|
+
// Private helper that adapts flexible inputs into a PlainDate.
|
|
15
|
+
TO_PLAIN_DATE = (date) => typeof date === "string" ? Temporal.PlainDate.from(date) : date;
|
|
16
|
+
useDiff = (start, end) => {
|
|
17
|
+
const startDate = this.TO_PLAIN_DATE(start);
|
|
18
|
+
const endDate = this.TO_PLAIN_DATE(end);
|
|
19
|
+
const duration = startDate.until(endDate, { largestUnit: "year" });
|
|
20
|
+
return `${duration.years} years, ${duration.months} months and ${duration.days} days`;
|
|
21
|
+
};
|
|
22
|
+
useFormat = (dateInput, locale = "en", options = {}) => {
|
|
23
|
+
let date;
|
|
24
|
+
try {
|
|
25
|
+
if (typeof dateInput === "number") {
|
|
26
|
+
date = Temporal.Instant.fromEpochMilliseconds(dateInput).toZonedDateTimeISO(Temporal.Now.timeZoneId());
|
|
27
|
+
}
|
|
28
|
+
else if (typeof dateInput === "string") {
|
|
29
|
+
try {
|
|
30
|
+
date = Temporal.PlainDate.from(dateInput);
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
date = Temporal.PlainDateTime.from(dateInput);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
else if (dateInput instanceof Date) {
|
|
37
|
+
date = Temporal.Instant.fromEpochMilliseconds(dateInput.getTime()).toZonedDateTimeISO(Temporal.Now.timeZoneId());
|
|
38
|
+
}
|
|
39
|
+
else if (dateInput instanceof Temporal.Instant) {
|
|
40
|
+
date = dateInput.toZonedDateTimeISO(Temporal.Now.timeZoneId());
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
date = dateInput;
|
|
44
|
+
}
|
|
45
|
+
return date.toLocaleString(locale, options);
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
console.error("Invalid date input:", error);
|
|
49
|
+
throw new Error(`Invalid date input: ${dateInput}`);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
useNow = () => Temporal.Now.plainDateISO().toString();
|
|
53
|
+
useNowDateTime = () => Temporal.Now.plainDateTimeISO().toString();
|
|
54
|
+
useAddDays = (date, days) => this.TO_PLAIN_DATE(date).add({ days }).toString();
|
|
55
|
+
useSubtractDays = (date, days) => this.TO_PLAIN_DATE(date).subtract({ days }).toString();
|
|
56
|
+
useIsEqual = (date1, date2) => Temporal.PlainDate.compare(this.TO_PLAIN_DATE(date1), this.TO_PLAIN_DATE(date2)) === 0;
|
|
57
|
+
useIsBefore = (date1, date2) => Temporal.PlainDate.compare(this.TO_PLAIN_DATE(date1), this.TO_PLAIN_DATE(date2)) < 0;
|
|
58
|
+
useIsAfter = (date1, date2) => Temporal.PlainDate.compare(this.TO_PLAIN_DATE(date1), this.TO_PLAIN_DATE(date2)) > 0;
|
|
59
|
+
useFirstDayOfMonth = (date = Temporal.Now.plainDateISO()) => this.TO_PLAIN_DATE(date).with({ day: 1 }).toString();
|
|
60
|
+
useLastDayOfMonth = (date = Temporal.Now.plainDateISO()) => this.TO_PLAIN_DATE(date).add({ months: 1 }).with({ day: 1 }).subtract({ days: 1 }).toString();
|
|
61
|
+
}
|
|
62
|
+
// Singleton instance and destructured exports.
|
|
63
|
+
export const { useDiff, useFormat, useNow, useNowDateTime, useAddDays, useSubtractDays, useIsEqual, useIsBefore, useIsAfter, useFirstDayOfMonth, useLastDayOfMonth, } = DatesService.getInstance();
|
|
64
|
+
//# sourceMappingURL=dates.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dates.service.js","sourceRoot":"","sources":["../../../src/core/services/dates.service.ts"],"names":[],"mappings":"AAA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X,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAC;CAC/F;AAED,+CAA+C;AAC/C,MAAM,CAAC,MAAM,EACZ,OAAO,EACP,SAAS,EACT,MAAM,EACN,cAAc,EACd,UAAU,EACV,eAAe,EACf,UAAU,EACV,WAAW,EACX,UAAU,EACV,kBAAkB,EAClB,iBAAiB,GACjB,GAAiB,YAAY,CAAC,WAAW,EAAE,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { IErrorFactory, ISerializedError } from "../../types/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Decoupled application error. Carries an HTTP-style status code.
|
|
4
|
+
*/
|
|
5
|
+
export declare class AppError extends Error {
|
|
6
|
+
readonly code: number;
|
|
7
|
+
constructor(message?: string, code?: number);
|
|
8
|
+
useToJson: () => ISerializedError;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Error factory implemented as a singleton (Factory Method pattern).
|
|
12
|
+
*/
|
|
13
|
+
export declare class ErrorFactoryService implements IErrorFactory {
|
|
14
|
+
private static instance;
|
|
15
|
+
private constructor();
|
|
16
|
+
static getInstance(): ErrorFactoryService;
|
|
17
|
+
useBadRequest: (message?: string) => AppError;
|
|
18
|
+
useUnauthorized: (message?: string) => AppError;
|
|
19
|
+
useForbidden: (message?: string) => AppError;
|
|
20
|
+
useNotFound: (message?: string) => AppError;
|
|
21
|
+
useInternal: (message?: string) => AppError;
|
|
22
|
+
useCustom: (message: string, code: number) => AppError;
|
|
23
|
+
}
|
|
24
|
+
export declare const useBadRequest: (message?: string) => AppError, useUnauthorized: (message?: string) => AppError, useForbidden: (message?: string) => AppError, useNotFound: (message?: string) => AppError, useInternal: (message?: string) => AppError, useCustom: (message: string, code: number) => AppError;
|
|
25
|
+
//# sourceMappingURL=error.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error.service.d.ts","sourceRoot":"","sources":["../../../src/core/services/error.service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAE5E;;GAEG;AACH,qBAAa,QAAS,SAAQ,KAAK;aAGjB,IAAI,EAAE,MAAM;IAF7B,YACC,OAAO,SAAkB,EACT,IAAI,GAAE,MAAY,EAKlC;IAEM,SAAS,QAAO,gBAAgB,CAIpC;CACH;AAED;;GAEG;AACH,qBAAa,mBAAoB,YAAW,aAAa;IACxD,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAsB;IAE7C,OAAO,eAAiB;IAExB,OAAc,WAAW,IAAI,mBAAmB,CAK/C;IAEM,aAAa,wBAA8B,QAAQ,CAA+B;IAElF,eAAe,wBAA+B,QAAQ,CAA+B;IAErF,YAAY,wBAA4B,QAAQ,CAA+B;IAE/E,WAAW,wBAA4B,QAAQ,CAA+B;IAE9E,WAAW,wBAAwC,QAAQ,CAA+B;IAE1F,SAAS,YAAa,MAAM,QAAQ,MAAM,KAAG,QAAQ,CAAgC;CAC5F;AAGD,eAAO,MACN,aAAa,wBAfqC,QAAQ,EAgB1D,eAAe,wBAdsC,QAAQ,EAe7D,YAAY,wBAbmC,QAAQ,EAcvD,WAAW,wBAZmC,QAAQ,EAatD,WAAW,wBAX+C,QAAQ,EAYlE,SAAS,YAVoB,MAAM,QAAQ,MAAM,KAAG,QAWK,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Decoupled application error. Carries an HTTP-style status code.
|
|
3
|
+
*/
|
|
4
|
+
export class AppError extends Error {
|
|
5
|
+
code;
|
|
6
|
+
constructor(message = "Unknown error", code = 400) {
|
|
7
|
+
super(message);
|
|
8
|
+
this.code = code;
|
|
9
|
+
this.name = "AppError";
|
|
10
|
+
Object.setPrototypeOf(this, AppError.prototype);
|
|
11
|
+
}
|
|
12
|
+
useToJson = () => ({
|
|
13
|
+
name: this.name,
|
|
14
|
+
message: this.message,
|
|
15
|
+
code: this.code,
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Error factory implemented as a singleton (Factory Method pattern).
|
|
20
|
+
*/
|
|
21
|
+
export class ErrorFactoryService {
|
|
22
|
+
static instance;
|
|
23
|
+
constructor() { }
|
|
24
|
+
static getInstance() {
|
|
25
|
+
if (!ErrorFactoryService.instance) {
|
|
26
|
+
ErrorFactoryService.instance = new ErrorFactoryService();
|
|
27
|
+
}
|
|
28
|
+
return ErrorFactoryService.instance;
|
|
29
|
+
}
|
|
30
|
+
useBadRequest = (message = "Bad Request") => new AppError(message, 400);
|
|
31
|
+
useUnauthorized = (message = "Unauthorized") => new AppError(message, 401);
|
|
32
|
+
useForbidden = (message = "Forbidden") => new AppError(message, 403);
|
|
33
|
+
useNotFound = (message = "Not Found") => new AppError(message, 404);
|
|
34
|
+
useInternal = (message = "Internal Server Error") => new AppError(message, 500);
|
|
35
|
+
useCustom = (message, code) => new AppError(message, code);
|
|
36
|
+
}
|
|
37
|
+
// Singleton instance and destructured exports.
|
|
38
|
+
export const { useBadRequest, useUnauthorized, useForbidden, useNotFound, useInternal, useCustom, } = ErrorFactoryService.getInstance();
|
|
39
|
+
//# sourceMappingURL=error.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error.service.js","sourceRoot":"","sources":["../../../src/core/services/error.service.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,OAAO,QAAS,SAAQ,KAAK;IAGjB,IAAI;IAFrB,YACC,OAAO,GAAG,eAAe,EACT,IAAI,GAAW,GAAG;QAElC,KAAK,CAAC,OAAO,CAAC,CAAC;oBAFC,IAAI;QAGpB,IAAI,CAAC,IAAI,GAAG,UAAU,CA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AA+C;AAC/C,MAAM,CAAC,MAAM,EACZ,aAAa,EACb,eAAe,EACf,YAAY,EACZ,WAAW,EACX,WAAW,EACX,SAAS,GACT,GAAwB,mBAAmB,CAAC,WAAW,EAAE,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { CurrencyFormatOptions, IConverterService, IFormatterService, Locale } from "../../types/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Number/currency/string formatter (Adapter + Singleton) over `Intl`.
|
|
4
|
+
*/
|
|
5
|
+
export declare class FormatterService implements IFormatterService {
|
|
6
|
+
private static instance;
|
|
7
|
+
private constructor();
|
|
8
|
+
static getInstance(): FormatterService;
|
|
9
|
+
useFormatNumber: (value: number, locale?: Locale, digits?: number) => string;
|
|
10
|
+
useUpperCase: (text: string, locale?: Locale) => string;
|
|
11
|
+
useLowerCase: (text: string, locale?: Locale) => string;
|
|
12
|
+
useCapitalize: (text: string, locale?: Locale) => string;
|
|
13
|
+
useFormatCurrency: (options: CurrencyFormatOptions) => string;
|
|
14
|
+
useJsonStringify: (data: unknown) => string;
|
|
15
|
+
useJsonParse: <T = unknown>(json: string) => T;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Unit converter facade (Facade + Adapter + Singleton) built on FormatterService.
|
|
19
|
+
*/
|
|
20
|
+
export declare class ConverterService implements IConverterService {
|
|
21
|
+
private static instance;
|
|
22
|
+
private readonly formatter;
|
|
23
|
+
private constructor();
|
|
24
|
+
static getInstance(): ConverterService;
|
|
25
|
+
useToCelsius: (fahrenheit: number, locale?: Locale, digits?: number) => string;
|
|
26
|
+
useToFahrenheit: (celsius: number, locale?: Locale, digits?: number) => string;
|
|
27
|
+
useToKilometers: (miles: number, locale?: Locale, digits?: number) => string;
|
|
28
|
+
useToMiles: (km: number, locale?: Locale, digits?: number) => string;
|
|
29
|
+
useToInches: (cm: number, locale?: Locale, digits?: number) => string;
|
|
30
|
+
useToCm: (inches: number, locale?: Locale, digits?: number) => string;
|
|
31
|
+
useToKilos: (pounds: number, locale?: Locale, digits?: number) => string;
|
|
32
|
+
useToPounds: (kilos: number, locale?: Locale, digits?: number) => string;
|
|
33
|
+
}
|
|
34
|
+
export declare const useToCelsius: (fahrenheit: number, locale?: Locale, digits?: number) => string, useToFahrenheit: (celsius: number, locale?: Locale, digits?: number) => string, useToKilometers: (miles: number, locale?: Locale, digits?: number) => string, useToMiles: (km: number, locale?: Locale, digits?: number) => string, useToInches: (cm: number, locale?: Locale, digits?: number) => string, useToCm: (inches: number, locale?: Locale, digits?: number) => string, useToKilos: (pounds: number, locale?: Locale, digits?: number) => string, useToPounds: (kilos: number, locale?: Locale, digits?: number) => string;
|
|
35
|
+
export declare const useFormatCurrency: (options: CurrencyFormatOptions) => string, useFormatNumber: (value: number, locale?: Locale, digits?: number) => string, useJsonStringify: (data: unknown) => string, useJsonParse: <T = unknown>(json: string) => T, useUpperCase: (text: string, locale?: Locale) => string, useLowerCase: (text: string, locale?: Locale) => string, useCapitalize: (text: string, locale?: Locale) => string;
|
|
36
|
+
//# sourceMappingURL=formatter.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatter.service.d.ts","sourceRoot":"","sources":["../../../src/core/services/formatter.service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,qBAAqB,EACrB,iBAAiB,EACjB,iBAAiB,EACjB,MAAM,EACN,MAAM,sBAAsB,CAAC;AAE9B;;GAEG;AACH,qBAAa,gBAAiB,YAAW,iBAAiB;IACzD,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAmB;IAE1C,OAAO,eAAiB;IAExB,OAAc,WAAW,IAAI,gBAAgB,CAK5C;IAEM,eAAe,UAAW,MAAM,WAAU,MAAM,sBAAsB,MAAM,CAKjF;IAEK,YAAY,SAAU,MAAM,WAAU,MAAM,KAAU,MAAM,CAC5B;IAEhC,YAAY,SAAU,MAAM,WAAU,MAAM,KAAU,MAAM,CAC5B;IAEhC,aAAa,SAAU,MAA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U,MAAM,sBAAsB,MAAM,EAgB/E,WAAW,UAbkB,MAAM,WAAU,MAAM,sBAAsB,MActB,CAAC;AAErD,eAAO,MACN,iBAAiB,YAtEoB,qBAAqB,KAAG,MAAM,EAuEnE,eAAe,UA1FkB,MAAM,WAAU,MAAM,sBAAsB,MAAM,EA2FnF,gBAAgB,SA/DiB,OAAO,KAAG,MAAM,EAgEjD,YAAY,GA9DW,CAAC,kBAAkB,MAAM,QA+DhD,YAAY,SAtFiB,MAAM,WAAU,MAAM,KAAU,MAAM,EAuFnE,YAAY,SApFiB,MAAM,WAAU,MAAM,KAAU,MAAM,EAqFnE,aAAa,SAlFiB,MAAM,WAAU,MAAM,KAAU,MAmFX,CAAC"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Number/currency/string formatter (Adapter + Singleton) over `Intl`.
|
|
3
|
+
*/
|
|
4
|
+
export class FormatterService {
|
|
5
|
+
static instance;
|
|
6
|
+
constructor() { }
|
|
7
|
+
static getInstance() {
|
|
8
|
+
if (!FormatterService.instance) {
|
|
9
|
+
FormatterService.instance = new FormatterService();
|
|
10
|
+
}
|
|
11
|
+
return FormatterService.instance;
|
|
12
|
+
}
|
|
13
|
+
useFormatNumber = (value, locale = "en", digits = 2) => {
|
|
14
|
+
return new Intl.NumberFormat(locale, {
|
|
15
|
+
maximumFractionDigits: digits,
|
|
16
|
+
minimumFractionDigits: digits,
|
|
17
|
+
}).format(value);
|
|
18
|
+
};
|
|
19
|
+
useUpperCase = (text, locale = "en") => text.toLocaleUpperCase(locale).trim();
|
|
20
|
+
useLowerCase = (text, locale = "en") => text.toLocaleLowerCase(locale).trim();
|
|
21
|
+
useCapitalize = (text, locale = "en") => {
|
|
22
|
+
const trimmed = text.trim();
|
|
23
|
+
if (!trimmed)
|
|
24
|
+
return "";
|
|
25
|
+
return trimmed.charAt(0).toLocaleUpperCase(locale) + trimmed.slice(1);
|
|
26
|
+
};
|
|
27
|
+
useFormatCurrency = (options) => {
|
|
28
|
+
const { amount, currency = "USD", taxes = 0, locale = "en" } = options;
|
|
29
|
+
// `taxes` may be a percentage (21) or a decimal fraction (0.21).
|
|
30
|
+
const taxRate = taxes > 1 ? taxes / 100 : taxes;
|
|
31
|
+
const total = amount * (1 + taxRate);
|
|
32
|
+
return new Intl.NumberFormat(locale, { style: "currency", currency }).format(total);
|
|
33
|
+
};
|
|
34
|
+
useJsonStringify = (data) => JSON.stringify(data, null, 3);
|
|
35
|
+
useJsonParse = (json) => JSON.parse(json);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Unit converter facade (Facade + Adapter + Singleton) built on FormatterService.
|
|
39
|
+
*/
|
|
40
|
+
export class ConverterService {
|
|
41
|
+
static instance;
|
|
42
|
+
formatter;
|
|
43
|
+
constructor() {
|
|
44
|
+
this.formatter = FormatterService.getInstance();
|
|
45
|
+
}
|
|
46
|
+
static getInstance() {
|
|
47
|
+
if (!ConverterService.instance) {
|
|
48
|
+
ConverterService.instance = new ConverterService();
|
|
49
|
+
}
|
|
50
|
+
return ConverterService.instance;
|
|
51
|
+
}
|
|
52
|
+
useToCelsius = (fahrenheit, locale = "en", digits = 2) => this.formatter.useFormatNumber((fahrenheit - 32) / 1.8, locale, digits);
|
|
53
|
+
useToFahrenheit = (celsius, locale = "en", digits = 2) => this.formatter.useFormatNumber(celsius * 1.8 + 32, locale, digits);
|
|
54
|
+
useToKilometers = (miles, locale = "en", digits = 2) => this.formatter.useFormatNumber(miles / 0.62137, locale, digits);
|
|
55
|
+
useToMiles = (km, locale = "en", digits = 2) => this.formatter.useFormatNumber(km * 1.60934, locale, digits);
|
|
56
|
+
useToInches = (cm, locale = "en", digits = 2) => this.formatter.useFormatNumber(cm / 2.54, locale, digits);
|
|
57
|
+
useToCm = (inches, locale = "en", digits = 2) => this.formatter.useFormatNumber(inches * 2.54, locale, digits);
|
|
58
|
+
useToKilos = (pounds, locale = "en", digits = 2) => this.formatter.useFormatNumber(pounds * 0.453592, locale, digits);
|
|
59
|
+
useToPounds = (kilos, locale = "en", digits = 2) => this.formatter.useFormatNumber(kilos / 0.453592, locale, digits);
|
|
60
|
+
}
|
|
61
|
+
// Singleton instances and destructured exports.
|
|
62
|
+
export const { useToCelsius, useToFahrenheit, useToKilometers, useToMiles, useToInches, useToCm, useToKilos, useToPounds, } = ConverterService.getInstance();
|
|
63
|
+
export const { useFormatCurrency, useFormatNumber, useJsonStringify, useJsonParse, useUpperCase, useLowerCase, useCapitalize, } = FormatterService.getInstance();
|
|
64
|
+
//# sourceMappingURL=formatter.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatter.service.js","sourceRoot":"","sources":["../../../src/core/services/formatter.service.ts"],"names":[],"mappings":"AAOA;;GAEG;AACH,MAAM,OAAO,gBAAgB;IACpB,MAAM,CAAC,QAAQ,CAAmB;IAE1C,gBAAuB,CAAC;IAEjB,MAAM,CAAC,WAAW;QACxB,IAAI,CAAC,gBAAgB,CAAC,QAAQ,EAAE,CAAC;YAChC,gBAAgB,CAAC,QAAQ,GAAG,IAAI,gBAAgB,EAAE,CAAC;QACpD,CAAC;QACD,OAAO,gBAAgB,CAAC,QAAQ,CAAC;IAClC,CAAC;IAEM,eAAe,GAAG,CAAC,KAAa,EAAE,MAAM,GAAW,IAAI,EAAE,MAAM,GAAG,CAAC,EAAU,EAAE;QACrF,OAAO,IAAI,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE;YACpC,qBAAqB,EAAE,MAAM;YAC7B,qBAAqB,EAAE,MAAM;SAC7B,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAClB,CAAC,CAAC;IAEK,YAAY,GAAG,CAAC,IAAY,EAAE,MAAM,GAAW,IAAI,EAAU,EAAE,CACrE,IAAI,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,CAAC;IAEhC,YAAY,GAAG,CAAC,IAAY,EAAE,MAAM,GAAW,IAAI,EAAU,EAAE,CACrE,IAAI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AO,GAAG,CAAC,MAAc,EAAE,MAAM,GAAW,IAAI,EAAE,MAAM,GAAG,CAAC,EAAU,EAAE,CAC9E,IAAI,CAAC,SAAS,CAAC,eAAe,CAAC,MAAM,GAAG,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IAExD,UAAU,GAAG,CAAC,MAAc,EAAE,MAAM,GAAW,IAAI,EAAE,MAAM,GAAG,CAAC,EAAU,EAAE,CACjF,IAAI,CAAC,SAAS,CAAC,eAAe,CAAC,MAAM,GAAG,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IAE5D,WAAW,GAAG,CAAC,KAAa,EAAE,MAAM,GAAW,IAAI,EAAE,MAAM,GAAG,CAAC,EAAU,EAAE,CACjF,IAAI,CAAC,SAAS,CAAC,eAAe,CAAC,KAAK,GAAG,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;CAClE;AAED,gDAAgD;AAChD,MAAM,CAAC,MAAM,EACZ,YAAY,EACZ,eAAe,EACf,eAAe,EACf,UAAU,EACV,WAAW,EACX,OAAO,EACP,UAAU,EACV,WAAW,GACX,GAAqB,gBAAgB,CAAC,WAAW,EAAE,CAAC;AAErD,MAAM,CAAC,MAAM,EACZ,iBAAiB,EACjB,eAAe,EACf,gBAAgB,EAChB,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,aAAa,GACb,GAAqB,gBAAgB,CAAC,WAAW,EAAE,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { ICryptoStrategy, IUuidStrategy } from "../../types/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Loads the Node.js `crypto` module lazily, only when `useEncrypt` is invoked.
|
|
4
|
+
*
|
|
5
|
+
* NOTE: this is a one-way hash demo, not a credential store. Do not rely on the
|
|
6
|
+
* fixed default salt for real password hashing; prefer scrypt/argon2id instead.
|
|
7
|
+
*/
|
|
8
|
+
export declare class LazyNodeCryptoStrategy implements ICryptoStrategy {
|
|
9
|
+
useEncrypt(plainText: string, salt?: string): Promise<string>;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Native UUID strategy using `globalThis.crypto.randomUUID`, with a fallback.
|
|
13
|
+
*/
|
|
14
|
+
export declare class NativeUuidStrategy implements IUuidStrategy {
|
|
15
|
+
useGenerate(): string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Generator facade (Singleton + Strategy) for ids, slugs, tokens and hashing.
|
|
19
|
+
*/
|
|
20
|
+
export default class GeneratorService {
|
|
21
|
+
private static instance;
|
|
22
|
+
private counter;
|
|
23
|
+
private cryptoStrategy;
|
|
24
|
+
private uuidStrategy;
|
|
25
|
+
private constructor();
|
|
26
|
+
static getInstance(): GeneratorService;
|
|
27
|
+
useNumericId: () => number;
|
|
28
|
+
useUuid: () => string;
|
|
29
|
+
useSlugify: (text: string) => string;
|
|
30
|
+
useToken: () => number;
|
|
31
|
+
useEncrypt: (plainText: string, salt?: string) => Promise<string>;
|
|
32
|
+
}
|
|
33
|
+
export declare const useSlugify: (text: string) => string, useUuid: () => string, useNumericId: () => number, useToken: () => number, useEncrypt: (plainText: string, salt?: string) => Promise<string>;
|
|
34
|
+
//# sourceMappingURL=generator.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generator.service.d.ts","sourceRoot":"","sources":["../../../src/core/services/generator.service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAE3E;;;;;GAKG;AACH,qBAAa,sBAAuB,YAAW,eAAe;IACvD,UAAU,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAYlE;CACD;AAED;;GAEG;AACH,qBAAa,kBAAmB,YAAW,aAAa;IACvD,WAAW,IAAI,MAAM,CAYpB;CACD;AAED;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,gBAAgB;IACpC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAmB;IAC1C,OAAO,CAAC,OAAO,CAAK;IAEpB,OAAO,CAAC,cAAc,CAAkB;IACxC,OAAO,CAAC,YAAY,CAAgB;IAEpC,OAAO,eAGN;IAED,OAAc,WAAW,IAAI,gBAAgB,CAK5C;IAEM,YAAY,QAAO,MAAM,CAAmB;IAE5C,OAAO,QAAO,MAAM,CAAoC;IAExD,UAAU,SAAU,MAAM,KAAG,MAAM,CAcxC;IAEK,QAAQ,QAAO,MAAM,CAO1B;IAEK,UAAU,cAAqB,MAAM,SAAS,MAAM,KAAG,OAAO,CAAC,MAAM,CAAC,CAC5B;CACjD;AAGD,eAAO,MAAQ,UAAU,SA9BG,MAAM,KAAG,MAAM,EA8BhB,OAAO,QAhCZ,MAAM,EAgCQ,YAAY,QAlCrB,MAAM,EAkCiB,QAAQ,QAdnC,MAAM,EAc+B,UAAU,cAL/B,MAAM,SAAS,MAAM,KAAG,OAAO,CAAC,MAAM,CAM9C,CAAC"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Loads the Node.js `crypto` module lazily, only when `useEncrypt` is invoked.
|
|
3
|
+
*
|
|
4
|
+
* NOTE: this is a one-way hash demo, not a credential store. Do not rely on the
|
|
5
|
+
* fixed default salt for real password hashing; prefer scrypt/argon2id instead.
|
|
6
|
+
*/
|
|
7
|
+
export class LazyNodeCryptoStrategy {
|
|
8
|
+
async useEncrypt(plainText, salt) {
|
|
9
|
+
const cryptoModule = await import("node:crypto");
|
|
10
|
+
// Supports both CJS and pure ESM environments.
|
|
11
|
+
const cryptoInstance = cryptoModule.default ?? cryptoModule;
|
|
12
|
+
// Generate a random salt if none is provided (128 bits).
|
|
13
|
+
const actualSalt = salt ?? cryptoInstance.randomBytes(16).toString("hex");
|
|
14
|
+
const hash = cryptoInstance
|
|
15
|
+
.pbkdf2Sync(plainText, actualSalt, 100000, 64, "sha512")
|
|
16
|
+
.toString("hex");
|
|
17
|
+
return `${actualSalt}:${hash}`;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Native UUID strategy using `globalThis.crypto.randomUUID`, with a fallback.
|
|
22
|
+
*/
|
|
23
|
+
export class NativeUuidStrategy {
|
|
24
|
+
useGenerate() {
|
|
25
|
+
if (typeof globalThis.crypto !== "undefined" &&
|
|
26
|
+
typeof globalThis.crypto.randomUUID === "function") {
|
|
27
|
+
return globalThis.crypto.randomUUID();
|
|
28
|
+
}
|
|
29
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
|
|
30
|
+
const r = (Math.random() * 16) | 0;
|
|
31
|
+
const v = c === "x" ? r : (r & 0x3) | 0x8;
|
|
32
|
+
return v.toString(16);
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Generator facade (Singleton + Strategy) for ids, slugs, tokens and hashing.
|
|
38
|
+
*/
|
|
39
|
+
export default class GeneratorService {
|
|
40
|
+
static instance;
|
|
41
|
+
counter = 0;
|
|
42
|
+
cryptoStrategy;
|
|
43
|
+
uuidStrategy;
|
|
44
|
+
constructor() {
|
|
45
|
+
this.cryptoStrategy = new LazyNodeCryptoStrategy();
|
|
46
|
+
this.uuidStrategy = new NativeUuidStrategy();
|
|
47
|
+
}
|
|
48
|
+
static getInstance() {
|
|
49
|
+
if (!GeneratorService.instance) {
|
|
50
|
+
GeneratorService.instance = new GeneratorService();
|
|
51
|
+
}
|
|
52
|
+
return GeneratorService.instance;
|
|
53
|
+
}
|
|
54
|
+
useNumericId = () => ++this.counter;
|
|
55
|
+
useUuid = () => this.uuidStrategy.useGenerate();
|
|
56
|
+
useSlugify = (text) => {
|
|
57
|
+
if (!text)
|
|
58
|
+
throw new Error("Text is required for slugify");
|
|
59
|
+
return text
|
|
60
|
+
.toString()
|
|
61
|
+
.trim()
|
|
62
|
+
.toLowerCase()
|
|
63
|
+
.normalize("NFD")
|
|
64
|
+
.replace(/\p{M}/gu, "")
|
|
65
|
+
.replace(/\s+/g, "-")
|
|
66
|
+
.replace(/[^\w-]+/g, "")
|
|
67
|
+
.replace(/--+/g, "-")
|
|
68
|
+
.replace(/^-+/, "")
|
|
69
|
+
.replace(/-+$/, "");
|
|
70
|
+
};
|
|
71
|
+
useToken = () => {
|
|
72
|
+
if (typeof globalThis.crypto?.getRandomValues === "function") {
|
|
73
|
+
const buffer = new Uint32Array(1);
|
|
74
|
+
globalThis.crypto.getRandomValues(buffer);
|
|
75
|
+
return 100000 + (buffer[0] % 900000);
|
|
76
|
+
}
|
|
77
|
+
return Math.floor(100000 + Math.random() * 900000);
|
|
78
|
+
};
|
|
79
|
+
useEncrypt = async (plainText, salt) => this.cryptoStrategy.useEncrypt(plainText, salt);
|
|
80
|
+
}
|
|
81
|
+
// Singleton instance and destructured exports.
|
|
82
|
+
export const { useSlugify, useUuid, useNumericId, useToken, useEncrypt } = GeneratorService.getInstance();
|
|
83
|
+
//# sourceMappingURL=generator.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generator.service.js","sourceRoot":"","sources":["../../../src/core/services/generator.service.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,MAAM,OAAO,sBAAsB;IAClC,KAAK,CAAC,UAAU,CAAC,SAAiB,EAAE,IAAa;QAChD,MAAM,YAAY,GAAG,MAAM,MAAM,CAAC,aAAa,CAAC,CAAC;QACjD,+CAA+C;QAC/C,MAAM,cAAc,GAAG,YAAY,CAAC,OAAO,IAAI,YAAY,CAAC;QAE5D,yDAAyD;QACzD,MAAM,UAAU,GAAG,IAAI,IAAI,cAAc,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;QAC1E,MAAM,IAAI,GAAG,cAAc;aACzB,UAAU,CAAC,SAAS,EAAE,UAAU,EAAE,MAAM,EAAE,EAAE,EAAE,QAAQ,CAAC;aACvD,QAAQ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,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,UAAU,EAAE,GACvE,gBAAgB,CAAC,WAAW,EAAE,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { GeometryFormatOptions } from "../../types/index.js";
|
|
2
|
+
/** Area calculations for geometric shapes. */
|
|
3
|
+
export declare class GeometryArea {
|
|
4
|
+
private constructor();
|
|
5
|
+
static useRectangle(width: number, height: number, options?: GeometryFormatOptions): string;
|
|
6
|
+
static useSquare(side: number, options?: GeometryFormatOptions): string;
|
|
7
|
+
static useTriangle(base: number, height: number, options?: GeometryFormatOptions): string;
|
|
8
|
+
static useCircle(radius: number, options?: GeometryFormatOptions): string;
|
|
9
|
+
static useTrapezoid(parallelSide1: number, parallelSide2: number, height: number, options?: GeometryFormatOptions): string;
|
|
10
|
+
static useHexagon(side: number, options?: GeometryFormatOptions): string;
|
|
11
|
+
static useEllipse(semiMajor: number, semiMinor: number, options?: GeometryFormatOptions): string;
|
|
12
|
+
static useParallelogram(base: number, height: number, options?: GeometryFormatOptions): string;
|
|
13
|
+
}
|
|
14
|
+
/** Perimeter calculations for geometric shapes. */
|
|
15
|
+
export declare class GeometryPerimeter {
|
|
16
|
+
private constructor();
|
|
17
|
+
static useRectangle(width: number, height: number, options?: GeometryFormatOptions): string;
|
|
18
|
+
static useSquare(side: number, options?: GeometryFormatOptions): string;
|
|
19
|
+
static useTriangle(side1: number, side2: number, side3: number, options?: GeometryFormatOptions): string;
|
|
20
|
+
static useCircle(radius: number, options?: GeometryFormatOptions): string;
|
|
21
|
+
static useHexagon(side: number, options?: GeometryFormatOptions): string;
|
|
22
|
+
static useTrapezoid(side1: number, side2: number, side3: number, side4: number, options?: GeometryFormatOptions): string;
|
|
23
|
+
static useEllipse(semiMajor: number, semiMinor: number, options?: GeometryFormatOptions): string;
|
|
24
|
+
static useParallelogram(side1: number, side2: number, options?: GeometryFormatOptions): string;
|
|
25
|
+
}
|
|
26
|
+
/** Volume calculations for 3D geometric shapes. */
|
|
27
|
+
export declare class GeometryVolume {
|
|
28
|
+
private constructor();
|
|
29
|
+
static useCube(side: number, options?: GeometryFormatOptions): string;
|
|
30
|
+
static useBox(length: number, width: number, height: number, options?: GeometryFormatOptions): string;
|
|
31
|
+
static useSphere(radius: number, options?: GeometryFormatOptions): string;
|
|
32
|
+
static useCylinder(radius: number, height: number, options?: GeometryFormatOptions): string;
|
|
33
|
+
static useCone(radius: number, height: number, options?: GeometryFormatOptions): string;
|
|
34
|
+
static usePyramid(baseArea: number, height: number, options?: GeometryFormatOptions): string;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Consolidated geometry utilities namespace.
|
|
38
|
+
* Groups area, perimeter and volume calculations.
|
|
39
|
+
*/
|
|
40
|
+
export declare const GeometryUtils: {
|
|
41
|
+
area: typeof GeometryArea;
|
|
42
|
+
perimeter: typeof GeometryPerimeter;
|
|
43
|
+
volume: typeof GeometryVolume;
|
|
44
|
+
};
|
|
45
|
+
//# sourceMappingURL=geometry.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"geometry.service.d.ts","sourceRoot":"","sources":["../../../src/core/services/geometry.service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAYlE,8CAA8C;AAC9C,qBAAa,YAAY;IACxB,OAAO,eAAiB;IAExB,MAAM,CAAC,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,qBAAqB,GAAG,MAAM,CAE1F;IAED,MAAM,CAAC,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,qBAAqB,GAAG,MAAM,CAEtE;IAED,MAAM,CAAC,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,qBAAqB,GAAG,MAAM,CAExF;IAED,MAAM,CAAC,SAAS,C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