@logtape/redaction 0.10.0-dev.164

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,20 @@
1
+ MIT License
2
+
3
+ Copyright 2024 Hong Minhee
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ 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, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,31 @@
1
+ <!-- deno-fmt-ignore-file -->
2
+
3
+ Data redaction for LogTape
4
+ ==========================
5
+
6
+ [![JSR][JSR badge]][JSR]
7
+ [![npm][npm badge]][npm]
8
+
9
+ This package provides data redaction for [LogTape]. You can redact sensitive
10
+ data in log records.
11
+
12
+ [JSR]: https://jsr.io/@logtape/redaction
13
+ [JSR badge]: https://jsr.io/badges/@logtape/redaction
14
+ [npm]: https://www.npmjs.com/package/@logtape/redaction
15
+ [npm badge]: https://img.shields.io/npm/v/@logtape/redaction?logo=npm
16
+ [LogTape]: https://logtape.org/
17
+
18
+
19
+ Installation
20
+ ------------
21
+
22
+ This package is available on [JSR] and [npm]. You can install it for various
23
+ JavaScript runtimes and package managers:
24
+
25
+ ~~~~ sh
26
+ deno add jsr:@logtape/redaction # for Deno
27
+ npm add @logtape/redaction # for npm
28
+ pnpm add @logtape/redaction # for pnpm
29
+ yarn add @logtape/redaction # for Yarn
30
+ bun add @logtape/redaction # for Bun
31
+ ~~~~
package/esm/field.js ADDED
@@ -0,0 +1,95 @@
1
+ /**
2
+ * Default field patterns for redaction. These patterns will match
3
+ * common sensitive fields such as passwords, tokens, and personal
4
+ * information.
5
+ * @since 0.10.0
6
+ */
7
+ export const DEFAULT_REDACT_FIELDS = [
8
+ /pass(?:code|phrase|word)/i,
9
+ /secret/i,
10
+ /token/i,
11
+ /key/i,
12
+ /credential/i,
13
+ /auth/i,
14
+ /signature/i,
15
+ /sensitive/i,
16
+ /private/i,
17
+ /ssn/i,
18
+ /email/i,
19
+ /phone/i,
20
+ /address/i,
21
+ ];
22
+ /**
23
+ * Redacts properties in a {@link LogRecord} based on the provided field
24
+ * patterns and action.
25
+ *
26
+ * Note that it is a decorator which wraps the sink and redacts properties
27
+ * before passing them to the sink.
28
+ *
29
+ * @example
30
+ * ```ts
31
+ * import { getConsoleSink } from "@logtape/logtape";
32
+ * import { redactByField } from "@logtape/redaction";
33
+ *
34
+ * const sink = redactByField(getConsoleSink());
35
+ * ```
36
+ *
37
+ * @param sink The sink to wrap.
38
+ * @param options The redaction options.
39
+ * @returns The wrapped sink.
40
+ * @since 0.10.0
41
+ */
42
+ export function redactByField(sink, options = DEFAULT_REDACT_FIELDS) {
43
+ const opts = Array.isArray(options) ? { fieldPatterns: options } : options;
44
+ const wrapped = (record) => {
45
+ sink({ ...record, properties: redactProperties(record.properties, opts) });
46
+ };
47
+ if (Symbol.dispose in sink)
48
+ wrapped[Symbol.dispose] = sink[Symbol.dispose];
49
+ if (Symbol.asyncDispose in sink) {
50
+ wrapped[Symbol.asyncDispose] = sink[Symbol.asyncDispose];
51
+ }
52
+ return wrapped;
53
+ }
54
+ /**
55
+ * Redacts properties in a record based on the provided field patterns and
56
+ * action.
57
+ * @param properties The properties to redact.
58
+ * @param options The redaction options.
59
+ * @returns The redacted properties.
60
+ * @since 0.10.0
61
+ */
62
+ export function redactProperties(properties, options) {
63
+ const copy = { ...properties };
64
+ for (const field in copy) {
65
+ if (!shouldFieldRedacted(field, options.fieldPatterns))
66
+ continue;
67
+ if (options.action == null || options.action === "delete") {
68
+ delete copy[field];
69
+ }
70
+ else {
71
+ copy[field] = options.action(copy[field]);
72
+ }
73
+ }
74
+ return copy;
75
+ }
76
+ /**
77
+ * Checks if a field should be redacted based on the provided field patterns.
78
+ * @param field The field name to check.
79
+ * @param fieldPatterns The field patterns to match against.
80
+ * @returns `true` if the field should be redacted, `false` otherwise.
81
+ * @since 0.10.0
82
+ */
83
+ export function shouldFieldRedacted(field, fieldPatterns) {
84
+ for (const fieldPattern of fieldPatterns) {
85
+ if (typeof fieldPattern === "string") {
86
+ if (fieldPattern === field)
87
+ return true;
88
+ }
89
+ else {
90
+ if (fieldPattern.test(field))
91
+ return true;
92
+ }
93
+ }
94
+ return false;
95
+ }
package/esm/mod.js ADDED
@@ -0,0 +1 @@
1
+ export { DEFAULT_REDACT_FIELDS, redactByField, } from "./field.js";
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "module"
3
+ }
package/package.json ADDED
@@ -0,0 +1,59 @@
1
+ {
2
+ "name": "@logtape/redaction",
3
+ "version": "0.10.0-dev.164+f355881a",
4
+ "description": "Redact sensitive data from log messages",
5
+ "keywords": [
6
+ "logging",
7
+ "log",
8
+ "logger",
9
+ "redaction",
10
+ "mask",
11
+ "masking",
12
+ "sensitive"
13
+ ],
14
+ "author": {
15
+ "name": "Hong Minhee",
16
+ "email": "hong@minhee.org",
17
+ "url": "https://hongminhee.org/"
18
+ },
19
+ "homepage": "https://logtape.org/",
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "git+https://github.com/dahlia/logtape.git",
23
+ "directory": "file/"
24
+ },
25
+ "license": "MIT",
26
+ "bugs": {
27
+ "url": "https://github.com/dahlia/logtape/issues"
28
+ },
29
+ "main": "./script/mod.js",
30
+ "module": "./esm/mod.js",
31
+ "types": "./types/mod.d.ts",
32
+ "exports": {
33
+ ".": {
34
+ "import": {
35
+ "types": "./types/mod.d.ts",
36
+ "default": "./esm/mod.js"
37
+ },
38
+ "require": {
39
+ "types": "./types/mod.d.ts",
40
+ "default": "./script/mod.js"
41
+ }
42
+ }
43
+ },
44
+ "scripts": {
45
+ "test": "node test_runner.js"
46
+ },
47
+ "funding": [
48
+ "https://github.com/sponsors/dahlia"
49
+ ],
50
+ "dependencies": {
51
+ "@logtape/logtape": "^0.10.0-dev.162"
52
+ },
53
+ "devDependencies": {
54
+ "@types/node": "^20.9.0",
55
+ "picocolors": "^1.0.0",
56
+ "@deno/shim-deno": "~0.18.0"
57
+ },
58
+ "_generatedBy": "dnt@dev"
59
+ }
@@ -0,0 +1,101 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DEFAULT_REDACT_FIELDS = void 0;
4
+ exports.redactByField = redactByField;
5
+ exports.redactProperties = redactProperties;
6
+ exports.shouldFieldRedacted = shouldFieldRedacted;
7
+ /**
8
+ * Default field patterns for redaction. These patterns will match
9
+ * common sensitive fields such as passwords, tokens, and personal
10
+ * information.
11
+ * @since 0.10.0
12
+ */
13
+ exports.DEFAULT_REDACT_FIELDS = [
14
+ /pass(?:code|phrase|word)/i,
15
+ /secret/i,
16
+ /token/i,
17
+ /key/i,
18
+ /credential/i,
19
+ /auth/i,
20
+ /signature/i,
21
+ /sensitive/i,
22
+ /private/i,
23
+ /ssn/i,
24
+ /email/i,
25
+ /phone/i,
26
+ /address/i,
27
+ ];
28
+ /**
29
+ * Redacts properties in a {@link LogRecord} based on the provided field
30
+ * patterns and action.
31
+ *
32
+ * Note that it is a decorator which wraps the sink and redacts properties
33
+ * before passing them to the sink.
34
+ *
35
+ * @example
36
+ * ```ts
37
+ * import { getConsoleSink } from "@logtape/logtape";
38
+ * import { redactByField } from "@logtape/redaction";
39
+ *
40
+ * const sink = redactByField(getConsoleSink());
41
+ * ```
42
+ *
43
+ * @param sink The sink to wrap.
44
+ * @param options The redaction options.
45
+ * @returns The wrapped sink.
46
+ * @since 0.10.0
47
+ */
48
+ function redactByField(sink, options = exports.DEFAULT_REDACT_FIELDS) {
49
+ const opts = Array.isArray(options) ? { fieldPatterns: options } : options;
50
+ const wrapped = (record) => {
51
+ sink({ ...record, properties: redactProperties(record.properties, opts) });
52
+ };
53
+ if (Symbol.dispose in sink)
54
+ wrapped[Symbol.dispose] = sink[Symbol.dispose];
55
+ if (Symbol.asyncDispose in sink) {
56
+ wrapped[Symbol.asyncDispose] = sink[Symbol.asyncDispose];
57
+ }
58
+ return wrapped;
59
+ }
60
+ /**
61
+ * Redacts properties in a record based on the provided field patterns and
62
+ * action.
63
+ * @param properties The properties to redact.
64
+ * @param options The redaction options.
65
+ * @returns The redacted properties.
66
+ * @since 0.10.0
67
+ */
68
+ function redactProperties(properties, options) {
69
+ const copy = { ...properties };
70
+ for (const field in copy) {
71
+ if (!shouldFieldRedacted(field, options.fieldPatterns))
72
+ continue;
73
+ if (options.action == null || options.action === "delete") {
74
+ delete copy[field];
75
+ }
76
+ else {
77
+ copy[field] = options.action(copy[field]);
78
+ }
79
+ }
80
+ return copy;
81
+ }
82
+ /**
83
+ * Checks if a field should be redacted based on the provided field patterns.
84
+ * @param field The field name to check.
85
+ * @param fieldPatterns The field patterns to match against.
86
+ * @returns `true` if the field should be redacted, `false` otherwise.
87
+ * @since 0.10.0
88
+ */
89
+ function shouldFieldRedacted(field, fieldPatterns) {
90
+ for (const fieldPattern of fieldPatterns) {
91
+ if (typeof fieldPattern === "string") {
92
+ if (fieldPattern === field)
93
+ return true;
94
+ }
95
+ else {
96
+ if (fieldPattern.test(field))
97
+ return true;
98
+ }
99
+ }
100
+ return false;
101
+ }
package/script/mod.js ADDED
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.redactByField = exports.DEFAULT_REDACT_FIELDS = void 0;
4
+ var field_js_1 = require("./field.js");
5
+ Object.defineProperty(exports, "DEFAULT_REDACT_FIELDS", { enumerable: true, get: function () { return field_js_1.DEFAULT_REDACT_FIELDS; } });
6
+ Object.defineProperty(exports, "redactByField", { enumerable: true, get: function () { return field_js_1.redactByField; } });
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_dnt.test_shims.d.ts","sourceRoot":"","sources":["../src/_dnt.test_shims.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AACvC,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAKvC,eAAO,MAAM,aAAa;;CAA2C,CAAC"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_constants.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/assert/0.222.1/_constants.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,eAAe,qBAAqB,CAAC"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_diff.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/assert/0.222.1/_diff.ts"],"names":[],"mappings":"AAUA,eAAO,MAAM,QAAQ;;;;CAIX,CAAC;AAEX,MAAM,MAAM,QAAQ,GAAG,MAAM,OAAO,QAAQ,CAAC;AAE7C,MAAM,WAAW,UAAU,CAAC,CAAC;IAC3B,IAAI,EAAE,QAAQ,CAAC;IACf,KAAK,EAAE,CAAC,CAAC;IACT,OAAO,CAAC,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;CAChC;AA4BD;;;;GAIG;AACH,wBAAgB,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,GAAG,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CA+L5D;AAED;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,wBAsI3C;AAwCD,wBAAgB,YAAY,CAC1B,UAAU,EAAE,aAAa,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,EAC7C,EAAE,UAAkB,EAAE;;CAAK,GAC1B,MAAM,EAAE,CAyBV"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_format.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/assert/0.222.1/_format.ts"],"names":[],"mappings":"AAYA,wBAAgB,MAAM,CAAC,CAAC,EAAE,OAAO,GAAG,MAAM,CAezC"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assert_equals.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/assert/0.222.1/assert_equals.ts"],"names":[],"mappings":"AASA;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAC5B,MAAM,EAAE,CAAC,EACT,QAAQ,EAAE,CAAC,EACX,GAAG,CAAC,EAAE,MAAM,EACZ,OAAO,GAAE;IAAE,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,MAAM,CAAA;CAAO,QAuBzD"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assertion_error.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/assert/0.222.1/assertion_error.ts"],"names":[],"mappings":"AAGA;;;;;;;;;GASG;AACH,qBAAa,cAAe,SAAQ,KAAK;IACvC,iCAAiC;gBACrB,OAAO,EAAE,MAAM;CAI5B"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"equal.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/assert/0.222.1/equal.ts"],"names":[],"mappings":"AAYA;;;;;;;;;;;;GAYG;AACH,wBAAgB,KAAK,CA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AED;;;;;GAKG;AACH,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAEzD;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,GAAG,GAAG,MAAM,CAuB9D;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,GAAG,GAAG,MAAM,CAuBhE;AAWD;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEjD;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEpD"}
@@ -0,0 +1,84 @@
1
+ import type { Sink } from "@logtape/logtape";
2
+ /**
3
+ * The type for a field pattern used in redaction. A string or a regular
4
+ * expression that matches field names.
5
+ * @since 0.10.0
6
+ */
7
+ export type FieldPattern = string | RegExp;
8
+ /**
9
+ * An array of field patterns used for redaction. Each pattern can be
10
+ * a string or a regular expression that matches field names.
11
+ * @since 0.10.0
12
+ */
13
+ export type FieldPatterns = FieldPattern[];
14
+ /**
15
+ * Default field patterns for redaction. These patterns will match
16
+ * common sensitive fields such as passwords, tokens, and personal
17
+ * information.
18
+ * @since 0.10.0
19
+ */
20
+ export declare const DEFAULT_REDACT_FIELDS: FieldPatterns;
21
+ /**
22
+ * Options for redacting fields in a {@link LogRecord}. Used by
23
+ * the {@link redactByField} function.
24
+ * @since 0.10.0
25
+ */
26
+ export interface FieldRedactionOptions {
27
+ /**
28
+ * The field patterns to match against. This can be an array of
29
+ * strings or regular expressions. If a field matches any of the
30
+ * patterns, it will be redacted.
31
+ * @defaultValue {@link DEFAULT_REDACT_FIELDS}
32
+ */
33
+ readonly fieldPatterns: FieldPatterns;
34
+ /**
35
+ * The action to perform on the matched fields. If not provided,
36
+ * the default action is to delete the field from the properties.
37
+ * If a function is provided, it will be called with the
38
+ * value of the field, and the return value will be used to replace
39
+ * the field in the properties.
40
+ * If the action is `"delete"`, the field will be removed from the
41
+ * properties.
42
+ * @default `"delete"`
43
+ */
44
+ readonly action?: "delete" | ((value: unknown) => unknown);
45
+ }
46
+ /**
47
+ * Redacts properties in a {@link LogRecord} based on the provided field
48
+ * patterns and action.
49
+ *
50
+ * Note that it is a decorator which wraps the sink and redacts properties
51
+ * before passing them to the sink.
52
+ *
53
+ * @example
54
+ * ```ts
55
+ * import { getConsoleSink } from "@logtape/logtape";
56
+ * import { redactByField } from "@logtape/redaction";
57
+ *
58
+ * const sink = redactByField(getConsoleSink());
59
+ * ```
60
+ *
61
+ * @param sink The sink to wrap.
62
+ * @param options The redaction options.
63
+ * @returns The wrapped sink.
64
+ * @since 0.10.0
65
+ */
66
+ export declare function redactByField(sink: Sink | Sink & Disposable | Sink & AsyncDisposable, options?: FieldRedactionOptions | FieldPatterns): Sink | Sink & Disposable | Sink & AsyncDisposable;
67
+ /**
68
+ * Redacts properties in a record based on the provided field patterns and
69
+ * action.
70
+ * @param properties The properties to redact.
71
+ * @param options The redaction options.
72
+ * @returns The redacted properties.
73
+ * @since 0.10.0
74
+ */
75
+ export declare function redactProperties(properties: Record<string, unknown>, options: FieldRedactionOptions): Record<string, unknown>;
76
+ /**
77
+ * Checks if a field should be redacted based on the provided field patterns.
78
+ * @param field The field name to check.
79
+ * @param fieldPatterns The field patterns to match against.
80
+ * @returns `true` if the field should be redacted, `false` otherwise.
81
+ * @since 0.10.0
82
+ */
83
+ export declare function shouldFieldRedacted(field: string, fieldPatterns: FieldPatterns): boolean;
84
+ //# sourceMappingURL=field.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"field.d.ts","sourceRoot":"","sources":["../src/field.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAa,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAExD;;;;GAIG;AACH,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,MAAM,CAAC;AAE3C;;;;GAIG;AACH,MAAM,MAAM,aAAa,GAAG,YAAY,EAAE,CAAC;AAE3C;;;;;GAKG;AACH,eAAO,MAAM,qBAAqB,EAAE,aAcnC,CAAC;AAEF;;;;GAIG;AACH,MAAM,WAAW,qBAAqB;IACpC;;;;;OAKG;IACH,QAAQ,CAAC,aAAa,EAAE,aAAa,CAAC;IAEtC;;;;;;;;;OASG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,QAAQ,GAAG,CAAC,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CAAC,CAAC;CAC5D;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,aAAa,CAC3B,IAAI,EAAE,IAAI,GAAG,IAAI,GAAG,UAAU,GAAG,IAAI,GAAG,eAAe,EACvD,OAAO,GAAE,qBAAqB,GAAG,aAAqC,GACrE,IAAI,GAAG,IAAI,GAAG,UAAU,GAAG,IAAI,GAAG,eAAe,CAUnD;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAC9B,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACnC,OAAO,EAAE,qBAAqB,GAC7B,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAWzB;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,MAAM,EACb,aAAa,EAAE,aAAa,GAC3B,OAAO,CAST"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"field.test.d.ts","sourceRoot":"","sources":["../src/field.test.ts"],"names":[],"mappings":""}
package/types/mod.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export { DEFAULT_REDACT_FIELDS, type FieldPattern, type FieldPatterns, type FieldRedactionOptions, redactByField, } from "./field.js";
2
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,KAAK,YAAY,EACjB,KAAK,aAAa,EAClB,KAAK,qBAAqB,EAC1B,aAAa,GACd,MAAM,YAAY,CAAC"}