@kuroson/common-utils 0.2.1

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 ADDED
@@ -0,0 +1,32 @@
1
+ # @kuroson/common-utils
2
+
3
+ ## 0.2.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 61adb1e: Updated dependency `@typescript-eslint/eslint-plugin` to `8.50.1`.
8
+ Updated dependency `@typescript-eslint/parser` to `8.50.1`.
9
+ Updated dependency `typescript-eslint` to `8.50.1`.
10
+ Updated dependency `next` to `16.1.1`.
11
+ Updated dependency `eslint-config-next` to `16.1.1`.
12
+ Updated dependency `@next/third-parties` to `16.1.1`.
13
+ Updated dependency `ldapts` to `8.0.31`.
14
+ Updated dependency `@next/eslint-plugin-next` to `16.1.1`.
15
+ Updated dependency `eslint-plugin-jest` to `29.10.1`.
16
+ Updated dependency `nodemailer` to `7.0.12`.
17
+
18
+ ## 0.2.0
19
+
20
+ ### Minor Changes
21
+
22
+ - cdb0acc: Initial release
23
+
24
+ ## 0.1.0
25
+
26
+ ### Features
27
+
28
+ - Initial release
29
+ - Added `sleep` utility function
30
+ - Added `parseError` utility function
31
+ - Added `Prettify` type utility
32
+ - Added error classes: `InputError`, `RuntimeError`, `SettingsError`, `HTTPError`
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Alvin Cherk
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/README.md ADDED
@@ -0,0 +1,21 @@
1
+ # @kuroson/common-utils
2
+
3
+ Common utility functions and types for my TypeScript/JavaScript projects.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @kuroson/common-utils
9
+ # or
10
+ pnpm add @kuroson/common-utils
11
+ # or
12
+ yarn add @kuroson/common-utils
13
+ ```
14
+
15
+ ## Requirements
16
+
17
+ - Node.js >= 22
18
+
19
+ ## License
20
+
21
+ MIT
package/dist/index.cjs ADDED
@@ -0,0 +1,61 @@
1
+ 'use strict';
2
+
3
+ // src/index.ts
4
+ var sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
5
+ var InputError = class extends Error {
6
+ constructor(message, options) {
7
+ super(message, options);
8
+ this.name = "InputError";
9
+ }
10
+ };
11
+ var RuntimeError = class extends Error {
12
+ constructor(message, options) {
13
+ super(message, options);
14
+ this.name = "RuntimeError";
15
+ }
16
+ };
17
+ var SettingsError = class extends Error {
18
+ constructor(message, options) {
19
+ super(message, options);
20
+ this.name = "SettingsError";
21
+ }
22
+ };
23
+ var HTTPError = class extends Error {
24
+ status;
25
+ message;
26
+ originalError;
27
+ constructor(status, message, originalError = void 0) {
28
+ super(message);
29
+ this.status = status;
30
+ this.message = message;
31
+ this.originalError = originalError;
32
+ }
33
+ getStatusCode() {
34
+ return this.status;
35
+ }
36
+ getMessage() {
37
+ return this.message;
38
+ }
39
+ };
40
+ var parseError = (err) => {
41
+ if (err instanceof Error) {
42
+ return err.message;
43
+ }
44
+ if (typeof err === "string") {
45
+ return err;
46
+ }
47
+ try {
48
+ return JSON.stringify(err);
49
+ } catch {
50
+ return String(err);
51
+ }
52
+ };
53
+
54
+ exports.HTTPError = HTTPError;
55
+ exports.InputError = InputError;
56
+ exports.RuntimeError = RuntimeError;
57
+ exports.SettingsError = SettingsError;
58
+ exports.parseError = parseError;
59
+ exports.sleep = sleep;
60
+ //# sourceMappingURL=index.cjs.map
61
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;AAAO,IAAM,KAAA,GAAQ,CAAC,EAAA,KAA8B,IAAI,OAAA,CAAQ,CAAC,OAAA,KAAY,UAAA,CAAW,OAAA,EAAS,EAAE,CAAC;AAK7F,IAAM,UAAA,GAAN,cAAyB,KAAA,CAAM;AAAA,EACpC,WAAA,CAAY,SAAiB,OAAA,EAAwB;AACnD,IAAA,KAAA,CAAM,SAAS,OAAO,CAAA;AACtB,IAAA,IAAA,CAAK,IAAA,GAAO,YAAA;AAAA,EACd;AACF;AAEO,IAAM,YAAA,GAAN,cAA2B,KAAA,CAAM;AAAA,EACtC,WAAA,CAAY,SAAiB,OAAA,EAAwB;AACnD,IAAA,KAAA,CAAM,SAAS,OAAO,CAAA;AACtB,IAAA,IAAA,CAAK,IAAA,GAAO,cAAA;AAAA,EACd;AACF;AAEO,IAAM,aAAA,GAAN,cAA4B,KAAA,CAAM;AAAA,EACvC,WAAA,CAAY,SAAiB,OAAA,EAAwB;AACnD,IAAA,KAAA,CAAM,SAAS,OAAO,CAAA;AACtB,IAAA,IAAA,CAAK,IAAA,GAAO,eAAA;AAAA,EACd;AACF;AAEO,IAAM,SAAA,GAAN,cAAwB,KAAA,CAAM;AAAA,EAC5B,MAAA;AAAA,EACS,OAAA;AAAA,EACT,aAAA;AAAA,EAEP,WAAA,CAAY,MAAA,EAAgB,OAAA,EAAiB,aAAA,GAAqB,MAAA,EAAW;AAC3E,IAAA,KAAA,CAAM,OAAO,CAAA;AACb,IAAA,IAAA,CAAK,MAAA,GAAS,MAAA;AACd,IAAA,IAAA,CAAK,OAAA,GAAU,OAAA;AAEf,IAAA,IAAA,CAAK,aAAA,GAAgB,aAAA;AAAA,EACvB;AAAA,EAEO,aAAA,GAAwB;AAC7B,IAAA,OAAO,IAAA,CAAK,MAAA;AAAA,EACd;AAAA,EAEO,UAAA,GAAqB;AAC1B,IAAA,OAAO,IAAA,CAAK,OAAA;AAAA,EACd;AACF;AAOO,IAAM,UAAA,GAAuC,CAAC,GAAA,KAAyB;AAC5E,EAAA,IAAI,eAAe,KAAA,EAAO;AACxB,IAAA,OAAO,GAAA,CAAI,OAAA;AAAA,EACb;AACA,EAAA,IAAI,OAAO,QAAQ,QAAA,EAAU;AAC3B,IAAA,OAAO,GAAA;AAAA,EACT;AACA,EAAA,IAAI;AACF,IAAA,OAAO,IAAA,CAAK,UAAU,GAAG,CAAA;AAAA,EAC3B,CAAA,CAAA,MAAQ;AACN,IAAA,OAAO,OAAO,GAAG,CAAA;AAAA,EACnB;AACF","file":"index.cjs","sourcesContent":["export const sleep = (ms: number): Promise<void> => new Promise((resolve) => setTimeout(resolve, ms));\nexport type Prettify<T> = {\n [K in keyof T]: T[K];\n} & {};\n\nexport class InputError extends Error {\n constructor(message: string, options?: ErrorOptions) {\n super(message, options);\n this.name = 'InputError';\n }\n}\n\nexport class RuntimeError extends Error {\n constructor(message: string, options?: ErrorOptions) {\n super(message, options);\n this.name = 'RuntimeError';\n }\n}\n\nexport class SettingsError extends Error {\n constructor(message: string, options?: ErrorOptions) {\n super(message, options);\n this.name = 'SettingsError';\n }\n}\n\nexport class HTTPError extends Error {\n public status: number;\n public override message: string;\n public originalError: any;\n\n constructor(status: number, message: string, originalError: any = undefined) {\n super(message);\n this.status = status;\n this.message = message;\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n this.originalError = originalError;\n }\n\n public getStatusCode(): number {\n return this.status;\n }\n\n public getMessage(): string {\n return this.message;\n }\n}\n\n/**\n * Attempts to decode an error into a string to be logged\n * @param err error to be decoded\n * @returns A string representation of the error\n */\nexport const parseError: (err: unknown) => string = (err: unknown): string => {\n if (err instanceof Error) {\n return err.message;\n }\n if (typeof err === 'string') {\n return err;\n }\n try {\n return JSON.stringify(err);\n } catch {\n return String(err);\n }\n};\n"]}
@@ -0,0 +1,29 @@
1
+ declare const sleep: (ms: number) => Promise<void>;
2
+ type Prettify<T> = {
3
+ [K in keyof T]: T[K];
4
+ } & {};
5
+ declare class InputError extends Error {
6
+ constructor(message: string, options?: ErrorOptions);
7
+ }
8
+ declare class RuntimeError extends Error {
9
+ constructor(message: string, options?: ErrorOptions);
10
+ }
11
+ declare class SettingsError extends Error {
12
+ constructor(message: string, options?: ErrorOptions);
13
+ }
14
+ declare class HTTPError extends Error {
15
+ status: number;
16
+ message: string;
17
+ originalError: any;
18
+ constructor(status: number, message: string, originalError?: any);
19
+ getStatusCode(): number;
20
+ getMessage(): string;
21
+ }
22
+ /**
23
+ * Attempts to decode an error into a string to be logged
24
+ * @param err error to be decoded
25
+ * @returns A string representation of the error
26
+ */
27
+ declare const parseError: (err: unknown) => string;
28
+
29
+ export { HTTPError, InputError, type Prettify, RuntimeError, SettingsError, parseError, sleep };
@@ -0,0 +1,29 @@
1
+ declare const sleep: (ms: number) => Promise<void>;
2
+ type Prettify<T> = {
3
+ [K in keyof T]: T[K];
4
+ } & {};
5
+ declare class InputError extends Error {
6
+ constructor(message: string, options?: ErrorOptions);
7
+ }
8
+ declare class RuntimeError extends Error {
9
+ constructor(message: string, options?: ErrorOptions);
10
+ }
11
+ declare class SettingsError extends Error {
12
+ constructor(message: string, options?: ErrorOptions);
13
+ }
14
+ declare class HTTPError extends Error {
15
+ status: number;
16
+ message: string;
17
+ originalError: any;
18
+ constructor(status: number, message: string, originalError?: any);
19
+ getStatusCode(): number;
20
+ getMessage(): string;
21
+ }
22
+ /**
23
+ * Attempts to decode an error into a string to be logged
24
+ * @param err error to be decoded
25
+ * @returns A string representation of the error
26
+ */
27
+ declare const parseError: (err: unknown) => string;
28
+
29
+ export { HTTPError, InputError, type Prettify, RuntimeError, SettingsError, parseError, sleep };
package/dist/index.js ADDED
@@ -0,0 +1,54 @@
1
+ // src/index.ts
2
+ var sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
3
+ var InputError = class extends Error {
4
+ constructor(message, options) {
5
+ super(message, options);
6
+ this.name = "InputError";
7
+ }
8
+ };
9
+ var RuntimeError = class extends Error {
10
+ constructor(message, options) {
11
+ super(message, options);
12
+ this.name = "RuntimeError";
13
+ }
14
+ };
15
+ var SettingsError = class extends Error {
16
+ constructor(message, options) {
17
+ super(message, options);
18
+ this.name = "SettingsError";
19
+ }
20
+ };
21
+ var HTTPError = class extends Error {
22
+ status;
23
+ message;
24
+ originalError;
25
+ constructor(status, message, originalError = void 0) {
26
+ super(message);
27
+ this.status = status;
28
+ this.message = message;
29
+ this.originalError = originalError;
30
+ }
31
+ getStatusCode() {
32
+ return this.status;
33
+ }
34
+ getMessage() {
35
+ return this.message;
36
+ }
37
+ };
38
+ var parseError = (err) => {
39
+ if (err instanceof Error) {
40
+ return err.message;
41
+ }
42
+ if (typeof err === "string") {
43
+ return err;
44
+ }
45
+ try {
46
+ return JSON.stringify(err);
47
+ } catch {
48
+ return String(err);
49
+ }
50
+ };
51
+
52
+ export { HTTPError, InputError, RuntimeError, SettingsError, parseError, sleep };
53
+ //# sourceMappingURL=index.js.map
54
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";AAAO,IAAM,KAAA,GAAQ,CAAC,EAAA,KAA8B,IAAI,OAAA,CAAQ,CAAC,OAAA,KAAY,UAAA,CAAW,OAAA,EAAS,EAAE,CAAC;AAK7F,IAAM,UAAA,GAAN,cAAyB,KAAA,CAAM;AAAA,EACpC,WAAA,CAAY,SAAiB,OAAA,EAAwB;AACnD,IAAA,KAAA,CAAM,SAAS,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,CAAA,MAAQ;AACN,IAAA,OAAO,OAAO,GAAG,CAAA;AAAA,EACnB;AACF","file":"index.js","sourcesContent":["export const sleep = (ms: number): Promise<void> => new Promise((resolve) => setTimeout(resolve, ms));\nexport type Prettify<T> = {\n [K in keyof T]: T[K];\n} & {};\n\nexport class InputError extends Error {\n constructor(message: string, options?: ErrorOptions) {\n super(message, options);\n this.name = 'InputError';\n }\n}\n\nexport class RuntimeError extends Error {\n constructor(message: string, options?: ErrorOptions) {\n super(message, options);\n this.name = 'RuntimeError';\n }\n}\n\nexport class SettingsError extends Error {\n constructor(message: string, options?: ErrorOptions) {\n super(message, options);\n this.name = 'SettingsError';\n }\n}\n\nexport class HTTPError extends Error {\n public status: number;\n public override message: string;\n public originalError: any;\n\n constructor(status: number, message: string, originalError: any = undefined) {\n super(message);\n this.status = status;\n this.message = message;\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n this.originalError = originalError;\n }\n\n public getStatusCode(): number {\n return this.status;\n }\n\n public getMessage(): string {\n return this.message;\n }\n}\n\n/**\n * Attempts to decode an error into a string to be logged\n * @param err error to be decoded\n * @returns A string representation of the error\n */\nexport const parseError: (err: unknown) => string = (err: unknown): string => {\n if (err instanceof Error) {\n return err.message;\n }\n if (typeof err === 'string') {\n return err;\n }\n try {\n return JSON.stringify(err);\n } catch {\n return String(err);\n }\n};\n"]}
package/package.json ADDED
@@ -0,0 +1,69 @@
1
+ {
2
+ "name": "@kuroson/common-utils",
3
+ "version": "0.2.1",
4
+ "description": "Common utility functions and types",
5
+ "license": "MIT",
6
+ "author": "Alvin Cherk <a.cherk@unsw.edu.au>",
7
+ "type": "module",
8
+ "exports": {
9
+ ".": {
10
+ "import": {
11
+ "types": "./dist/index.d.ts",
12
+ "default": "./dist/index.js"
13
+ },
14
+ "require": {
15
+ "types": "./dist/index.d.cts",
16
+ "default": "./dist/index.cjs"
17
+ }
18
+ },
19
+ "./package.json": "./package.json"
20
+ },
21
+ "main": "./dist/index.cjs",
22
+ "module": "./dist/index.js",
23
+ "types": "./dist/index.d.ts",
24
+ "files": [
25
+ "dist",
26
+ "package.json",
27
+ "README.md",
28
+ "LICENSE",
29
+ "CHANGELOG.md"
30
+ ],
31
+ "devDependencies": {
32
+ "@eslint/js": "9.39.2",
33
+ "@typescript-eslint/eslint-plugin": "8.50.1",
34
+ "depcheck": "1.4.7",
35
+ "eslint": "9.39.2",
36
+ "eslint-config-prettier": "10.1.8",
37
+ "eslint-plugin-prettier": "5.5.4",
38
+ "eslint-plugin-unused-imports": "4.3.0",
39
+ "prettier": "3.7.4",
40
+ "tsup": "8.5.1",
41
+ "typescript": "5.9.3",
42
+ "typescript-eslint": "8.50.1"
43
+ },
44
+ "peerDependencies": {
45
+ "typescript": ">=4.7.0"
46
+ },
47
+ "peerDependenciesMeta": {
48
+ "typescript": {
49
+ "optional": true
50
+ }
51
+ },
52
+ "engines": {
53
+ "node": ">=22"
54
+ },
55
+ "publishConfig": {
56
+ "access": "public"
57
+ },
58
+ "depcheck": {
59
+ "ignores": [],
60
+ "skip-missing": true
61
+ },
62
+ "scripts": {
63
+ "build:all": "tsup",
64
+ "depcheck": "depcheck",
65
+ "lint": "eslint './**/*.{ts,js}'",
66
+ "lint:fix": "eslint './**/*.{ts,js}' --fix",
67
+ "typecheck": "tsc --noEmit"
68
+ }
69
+ }