@swissgeo/log 1.0.0-beta.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.
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class a{msg;params;constructor(s,e){this.msg=s,this.params=e??{}}isEqual(s){return s.msg===this.msg&&Object.keys(this.params).length===Object.keys(s.params).length&&Object.keys(this.params).every(e=>this.params[e]===s.params[e])}}class t extends a{}class g extends a{}exports.ErrorMessage=t;exports.Message=a;exports.WarningMessage=g;
@@ -0,0 +1,19 @@
1
+ export declare class ErrorMessage extends Message {
2
+ }
3
+
4
+ /** @module swissgeo/log */
5
+ export declare class Message {
6
+ msg: string;
7
+ params: Record<string, unknown>;
8
+ /**
9
+ * @param msg Translation key message
10
+ * @param params Translation params to pass to i18n (used for message formatting)
11
+ */
12
+ constructor(msg: string, params?: Record<string, unknown>);
13
+ isEqual(object: Message): boolean;
14
+ }
15
+
16
+ export declare class WarningMessage extends Message {
17
+ }
18
+
19
+ export { }
@@ -0,0 +1,23 @@
1
+ class r {
2
+ msg;
3
+ params;
4
+ /**
5
+ * @param msg Translation key message
6
+ * @param params Translation params to pass to i18n (used for message formatting)
7
+ */
8
+ constructor(s, a) {
9
+ this.msg = s, this.params = a ?? {};
10
+ }
11
+ isEqual(s) {
12
+ return s.msg === this.msg && Object.keys(this.params).length === Object.keys(s.params).length && Object.keys(this.params).every((a) => this.params[a] === s.params[a]);
13
+ }
14
+ }
15
+ class t extends r {
16
+ }
17
+ class m extends r {
18
+ }
19
+ export {
20
+ t as ErrorMessage,
21
+ r as Message,
22
+ m as WarningMessage
23
+ };
package/dist/index.cjs ADDED
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});var h=(t=>(t[t.Error=0]="Error",t[t.Warn=1]="Warn",t[t.Info=2]="Info",t[t.Debug=3]="Debug",t))(h||{}),a=(t=>(t.Red="oklch(63.7% 0.237 25.331)",t.Orange="oklch(70.5% 0.213 47.604)",t.Amber="oklch(76.9% 0.188 70.08)",t.Yellow="oklch(79.5% 0.184 86.047)",t.Lime="oklch(76.8% 0.233 130.85)",t.Green="oklch(72.3% 0.219 149.579)",t.Emerald="oklch(69.6% 0.17 162.48)",t.Teal="oklch(70.4% 0.14 182.503)",t.Cyan="oklch(71.5% 0.143 215.221)",t.Sky="oklch(68.5% 0.169 237.323)",t.Blue="oklch(62.3% 0.214 259.815)",t.Indigo="oklch(58.5% 0.233 277.117)",t.Violet="oklch(60.6% 0.25 292.717)",t.Purple="oklch(62.7% 0.265 303.9)",t.Fuchsia="oklch(66.7% 0.295 322.15)",t.Pink="oklch(65.6% 0.241 354.308)",t.Rose="oklch(64.5% 0.246 16.439)",t.Slate="oklch(55.4% 0.046 257.417)",t.Gray="oklch(55.1% 0.027 264.364)",t.Zinc="oklch(55.2% 0.016 285.938)",t.Neutral="oklch(55.6% 0 0)",t.Stone="oklch(55.3% 0.013 58.071)",t))(a||{});function i(t){return`color: #000; font-weight: bold; background-color: ${t}; padding: 2px 4px; border-radius: 4px;`}function u(t){return t.flatMap(c=>{if(c&&typeof c=="object"&&"messages"in c&&Array.isArray(c.messages)){const l=[];if("title"in c&&typeof c.title=="string"){l.push(`%c[${c.title}]%c`);let n="oklch(55.4% 0.046 257.417)";"titleColor"in c&&typeof c.titleColor=="string"&&(n=c.titleColor),l.push(i(n)),l.push("")}return l.push(...c.messages),l}return c})}function k(t,c){if(r.wantedLevels.includes(t))switch(t){case 0:console.error(...u(c));break;case 1:console.warn(...u(c));break;case 2:console.info(...u(c));break;case 3:console.debug(...u(c));break}}const r={wantedLevels:[0,1],error:(...t)=>k(0,t),warn:(...t)=>k(1,t),info:(...t)=>k(2,t),debug:(...t)=>k(3,t)};exports.LogLevel=h;exports.LogPreDefinedColor=a;exports.default=r;
@@ -0,0 +1,66 @@
1
+ /**
2
+ * Logs the provided parameters to the console.
3
+ *
4
+ * By default, only calls with LogLevel.Error and LogLevel.Warn will be logged (calls to info and
5
+ * debug will be ignored). If you want more logging, set the variable `log.wantedLevels` to your
6
+ * desired list of LogLevel
7
+ */
8
+ declare const log: SwissGeoLog;
9
+ export default log;
10
+
11
+ /** @module swissgeo/log */
12
+ /** A log level reference. The levels correspond to the native console methods and their log level. */
13
+ export declare enum LogLevel {
14
+ Error = 0,
15
+ Warn = 1,
16
+ Info = 2,
17
+ Debug = 3
18
+ }
19
+
20
+ /**
21
+ * Colors coming from TailwindCSS colors, taking the column 500
22
+ *
23
+ * @see https://tailwindcss.com/docs/colors
24
+ */
25
+ export declare enum LogPreDefinedColor {
26
+ Red = "oklch(63.7% 0.237 25.331)",
27
+ Orange = "oklch(70.5% 0.213 47.604)",
28
+ Amber = "oklch(76.9% 0.188 70.08)",
29
+ Yellow = "oklch(79.5% 0.184 86.047)",
30
+ Lime = "oklch(76.8% 0.233 130.85)",
31
+ Green = "oklch(72.3% 0.219 149.579)",
32
+ Emerald = "oklch(69.6% 0.17 162.48)",
33
+ Teal = "oklch(70.4% 0.14 182.503)",
34
+ Cyan = "oklch(71.5% 0.143 215.221)",
35
+ Sky = "oklch(68.5% 0.169 237.323)",
36
+ Blue = "oklch(62.3% 0.214 259.815)",
37
+ Indigo = "oklch(58.5% 0.233 277.117)",
38
+ Violet = "oklch(60.6% 0.25 292.717)",
39
+ Purple = "oklch(62.7% 0.265 303.9)",
40
+ Fuchsia = "oklch(66.7% 0.295 322.15)",
41
+ Pink = "oklch(65.6% 0.241 354.308)",
42
+ Rose = "oklch(64.5% 0.246 16.439)",
43
+ Slate = "oklch(55.4% 0.046 257.417)",
44
+ Gray = "oklch(55.1% 0.027 264.364)",
45
+ Zinc = "oklch(55.2% 0.016 285.938)",
46
+ Neutral = "oklch(55.6% 0 0)",
47
+ Stone = "oklch(55.3% 0.013 58.071)"
48
+ }
49
+
50
+ declare interface SwissGeoLog {
51
+ wantedLevels: LogLevel[];
52
+ debug: (...messages: SwissGeoLogInput[]) => void;
53
+ info: (...messages: SwissGeoLogInput[]) => void;
54
+ warn: (...messages: SwissGeoLogInput[]) => void;
55
+ error: (...messages: SwissGeoLogInput[]) => void;
56
+ }
57
+
58
+ export declare type SwissGeoLogInput = SwissGeoLogMessage | string | number | boolean | object;
59
+
60
+ declare interface SwissGeoLogMessage {
61
+ title?: string;
62
+ titleColor?: LogPreDefinedColor | string;
63
+ messages: SwissGeoLogInput[];
64
+ }
65
+
66
+ export { }
package/dist/index.js ADDED
@@ -0,0 +1,51 @@
1
+ var u = /* @__PURE__ */ ((c) => (c[c.Error = 0] = "Error", c[c.Warn = 1] = "Warn", c[c.Info = 2] = "Info", c[c.Debug = 3] = "Debug", c))(u || {}), a = /* @__PURE__ */ ((c) => (c.Red = "oklch(63.7% 0.237 25.331)", c.Orange = "oklch(70.5% 0.213 47.604)", c.Amber = "oklch(76.9% 0.188 70.08)", c.Yellow = "oklch(79.5% 0.184 86.047)", c.Lime = "oklch(76.8% 0.233 130.85)", c.Green = "oklch(72.3% 0.219 149.579)", c.Emerald = "oklch(69.6% 0.17 162.48)", c.Teal = "oklch(70.4% 0.14 182.503)", c.Cyan = "oklch(71.5% 0.143 215.221)", c.Sky = "oklch(68.5% 0.169 237.323)", c.Blue = "oklch(62.3% 0.214 259.815)", c.Indigo = "oklch(58.5% 0.233 277.117)", c.Violet = "oklch(60.6% 0.25 292.717)", c.Purple = "oklch(62.7% 0.265 303.9)", c.Fuchsia = "oklch(66.7% 0.295 322.15)", c.Pink = "oklch(65.6% 0.241 354.308)", c.Rose = "oklch(64.5% 0.246 16.439)", c.Slate = "oklch(55.4% 0.046 257.417)", c.Gray = "oklch(55.1% 0.027 264.364)", c.Zinc = "oklch(55.2% 0.016 285.938)", c.Neutral = "oklch(55.6% 0 0)", c.Stone = "oklch(55.3% 0.013 58.071)", c))(a || {});
2
+ function r(c) {
3
+ return `color: #000; font-weight: bold; background-color: ${c}; padding: 2px 4px; border-radius: 4px;`;
4
+ }
5
+ function l(c) {
6
+ return c.flatMap((t) => {
7
+ if (t && typeof t == "object" && "messages" in t && Array.isArray(t.messages)) {
8
+ const k = [];
9
+ if ("title" in t && typeof t.title == "string") {
10
+ k.push(`%c[${t.title}]%c`);
11
+ let n = "oklch(55.4% 0.046 257.417)";
12
+ "titleColor" in t && typeof t.titleColor == "string" && (n = t.titleColor), k.push(r(n)), k.push("");
13
+ }
14
+ return k.push(...t.messages), k;
15
+ }
16
+ return t;
17
+ });
18
+ }
19
+ function h(c, t) {
20
+ if (p.wantedLevels.includes(c))
21
+ switch (c) {
22
+ case 0:
23
+ console.error(...l(t));
24
+ break;
25
+ case 1:
26
+ console.warn(...l(t));
27
+ break;
28
+ case 2:
29
+ console.info(...l(t));
30
+ break;
31
+ case 3:
32
+ console.debug(...l(t));
33
+ break;
34
+ }
35
+ }
36
+ const p = {
37
+ wantedLevels: [
38
+ 0,
39
+ 1
40
+ /* Warn */
41
+ ],
42
+ error: (...c) => h(0, c),
43
+ warn: (...c) => h(1, c),
44
+ info: (...c) => h(2, c),
45
+ debug: (...c) => h(3, c)
46
+ };
47
+ export {
48
+ u as LogLevel,
49
+ a as LogPreDefinedColor,
50
+ p as default
51
+ };
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "@swissgeo/log",
3
+ "version": "1.0.0-beta.1",
4
+ "description": "Logging utils for SWISSGEO projects.",
5
+ "license": "BSD-3-Clause",
6
+ "type": "module",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "import": "./dist/index.js",
11
+ "require": "./dist/index.umd.cjs"
12
+ },
13
+ "./Message": {
14
+ "types": "./dist/Message.d.ts",
15
+ "import": "./dist/Message.js",
16
+ "require": "./dist/Message.umd.js"
17
+ }
18
+ },
19
+ "files": [
20
+ "dist"
21
+ ],
22
+ "scripts": {
23
+ "build": "pnpm run type-check && pnpm run generate-types && vite build",
24
+ "build:dev": "pnpm run build --mode development",
25
+ "build:dev:watch": "pnpm run build --watch --mode development",
26
+ "build:int": "pnpm run build --mode integration",
27
+ "build:prod": "pnpm run build --mode production",
28
+ "dev": "vite",
29
+ "generate-types": "tsc --declaration",
30
+ "lint": "eslint --fix",
31
+ "lint:no-fix": "eslint",
32
+ "type-check": "tsc -p tsconfig.json"
33
+ },
34
+ "devDependencies": {
35
+ "@microsoft/api-extractor": "catalog:",
36
+ "@prettier/plugin-xml": "catalog:",
37
+ "@swissgeo/config-eslint": "workspace:*",
38
+ "@swissgeo/config-prettier": "workspace:*",
39
+ "@swissgeo/config-typescript": "workspace:*",
40
+ "eslint": "catalog:",
41
+ "prettier": "catalog:",
42
+ "prettier-plugin-jsdoc": "catalog:",
43
+ "prettier-plugin-packagejson": "catalog:",
44
+ "prettier-plugin-tailwindcss": "catalog:",
45
+ "typescript": "catalog:",
46
+ "unplugin-dts": "catalog:",
47
+ "vite": "catalog:"
48
+ },
49
+ "peerDependencies": {
50
+ "proj4": "catalog:"
51
+ }
52
+ }