kompkit-core 0.2.0-alpha.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 KompKit
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/index.cjs ADDED
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ debounce: () => debounce,
24
+ formatCurrency: () => formatCurrency,
25
+ isEmail: () => isEmail
26
+ });
27
+ module.exports = __toCommonJS(index_exports);
28
+
29
+ // src/debounce.ts
30
+ function debounce(fn, wait = 250) {
31
+ let t = null;
32
+ return (...args) => {
33
+ if (t) clearTimeout(t);
34
+ t = setTimeout(() => fn(...args), wait);
35
+ };
36
+ }
37
+
38
+ // src/validate.ts
39
+ var EMAIL_RE = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
40
+ function isEmail(v) {
41
+ return EMAIL_RE.test(v.trim());
42
+ }
43
+
44
+ // src/format.ts
45
+ function formatCurrency(amount, currency = "EUR", locale = "es-ES") {
46
+ return new Intl.NumberFormat(locale, { style: "currency", currency }).format(amount);
47
+ }
48
+ // Annotate the CommonJS export names for ESM import in node:
49
+ 0 && (module.exports = {
50
+ debounce,
51
+ formatCurrency,
52
+ isEmail
53
+ });
54
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/debounce.ts","../src/validate.ts","../src/format.ts"],"sourcesContent":["// KompKit Core - Cross-platform utilities\nexport * from \"./debounce\";\nexport * from \"./validate\";\nexport * from \"./format\";\n","/**\n * Debounces a function call by delaying its execution until after a specified wait period.\n * Subsequent calls within the wait period reset the timer.\n * \n * @param fn - The function to debounce.\n * @param wait - Milliseconds to wait before invoking the function. Defaults to 250ms.\n * @returns A debounced version of the function.\n * \n * @example\n * ```ts\n * const search = debounce((query: string) => {\n * console.log('Searching:', query);\n * }, 300);\n * \n * search('hello'); // Will execute after 300ms if no other calls are made\n * ```\n */\nexport function debounce<T extends (...args: any[]) => any>(fn: T, wait = 250) {\n let t: ReturnType<typeof setTimeout> | null = null;\n return (...args: Parameters<T>) => {\n if (t) clearTimeout(t);\n t = setTimeout(() => fn(...args), wait);\n };\n}\n","const EMAIL_RE = /^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/;\n\n/**\n * Validates whether a string matches a basic email pattern.\n * \n * @param v - The string to validate.\n * @returns `true` if the string is a valid email format, `false` otherwise.\n * \n * @example\n * ```ts\n * isEmail('user@example.com'); // true\n * isEmail('invalid@'); // false\n * isEmail(' test@domain.org '); // true (whitespace is trimmed)\n * ```\n */\nexport function isEmail(v: string): boolean {\n return EMAIL_RE.test(v.trim());\n}\n","/**\n * Formats a number as a localized currency string.\n * \n * @param amount - The numeric amount to format.\n * @param currency - The currency code (e.g., \"USD\", \"EUR\", \"JPY\"). Defaults to \"EUR\".\n * @param locale - The locale string (e.g., \"en-US\", \"es-ES\"). Defaults to \"es-ES\".\n * @returns A formatted currency string.\n * \n * @example\n * ```ts\n * formatCurrency(1234.56); // \"1.234,56 €\" (es-ES default)\n * formatCurrency(1234.56, \"USD\", \"en-US\"); // \"$1,234.56\"\n * formatCurrency(1000, \"JPY\", \"ja-JP\"); // \"¥1,000\"\n * ```\n */\nexport function formatCurrency(\n amount: number,\n currency = \"EUR\",\n locale = \"es-ES\"\n): string {\n return new Intl.NumberFormat(locale, { style: \"currency\", currency }).format(amount);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACiBO,SAAS,SAA4C,IAAO,OAAO,KAAK;AAC7E,MAAI,IAA0C;AAC9C,SAAO,IAAI,SAAwB;AACjC,QAAI,EAAG,cAAa,CAAC;AACrB,QAAI,WAAW,MAAM,GAAG,GAAG,IAAI,GAAG,IAAI;AAAA,EACxC;AACF;;;ACvBA,IAAM,WAAW;AAeV,SAAS,QAAQ,GAAoB;AAC1C,SAAO,SAAS,KAAK,EAAE,KAAK,CAAC;AAC/B;;;ACFO,SAAS,eACd,QACA,WAAW,OACX,SAAS,SACD;AACR,SAAO,IAAI,KAAK,aAAa,QAAQ,EAAE,OAAO,YAAY,SAAS,CAAC,EAAE,OAAO,MAAM;AACrF;","names":[]}
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Debounces a function call by delaying its execution until after a specified wait period.
3
+ * Subsequent calls within the wait period reset the timer.
4
+ *
5
+ * @param fn - The function to debounce.
6
+ * @param wait - Milliseconds to wait before invoking the function. Defaults to 250ms.
7
+ * @returns A debounced version of the function.
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * const search = debounce((query: string) => {
12
+ * console.log('Searching:', query);
13
+ * }, 300);
14
+ *
15
+ * search('hello'); // Will execute after 300ms if no other calls are made
16
+ * ```
17
+ */
18
+ declare function debounce<T extends (...args: any[]) => any>(fn: T, wait?: number): (...args: Parameters<T>) => void;
19
+
20
+ /**
21
+ * Validates whether a string matches a basic email pattern.
22
+ *
23
+ * @param v - The string to validate.
24
+ * @returns `true` if the string is a valid email format, `false` otherwise.
25
+ *
26
+ * @example
27
+ * ```ts
28
+ * isEmail('user@example.com'); // true
29
+ * isEmail('invalid@'); // false
30
+ * isEmail(' test@domain.org '); // true (whitespace is trimmed)
31
+ * ```
32
+ */
33
+ declare function isEmail(v: string): boolean;
34
+
35
+ /**
36
+ * Formats a number as a localized currency string.
37
+ *
38
+ * @param amount - The numeric amount to format.
39
+ * @param currency - The currency code (e.g., "USD", "EUR", "JPY"). Defaults to "EUR".
40
+ * @param locale - The locale string (e.g., "en-US", "es-ES"). Defaults to "es-ES".
41
+ * @returns A formatted currency string.
42
+ *
43
+ * @example
44
+ * ```ts
45
+ * formatCurrency(1234.56); // "1.234,56 €" (es-ES default)
46
+ * formatCurrency(1234.56, "USD", "en-US"); // "$1,234.56"
47
+ * formatCurrency(1000, "JPY", "ja-JP"); // "¥1,000"
48
+ * ```
49
+ */
50
+ declare function formatCurrency(amount: number, currency?: string, locale?: string): string;
51
+
52
+ export { debounce, formatCurrency, isEmail };
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Debounces a function call by delaying its execution until after a specified wait period.
3
+ * Subsequent calls within the wait period reset the timer.
4
+ *
5
+ * @param fn - The function to debounce.
6
+ * @param wait - Milliseconds to wait before invoking the function. Defaults to 250ms.
7
+ * @returns A debounced version of the function.
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * const search = debounce((query: string) => {
12
+ * console.log('Searching:', query);
13
+ * }, 300);
14
+ *
15
+ * search('hello'); // Will execute after 300ms if no other calls are made
16
+ * ```
17
+ */
18
+ declare function debounce<T extends (...args: any[]) => any>(fn: T, wait?: number): (...args: Parameters<T>) => void;
19
+
20
+ /**
21
+ * Validates whether a string matches a basic email pattern.
22
+ *
23
+ * @param v - The string to validate.
24
+ * @returns `true` if the string is a valid email format, `false` otherwise.
25
+ *
26
+ * @example
27
+ * ```ts
28
+ * isEmail('user@example.com'); // true
29
+ * isEmail('invalid@'); // false
30
+ * isEmail(' test@domain.org '); // true (whitespace is trimmed)
31
+ * ```
32
+ */
33
+ declare function isEmail(v: string): boolean;
34
+
35
+ /**
36
+ * Formats a number as a localized currency string.
37
+ *
38
+ * @param amount - The numeric amount to format.
39
+ * @param currency - The currency code (e.g., "USD", "EUR", "JPY"). Defaults to "EUR".
40
+ * @param locale - The locale string (e.g., "en-US", "es-ES"). Defaults to "es-ES".
41
+ * @returns A formatted currency string.
42
+ *
43
+ * @example
44
+ * ```ts
45
+ * formatCurrency(1234.56); // "1.234,56 €" (es-ES default)
46
+ * formatCurrency(1234.56, "USD", "en-US"); // "$1,234.56"
47
+ * formatCurrency(1000, "JPY", "ja-JP"); // "¥1,000"
48
+ * ```
49
+ */
50
+ declare function formatCurrency(amount: number, currency?: string, locale?: string): string;
51
+
52
+ export { debounce, formatCurrency, isEmail };
package/dist/index.js ADDED
@@ -0,0 +1,25 @@
1
+ // src/debounce.ts
2
+ function debounce(fn, wait = 250) {
3
+ let t = null;
4
+ return (...args) => {
5
+ if (t) clearTimeout(t);
6
+ t = setTimeout(() => fn(...args), wait);
7
+ };
8
+ }
9
+
10
+ // src/validate.ts
11
+ var EMAIL_RE = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
12
+ function isEmail(v) {
13
+ return EMAIL_RE.test(v.trim());
14
+ }
15
+
16
+ // src/format.ts
17
+ function formatCurrency(amount, currency = "EUR", locale = "es-ES") {
18
+ return new Intl.NumberFormat(locale, { style: "currency", currency }).format(amount);
19
+ }
20
+ export {
21
+ debounce,
22
+ formatCurrency,
23
+ isEmail
24
+ };
25
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/debounce.ts","../src/validate.ts","../src/format.ts"],"sourcesContent":["/**\n * Debounces a function call by delaying its execution until after a specified wait period.\n * Subsequent calls within the wait period reset the timer.\n * \n * @param fn - The function to debounce.\n * @param wait - Milliseconds to wait before invoking the function. Defaults to 250ms.\n * @returns A debounced version of the function.\n * \n * @example\n * ```ts\n * const search = debounce((query: string) => {\n * console.log('Searching:', query);\n * }, 300);\n * \n * search('hello'); // Will execute after 300ms if no other calls are made\n * ```\n */\nexport function debounce<T extends (...args: any[]) => any>(fn: T, wait = 250) {\n let t: ReturnType<typeof setTimeout> | null = null;\n return (...args: Parameters<T>) => {\n if (t) clearTimeout(t);\n t = setTimeout(() => fn(...args), wait);\n };\n}\n","const EMAIL_RE = /^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/;\n\n/**\n * Validates whether a string matches a basic email pattern.\n * \n * @param v - The string to validate.\n * @returns `true` if the string is a valid email format, `false` otherwise.\n * \n * @example\n * ```ts\n * isEmail('user@example.com'); // true\n * isEmail('invalid@'); // false\n * isEmail(' test@domain.org '); // true (whitespace is trimmed)\n * ```\n */\nexport function isEmail(v: string): boolean {\n return EMAIL_RE.test(v.trim());\n}\n","/**\n * Formats a number as a localized currency string.\n * \n * @param amount - The numeric amount to format.\n * @param currency - The currency code (e.g., \"USD\", \"EUR\", \"JPY\"). Defaults to \"EUR\".\n * @param locale - The locale string (e.g., \"en-US\", \"es-ES\"). Defaults to \"es-ES\".\n * @returns A formatted currency string.\n * \n * @example\n * ```ts\n * formatCurrency(1234.56); // \"1.234,56 €\" (es-ES default)\n * formatCurrency(1234.56, \"USD\", \"en-US\"); // \"$1,234.56\"\n * formatCurrency(1000, \"JPY\", \"ja-JP\"); // \"¥1,000\"\n * ```\n */\nexport function formatCurrency(\n amount: number,\n currency = \"EUR\",\n locale = \"es-ES\"\n): string {\n return new Intl.NumberFormat(locale, { style: \"currency\", currency }).format(amount);\n}\n"],"mappings":";AAiBO,SAAS,SAA4C,IAAO,OAAO,KAAK;AAC7E,MAAI,IAA0C;AAC9C,SAAO,IAAI,SAAwB;AACjC,QAAI,EAAG,cAAa,CAAC;AACrB,QAAI,WAAW,MAAM,GAAG,GAAG,IAAI,GAAG,IAAI;AAAA,EACxC;AACF;;;ACvBA,IAAM,WAAW;AAeV,SAAS,QAAQ,GAAoB;AAC1C,SAAO,SAAS,KAAK,EAAE,KAAK,CAAC;AAC/B;;;ACFO,SAAS,eACd,QACA,WAAW,OACX,SAAS,SACD;AACR,SAAO,IAAI,KAAK,aAAa,QAAQ,EAAE,OAAO,YAAY,SAAS,CAAC,EAAE,OAAO,MAAM;AACrF;","names":[]}
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "kompkit-core",
3
+ "version": "0.2.0-alpha.0",
4
+ "description": "Cross-platform utility functions for web applications. Part of the KompKit ecosystem.",
5
+ "type": "module",
6
+ "main": "dist/index.cjs",
7
+ "module": "dist/index.js",
8
+ "types": "dist/index.d.ts",
9
+ "license": "MIT",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/Kompkit/KompKit.git",
13
+ "directory": "packages/core/web"
14
+ },
15
+ "homepage": "https://github.com/Kompkit/KompKit",
16
+ "bugs": "https://github.com/Kompkit/KompKit/issues",
17
+ "keywords": [
18
+ "utilities",
19
+ "debounce",
20
+ "validation",
21
+ "email",
22
+ "currency",
23
+ "format",
24
+ "cross-platform"
25
+ ],
26
+ "files": [
27
+ "dist",
28
+ "LICENSE"
29
+ ],
30
+ "scripts": {
31
+ "build": "tsup",
32
+ "test": "vitest run",
33
+ "docs": "typedoc"
34
+ },
35
+ "devDependencies": {
36
+ "typedoc": "^0.28.16",
37
+ "vitest": "^3.0.0",
38
+ "tsup": "^8.5.0",
39
+ "typescript": "^5.7.0"
40
+ }
41
+ }