@fuzdev/fuz_util 0.42.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 +21 -0
- package/README.md +83 -0
- package/dist/array.d.ts +15 -0
- package/dist/array.d.ts.map +1 -0
- package/dist/array.js +25 -0
- package/dist/async.d.ts +62 -0
- package/dist/async.d.ts.map +1 -0
- package/dist/async.js +147 -0
- package/dist/colors.d.ts +41 -0
- package/dist/colors.d.ts.map +1 -0
- package/dist/colors.js +106 -0
- package/dist/counter.d.ts +7 -0
- package/dist/counter.d.ts.map +1 -0
- package/dist/counter.js +7 -0
- package/dist/deep_equal.d.ts +18 -0
- package/dist/deep_equal.d.ts.map +1 -0
- package/dist/deep_equal.js +152 -0
- package/dist/dom.d.ts +35 -0
- package/dist/dom.d.ts.map +1 -0
- package/dist/dom.js +95 -0
- package/dist/error.d.ts +15 -0
- package/dist/error.d.ts.map +1 -0
- package/dist/error.js +18 -0
- package/dist/fetch.d.ts +81 -0
- package/dist/fetch.d.ts.map +1 -0
- package/dist/fetch.js +162 -0
- package/dist/fs.d.ts +34 -0
- package/dist/fs.d.ts.map +1 -0
- package/dist/fs.js +73 -0
- package/dist/function.d.ts +27 -0
- package/dist/function.d.ts.map +1 -0
- package/dist/function.js +21 -0
- package/dist/git.d.ts +132 -0
- package/dist/git.d.ts.map +1 -0
- package/dist/git.js +288 -0
- package/dist/id.d.ts +18 -0
- package/dist/id.d.ts.map +1 -0
- package/dist/id.js +18 -0
- package/dist/iterator.d.ts +5 -0
- package/dist/iterator.d.ts.map +1 -0
- package/dist/iterator.js +9 -0
- package/dist/json.d.ts +30 -0
- package/dist/json.d.ts.map +1 -0
- package/dist/json.js +44 -0
- package/dist/library_json.d.ts +42 -0
- package/dist/library_json.d.ts.map +1 -0
- package/dist/library_json.js +76 -0
- package/dist/log.d.ts +188 -0
- package/dist/log.d.ts.map +1 -0
- package/dist/log.js +393 -0
- package/dist/map.d.ts +12 -0
- package/dist/map.d.ts.map +1 -0
- package/dist/map.js +14 -0
- package/dist/maths.d.ts +85 -0
- package/dist/maths.d.ts.map +1 -0
- package/dist/maths.js +87 -0
- package/dist/object.d.ts +46 -0
- package/dist/object.d.ts.map +1 -0
- package/dist/object.js +89 -0
- package/dist/package_json.d.ts +90 -0
- package/dist/package_json.d.ts.map +1 -0
- package/dist/package_json.js +112 -0
- package/dist/path.d.ts +63 -0
- package/dist/path.d.ts.map +1 -0
- package/dist/path.js +83 -0
- package/dist/print.d.ts +52 -0
- package/dist/print.d.ts.map +1 -0
- package/dist/print.js +89 -0
- package/dist/process.d.ts +77 -0
- package/dist/process.d.ts.map +1 -0
- package/dist/process.js +148 -0
- package/dist/random.d.ts +25 -0
- package/dist/random.d.ts.map +1 -0
- package/dist/random.js +35 -0
- package/dist/random_alea.d.ts +23 -0
- package/dist/random_alea.d.ts.map +1 -0
- package/dist/random_alea.js +95 -0
- package/dist/regexp.d.ts +12 -0
- package/dist/regexp.d.ts.map +1 -0
- package/dist/regexp.js +16 -0
- package/dist/result.d.ts +64 -0
- package/dist/result.d.ts.map +1 -0
- package/dist/result.js +48 -0
- package/dist/source_json.d.ts +375 -0
- package/dist/source_json.d.ts.map +1 -0
- package/dist/source_json.js +189 -0
- package/dist/string.d.ts +51 -0
- package/dist/string.d.ts.map +1 -0
- package/dist/string.js +92 -0
- package/dist/throttle.d.ts +26 -0
- package/dist/throttle.d.ts.map +1 -0
- package/dist/throttle.js +53 -0
- package/dist/timings.d.ts +33 -0
- package/dist/timings.d.ts.map +1 -0
- package/dist/timings.js +75 -0
- package/dist/types.d.ts +77 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +10 -0
- package/dist/url.d.ts +10 -0
- package/dist/url.d.ts.map +1 -0
- package/dist/url.js +8 -0
- package/package.json +125 -0
- package/src/lib/array.ts +30 -0
- package/src/lib/async.ts +182 -0
- package/src/lib/colors.ts +132 -0
- package/src/lib/counter.ts +11 -0
- package/src/lib/deep_equal.ts +155 -0
- package/src/lib/dom.ts +108 -0
- package/src/lib/error.ts +22 -0
- package/src/lib/fetch.ts +231 -0
- package/src/lib/fs.ts +128 -0
- package/src/lib/function.ts +32 -0
- package/src/lib/git.ts +390 -0
- package/src/lib/id.ts +30 -0
- package/src/lib/iterator.ts +8 -0
- package/src/lib/json.ts +61 -0
- package/src/lib/library_json.ts +122 -0
- package/src/lib/log.ts +469 -0
- package/src/lib/map.ts +18 -0
- package/src/lib/maths.ts +91 -0
- package/src/lib/object.ts +110 -0
- package/src/lib/package_json.ts +135 -0
- package/src/lib/path.ts +137 -0
- package/src/lib/print.ts +111 -0
- package/src/lib/process.ts +207 -0
- package/src/lib/random.ts +48 -0
- package/src/lib/random_alea.ts +107 -0
- package/src/lib/regexp.ts +17 -0
- package/src/lib/result.ts +67 -0
- package/src/lib/source_json.ts +209 -0
- package/src/lib/string.ts +99 -0
- package/src/lib/throttle.ts +70 -0
- package/src/lib/timings.ts +93 -0
- package/src/lib/types.ts +99 -0
- package/src/lib/url.ts +14 -0
package/dist/json.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the `JsonType` of `value`, which is like `typeof json`
|
|
3
|
+
* but includes `'array'` and omits `'undefined'`.
|
|
4
|
+
*/
|
|
5
|
+
export const json_type_of = (value) => {
|
|
6
|
+
const type = typeof value;
|
|
7
|
+
switch (type) {
|
|
8
|
+
case 'string':
|
|
9
|
+
case 'number':
|
|
10
|
+
case 'boolean':
|
|
11
|
+
return type;
|
|
12
|
+
case 'object': {
|
|
13
|
+
return value === null ? 'null' : Array.isArray(value) ? 'array' : 'object';
|
|
14
|
+
}
|
|
15
|
+
default: {
|
|
16
|
+
// "undefined" | "function" | "bigint" | "symbol"
|
|
17
|
+
return undefined;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Embeds `data` as a JSON string, escaping single quotes.
|
|
23
|
+
* Useful for optimizing JSON in JS because it parses faster.
|
|
24
|
+
*/
|
|
25
|
+
export const json_embed = (data, stringify = JSON.stringify) => `JSON.parse('${stringify(data).replaceAll("'", "\\'").replaceAll('\n', '\\\n')}')`;
|
|
26
|
+
/**
|
|
27
|
+
* Serializes a value to JSON with deterministic key ordering.
|
|
28
|
+
* Recursively sorts object keys alphabetically for consistent hashing.
|
|
29
|
+
* Arrays and primitives are serialized as-is.
|
|
30
|
+
*
|
|
31
|
+
* @param value Any JSON-serializable value
|
|
32
|
+
* @returns Deterministic JSON string representation
|
|
33
|
+
*/
|
|
34
|
+
export const json_stringify_deterministic = (value) => JSON.stringify(value, (_key, val) => {
|
|
35
|
+
if (val !== null && typeof val === 'object' && !Array.isArray(val)) {
|
|
36
|
+
const sorted = {};
|
|
37
|
+
const keys = Object.keys(val).sort();
|
|
38
|
+
for (const k of keys) {
|
|
39
|
+
sorted[k] = val[k];
|
|
40
|
+
}
|
|
41
|
+
return sorted;
|
|
42
|
+
}
|
|
43
|
+
return val;
|
|
44
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Library metadata combining package.json with analyzed source.
|
|
3
|
+
*/
|
|
4
|
+
import type { PackageJson } from './package_json.js';
|
|
5
|
+
import type { SourceJson } from './source_json.js';
|
|
6
|
+
import type { Url } from './url.js';
|
|
7
|
+
/**
|
|
8
|
+
* A library's package.json and source metadata with computed properties.
|
|
9
|
+
*/
|
|
10
|
+
export interface LibraryJson {
|
|
11
|
+
package_json: PackageJson;
|
|
12
|
+
source_json: SourceJson;
|
|
13
|
+
/** Package name, e.g. `@ryanatkn/fuz`. */
|
|
14
|
+
name: string;
|
|
15
|
+
/** Name without scope, e.g. `fuz`. */
|
|
16
|
+
repo_name: string;
|
|
17
|
+
/** GitHub repo URL, e.g. `https://github.com/ryanatkn/fuz`. */
|
|
18
|
+
repo_url: Url;
|
|
19
|
+
/** GitHub user/org, e.g. `ryanatkn`. */
|
|
20
|
+
owner_name: string | null;
|
|
21
|
+
homepage_url: Url | null;
|
|
22
|
+
/** Logo URL, falls back to `favicon.png`. */
|
|
23
|
+
logo_url: Url | null;
|
|
24
|
+
logo_alt: string;
|
|
25
|
+
npm_url: Url | null;
|
|
26
|
+
changelog_url: Url | null;
|
|
27
|
+
/** True if has exports and version is not `0.0.1`. */
|
|
28
|
+
published: boolean;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Creates a `LibraryJson` with computed properties from package.json and source metadata.
|
|
32
|
+
*/
|
|
33
|
+
export declare const library_json_parse: (package_json: PackageJson, source_json: SourceJson) => LibraryJson;
|
|
34
|
+
/**
|
|
35
|
+
* Extracts repo name from a package name, e.g. `@ryanatkn/fuz` → `fuz`.
|
|
36
|
+
*/
|
|
37
|
+
export declare const library_repo_name_parse: (name: string) => string;
|
|
38
|
+
/**
|
|
39
|
+
* Extracts GitHub org URL from a library, e.g. `https://github.com/ryanatkn`.
|
|
40
|
+
*/
|
|
41
|
+
export declare const library_org_url_parse: (library: LibraryJson) => string | null;
|
|
42
|
+
//# sourceMappingURL=library_json.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"library_json.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/library_json.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,mBAAmB,CAAC;AACnD,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,kBAAkB,CAAC;AACjD,OAAO,KAAK,EAAC,GAAG,EAAC,MAAM,UAAU,CAAC;AAElC;;GAEG;AACH,MAAM,WAAW,WAAW;IAC3B,YAAY,EAAE,WAAW,CAAC;IAC1B,WAAW,EAAE,UAAU,CAAC;IACxB,0CAA0C;IAC1C,IAAI,EAAE,MAAM,CAAC;IACb,sCAAsC;IACtC,SAAS,EAAE,MAAM,CAAC;IAClB,+DAA+D;IAC/D,QAAQ,EAAE,GAAG,CAAC;IACd,wCAAwC;IACxC,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,YAAY,EAAE,GAAG,GAAG,IAAI,CAAC;IACzB,6CAA6C;IAC7C,QAAQ,EAAE,GAAG,GAAG,IAAI,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,GAAG,GAAG,IAAI,CAAC;IACpB,aAAa,EAAE,GAAG,GAAG,IAAI,CAAC;IAC1B,sDAAsD;IACtD,SAAS,EAAE,OAAO,CAAC;CACnB;AAED;;GAEG;AACH,eAAO,MAAM,kBAAkB,GAC9B,cAAc,WAAW,EACzB,aAAa,UAAU,KACrB,WAuDF,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,uBAAuB,GAAI,MAAM,MAAM,KAAG,MAStD,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,qBAAqB,GAAI,SAAS,WAAW,KAAG,MAAM,GAAG,IAQrE,CAAC"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Library metadata combining package.json with analyzed source.
|
|
3
|
+
*/
|
|
4
|
+
import { ensure_end, strip_end, strip_start } from './string.js';
|
|
5
|
+
/**
|
|
6
|
+
* Creates a `LibraryJson` with computed properties from package.json and source metadata.
|
|
7
|
+
*/
|
|
8
|
+
export const library_json_parse = (package_json, source_json) => {
|
|
9
|
+
const { name } = package_json;
|
|
10
|
+
// TODO hacky
|
|
11
|
+
const parse_repo = (r) => {
|
|
12
|
+
if (!r)
|
|
13
|
+
return null;
|
|
14
|
+
return strip_end(strip_start(strip_end(r, '.git'), 'git+'), '/');
|
|
15
|
+
};
|
|
16
|
+
const repo_url = parse_repo(package_json.repository
|
|
17
|
+
? typeof package_json.repository === 'string'
|
|
18
|
+
? package_json.repository
|
|
19
|
+
: package_json.repository.url
|
|
20
|
+
: null);
|
|
21
|
+
if (!repo_url) {
|
|
22
|
+
throw Error('failed to parse library_json - `repo_url` is required in package_json');
|
|
23
|
+
}
|
|
24
|
+
const homepage_url = package_json.homepage ?? null;
|
|
25
|
+
const published = !package_json.private && !!package_json.exports && package_json.version !== '0.0.1';
|
|
26
|
+
// TODO generic registries
|
|
27
|
+
const npm_url = published ? 'https://www.npmjs.com/package/' + package_json.name : null;
|
|
28
|
+
const changelog_url = published && repo_url ? repo_url + '/blob/main/CHANGELOG.md' : null;
|
|
29
|
+
const repo_name = library_repo_name_parse(name);
|
|
30
|
+
const owner_name = repo_url ? strip_start(repo_url, 'https://github.com/').split('/')[0] : null;
|
|
31
|
+
const logo_url = homepage_url
|
|
32
|
+
? ensure_end(homepage_url, '/') +
|
|
33
|
+
(package_json.logo ? strip_start(package_json.logo, '/') : 'favicon.png')
|
|
34
|
+
: null;
|
|
35
|
+
const logo_alt = package_json.logo_alt ?? `logo for ${repo_name}`;
|
|
36
|
+
return {
|
|
37
|
+
package_json,
|
|
38
|
+
source_json,
|
|
39
|
+
name,
|
|
40
|
+
repo_name,
|
|
41
|
+
repo_url,
|
|
42
|
+
owner_name,
|
|
43
|
+
homepage_url,
|
|
44
|
+
logo_url,
|
|
45
|
+
logo_alt,
|
|
46
|
+
npm_url,
|
|
47
|
+
changelog_url,
|
|
48
|
+
published,
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Extracts repo name from a package name, e.g. `@ryanatkn/fuz` → `fuz`.
|
|
53
|
+
*/
|
|
54
|
+
export const library_repo_name_parse = (name) => {
|
|
55
|
+
if (name[0] === '@') {
|
|
56
|
+
const parts = name.split('/');
|
|
57
|
+
if (parts.length < 2) {
|
|
58
|
+
throw new Error(`invalid scoped package name: "${name}" (expected format: @org/package)`);
|
|
59
|
+
}
|
|
60
|
+
return parts[1];
|
|
61
|
+
}
|
|
62
|
+
return name;
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Extracts GitHub org URL from a library, e.g. `https://github.com/ryanatkn`.
|
|
66
|
+
*/
|
|
67
|
+
export const library_org_url_parse = (library) => {
|
|
68
|
+
const { repo_name, repo_url } = library;
|
|
69
|
+
if (!repo_url)
|
|
70
|
+
return null;
|
|
71
|
+
const suffix = '/' + repo_name;
|
|
72
|
+
if (repo_url.endsWith(suffix)) {
|
|
73
|
+
return strip_end(repo_url, suffix);
|
|
74
|
+
}
|
|
75
|
+
return null;
|
|
76
|
+
};
|
package/dist/log.d.ts
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Log level hierarchy from least to most verbose.
|
|
3
|
+
* - `'off'`: No logging
|
|
4
|
+
* - `'error'`: Only errors
|
|
5
|
+
* - `'warn'`: Errors and warnings
|
|
6
|
+
* - `'info'`: Errors, warnings, and info (default)
|
|
7
|
+
* - `'debug'`: All messages including debug
|
|
8
|
+
*/
|
|
9
|
+
export type LogLevel = 'off' | 'error' | 'warn' | 'info' | 'debug';
|
|
10
|
+
/**
|
|
11
|
+
* Console interface subset used by Logger for output.
|
|
12
|
+
* Allows custom console implementations for testing.
|
|
13
|
+
*/
|
|
14
|
+
export type LogConsole = Pick<typeof console, 'error' | 'warn' | 'log'>;
|
|
15
|
+
/**
|
|
16
|
+
* Converts a log level to its numeric value for comparison.
|
|
17
|
+
* Higher numbers indicate more verbose logging.
|
|
18
|
+
* @param level The log level to convert
|
|
19
|
+
* @returns Numeric value (0-4)
|
|
20
|
+
*/
|
|
21
|
+
export declare const log_level_to_number: (level: LogLevel) => number;
|
|
22
|
+
/**
|
|
23
|
+
* Parses and validates a log level string.
|
|
24
|
+
* @param value The value to parse as a log level
|
|
25
|
+
* @returns The validated log level, or undefined if value is undefined
|
|
26
|
+
* @throws Error if value is provided but invalid
|
|
27
|
+
*/
|
|
28
|
+
export declare const log_level_parse: (value: string | undefined) => LogLevel | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* Simple, flexible logger with support for child loggers and automatic context.
|
|
31
|
+
*
|
|
32
|
+
* Features:
|
|
33
|
+
* - Instance-based configuration (no global state)
|
|
34
|
+
* - Child loggers with automatic label concatenation
|
|
35
|
+
* - Parent chain inheritance for level, console, and colors
|
|
36
|
+
* - Respects NO_COLOR environment variable
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```ts
|
|
40
|
+
* // Basic logger
|
|
41
|
+
* const log = new Logger('app');
|
|
42
|
+
* log.info('starting'); // [app] ➤ starting
|
|
43
|
+
*
|
|
44
|
+
* // Child logger
|
|
45
|
+
* const db_log = log.child('db');
|
|
46
|
+
* db_log.info('connected'); // [app:db] ➤ connected
|
|
47
|
+
*
|
|
48
|
+
* // Custom configuration
|
|
49
|
+
* const verbose_log = new Logger('debug', { level: 'debug', colors: true });
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export declare class Logger {
|
|
53
|
+
#private;
|
|
54
|
+
readonly label?: string;
|
|
55
|
+
readonly parent?: Logger;
|
|
56
|
+
/**
|
|
57
|
+
* Creates a new Logger instance.
|
|
58
|
+
*
|
|
59
|
+
* @param label Optional label for this logger. Can be `undefined` for no label, or an
|
|
60
|
+
* empty string `''` which is functionally equivalent (both produce no brackets in output).
|
|
61
|
+
* Note: Empty strings are only allowed for root loggers - child loggers cannot have empty labels.
|
|
62
|
+
* @param options Optional configuration for level, colors, and console
|
|
63
|
+
*/
|
|
64
|
+
constructor(label?: string, options?: LoggerOptions);
|
|
65
|
+
/**
|
|
66
|
+
* Dynamic getter for level - checks override, then parent, then default.
|
|
67
|
+
*/
|
|
68
|
+
get level(): LogLevel;
|
|
69
|
+
/**
|
|
70
|
+
* Setter for level - creates override.
|
|
71
|
+
*/
|
|
72
|
+
set level(value: LogLevel);
|
|
73
|
+
/**
|
|
74
|
+
* Dynamic getter for colors - checks override, then parent, then environment variables.
|
|
75
|
+
*
|
|
76
|
+
* Colors are disabled if either the `NO_COLOR` or `CLAUDECODE` environment variable is set.
|
|
77
|
+
* The `CLAUDECODE` check disables colors in Claude Code environments where ANSI color codes
|
|
78
|
+
* may not render correctly in the output.
|
|
79
|
+
*/
|
|
80
|
+
get colors(): boolean;
|
|
81
|
+
/**
|
|
82
|
+
* Setter for colors - creates override.
|
|
83
|
+
*/
|
|
84
|
+
set colors(value: boolean);
|
|
85
|
+
/**
|
|
86
|
+
* Dynamic getter for console - checks override, then parent, then global console.
|
|
87
|
+
*/
|
|
88
|
+
get console(): LogConsole;
|
|
89
|
+
/**
|
|
90
|
+
* Setter for console - creates override.
|
|
91
|
+
*/
|
|
92
|
+
set console(value: LogConsole);
|
|
93
|
+
/**
|
|
94
|
+
* Gets the root logger by walking up the parent chain.
|
|
95
|
+
* Useful for setting global configuration that affects all child loggers.
|
|
96
|
+
* @returns The root logger (the one without a parent)
|
|
97
|
+
*/
|
|
98
|
+
get root(): Logger;
|
|
99
|
+
/**
|
|
100
|
+
* Clears the level override for this logger, restoring inheritance from parent.
|
|
101
|
+
* After calling this, the logger will dynamically inherit the level from its parent
|
|
102
|
+
* (or use the default level if it has no parent).
|
|
103
|
+
*/
|
|
104
|
+
clear_level_override(): void;
|
|
105
|
+
/**
|
|
106
|
+
* Clears the colors override for this logger, restoring inheritance from parent.
|
|
107
|
+
* After calling this, the logger will dynamically inherit colors from its parent
|
|
108
|
+
* (or use the default colors behavior if it has no parent).
|
|
109
|
+
*/
|
|
110
|
+
clear_colors_override(): void;
|
|
111
|
+
/**
|
|
112
|
+
* Clears the console override for this logger, restoring inheritance from parent.
|
|
113
|
+
* After calling this, the logger will dynamically inherit the console from its parent
|
|
114
|
+
* (or use the global console if it has no parent).
|
|
115
|
+
*/
|
|
116
|
+
clear_console_override(): void;
|
|
117
|
+
/**
|
|
118
|
+
* Creates a child logger with automatic label concatenation.
|
|
119
|
+
* Children inherit parent configuration unless overridden.
|
|
120
|
+
*
|
|
121
|
+
* @param label Child label (will be concatenated with parent label using `:`).
|
|
122
|
+
* Cannot be an empty string - empty labels would result in confusing output like `parent:`
|
|
123
|
+
* with a trailing colon. Use `undefined` or `''` only for root loggers.
|
|
124
|
+
* @param options Optional configuration overrides
|
|
125
|
+
* @returns New Logger instance with concatenated label
|
|
126
|
+
* @throws Error if label is an empty string
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* ```ts
|
|
130
|
+
* const app_log = new Logger('app');
|
|
131
|
+
* const db_log = app_log.child('db'); // label: 'app:db'
|
|
132
|
+
* const query_log = db_log.child('query'); // label: 'app:db:query'
|
|
133
|
+
* ```
|
|
134
|
+
*/
|
|
135
|
+
child(label: string, options?: LoggerOptions): Logger;
|
|
136
|
+
/**
|
|
137
|
+
* Logs an error message with `🞩error🞩` prefix.
|
|
138
|
+
* Only outputs if current level is `error` or higher.
|
|
139
|
+
*/
|
|
140
|
+
error(...args: Array<unknown>): void;
|
|
141
|
+
/**
|
|
142
|
+
* Logs a warning message with `⚑warn⚑` prefix.
|
|
143
|
+
* Only outputs if current level is `warn` or higher.
|
|
144
|
+
*/
|
|
145
|
+
warn(...args: Array<unknown>): void;
|
|
146
|
+
/**
|
|
147
|
+
* Logs an informational message.
|
|
148
|
+
* Unlike error/warn/debug, info has no character prefix - only the label is shown.
|
|
149
|
+
* This keeps standard output clean since info is the default log level.
|
|
150
|
+
* Only outputs if current level is `info` or higher.
|
|
151
|
+
*/
|
|
152
|
+
info(...args: Array<unknown>): void;
|
|
153
|
+
/**
|
|
154
|
+
* Logs a debug message with `┆debug┆` prefix.
|
|
155
|
+
* Only outputs if current level is `debug`.
|
|
156
|
+
*/
|
|
157
|
+
debug(...args: Array<unknown>): void;
|
|
158
|
+
/**
|
|
159
|
+
* Logs raw output without any prefix, formatting, or level filtering.
|
|
160
|
+
* Bypasses the logger's level checking, prefix formatting, and color application entirely.
|
|
161
|
+
* Useful for outputting structured data or when you need full control over formatting.
|
|
162
|
+
*
|
|
163
|
+
* Note: This method ignores the configured log level - it always outputs regardless of
|
|
164
|
+
* whether the logger is set to 'off' or any other level.
|
|
165
|
+
*
|
|
166
|
+
* @param args Values to log directly to console
|
|
167
|
+
*/
|
|
168
|
+
raw(...args: Array<unknown>): void;
|
|
169
|
+
}
|
|
170
|
+
export interface LoggerOptions {
|
|
171
|
+
/**
|
|
172
|
+
* Log level for this logger instance.
|
|
173
|
+
* Inherits from parent or defaults to 'info'.
|
|
174
|
+
*/
|
|
175
|
+
level?: LogLevel;
|
|
176
|
+
/**
|
|
177
|
+
* Console interface for output.
|
|
178
|
+
* Inherits from parent or defaults to global console.
|
|
179
|
+
* Useful for testing.
|
|
180
|
+
*/
|
|
181
|
+
console?: LogConsole;
|
|
182
|
+
/**
|
|
183
|
+
* Whether to use colors in output.
|
|
184
|
+
* Inherits from parent or defaults to enabled (unless NO_COLOR env var is set).
|
|
185
|
+
*/
|
|
186
|
+
colors?: boolean;
|
|
187
|
+
}
|
|
188
|
+
//# sourceMappingURL=log.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"log.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/log.ts"],"names":[],"mappings":"AAGA;;;;;;;GAOG;AACH,MAAM,MAAM,QAAQ,GAAG,KAAK,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;AAEnE;;;GAGG;AACH,MAAM,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,OAAO,EAAE,OAAO,GAAG,MAAM,GAAG,KAAK,CAAC,CAAC;AAwBxE;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,GAAI,OAAO,QAAQ,KAAG,MAAiC,CAAC;AAExF;;;;;GAKG;AACH,eAAO,MAAM,eAAe,GAAI,OAAO,MAAM,GAAG,SAAS,KAAG,QAAQ,GAAG,SAItE,CAAC;AASF;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,qBAAa,MAAM;;IAClB,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAkBzB;;;;;;;OAOG;gBACS,KAAK,CAAC,EAAE,MAAM,EAAE,OAAO,GAAE,aAAkB;IAiBvD;;OAEG;IACH,IAAI,KAAK,IAAI,QAAQ,CAQpB;IAED;;OAEG;IACH,IAAI,KAAK,CAAC,KAAK,EAAE,QAAQ,EAGxB;IAED;;;;;;OAMG;IACH,IAAI,MAAM,IAAI,OAAO,CAWpB;IAED;;OAEG;IACH,IAAI,MAAM,CAAC,KAAK,EAAE,OAAO,EAExB;IAED;;OAEG;IACH,IAAI,OAAO,IAAI,UAAU,CAQxB;IAED;;OAEG;IACH,IAAI,OAAO,CAAC,KAAK,EAAE,UAAU,EAE5B;IAED;;;;OAIG;IACH,IAAI,IAAI,IAAI,MAAM,CAMjB;IAED;;;;OAIG;IACH,oBAAoB,IAAI,IAAI;IAM5B;;;;OAIG;IACH,qBAAqB,IAAI,IAAI;IAU7B;;;;OAIG;IACH,sBAAsB,IAAI,IAAI;IA8G9B;;;;;;;;;;;;;;;;;OAiBG;IACH,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,GAAE,aAAkB,GAAG,MAAM;IAezD;;;OAGG;IACH,KAAK,CAAC,GAAG,IAAI,EAAE,KAAK,CAAC,OAAO,CAAC,GAAG,IAAI;IAKpC;;;OAGG;IACH,IAAI,CAAC,GAAG,IAAI,EAAE,KAAK,CAAC,OAAO,CAAC,GAAG,IAAI;IAKnC;;;;;OAKG;IACH,IAAI,CAAC,GAAG,IAAI,EAAE,KAAK,CAAC,OAAO,CAAC,GAAG,IAAI;IAKnC;;;OAGG;IACH,KAAK,CAAC,GAAG,IAAI,EAAE,KAAK,CAAC,OAAO,CAAC,GAAG,IAAI;IAKpC;;;;;;;;;OASG;IACH,GAAG,CAAC,GAAG,IAAI,EAAE,KAAK,CAAC,OAAO,CAAC,GAAG,IAAI;CAGlC;AAED,MAAM,WAAW,aAAa;IAC7B;;;OAGG;IACH,KAAK,CAAC,EAAE,QAAQ,CAAC;IAEjB;;;;OAIG;IACH,OAAO,CAAC,EAAE,UAAU,CAAC;IAErB;;;OAGG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;CACjB"}
|