@peerigon/typescript-toolkit 0.0.1-semantically-released

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) 2024 Peerigon
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,54 @@
1
+ <h1 align="center">typescript-toolkit</h1>
2
+ <p align="center"><strong>🔧✨ Tiny helpers for TypeScript applications</strong></p>
3
+
4
+ <p align="center">
5
+ <a href="https://www.npmjs.com/package/@peerigon/typescript-toolkit"><img src="https://img.shields.io/npm/v/@peerigon/typescript-toolkit?style=for-the-badge" alt="Version on NPM" /></a>
6
+ <a href="https://jsr.io/@peerigon/typescript-toolkit"><img src="https://img.shields.io/jsr/v/@peerigon/typescript-toolkit?style=for-the-badge" alt="Version on JSR" /></a>
7
+ <a href="https://github.com/semantic-release/semantic-release"><img src="https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=for-the-badge" alt="Semantically released" /></a>
8
+ <a href="https://www.npmjs.com/package/@peerigon/typescript-toolkit"><img src="https://img.shields.io/npm/dm/@peerigon/typescript-toolkit?style=for-the-badge" alt="Monthly downloads on NPM" /></a>
9
+ <a href="./LICENSE"><img src="https://img.shields.io/npm/l/@peerigon/typescript-toolkit?style=for-the-badge" alt="License" /></a>
10
+ </p>
11
+
12
+ <p align="center">
13
+ Small, focused utilities you import one at a time — tree-shakeable ES modules with subpath exports.
14
+ </p>
15
+
16
+ ## Features
17
+
18
+ - 🎯 High-quality module design
19
+ - âš¡ Lightweight sub-package exports
20
+ - 📦 Tree-shakeable ES modules
21
+
22
+ ## Installation
23
+
24
+ ```sh
25
+ npm install @peerigon/typescript-toolkit --save
26
+ ```
27
+
28
+ Also available on [JSR](https://jsr.io/@peerigon/typescript-toolkit).
29
+
30
+ ## Usage
31
+
32
+ Import only the utilities you need. Each one is exposed as its own subpath:
33
+
34
+ ```ts
35
+ import { assert } from "@peerigon/typescript-toolkit/assert";
36
+ ```
37
+
38
+ ## Utilities
39
+
40
+ | Module | Description | Docs |
41
+ | ---------------------------------- | -------------------------------------------------------------------------------- | --------------------------- |
42
+ | [`assert`](./src/assert/README.md) | Assert a value is not `null`, `undefined`, or `false`, with TypeScript narrowing | [→](./src/assert/README.md) |
43
+
44
+ ## License
45
+
46
+ [MIT](./LICENSE)
47
+
48
+ ## Sponsors
49
+
50
+ <p align="center">
51
+ <a href="https://peerigon.com">
52
+ <img src="https://assets.peerigon.com/peerigon/logo/peerigon-logo-flat-spinat.png" width="150" alt="Peerigon" />
53
+ </a>
54
+ </p>
@@ -0,0 +1,16 @@
1
+ import { type ErrorMessage } from "../lib/error-message.ts";
2
+ /**
3
+ * Asserts that a given `value` is not `null`, `undefined`, or `false`,
4
+ * and narrows its type.
5
+ *
6
+ * Unlike regular truthiness checks, `assert` only rejects `null`, `undefined`,
7
+ * and `false` while allowing other falsy values like `0`, `""`, and `NaN` to pass through.
8
+ *
9
+ * @param value - The value that shouldn't be `null`, `undefined`, or `false`.
10
+ * @param errorMessage - The error message to throw if the value is `null`, `undefined`, or `false`.
11
+ */
12
+ export declare const assert: {
13
+ <Value>(value: Value, errorMessage?: ErrorMessage): asserts value is NonNullable<Value> & Exclude<Value, false>;
14
+ truthy(value: unknown, errorMessage?: ErrorMessage): asserts value;
15
+ };
16
+ //# sourceMappingURL=assert.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assert.d.ts","sourceRoot":"","sources":["../../src/assert/assert.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,KAAK,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAG7E;;;;;;;;;GASG;AACH,eAAO,MAAM,MAAM;KAAI,KAAK,SACnB,KAAK,iBACG,YAAY,GAC1B,QAAQ,KAAK,IAAI,WAAW,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC;kBAiBrD,OAAO,iBACC,YAAY,GAC1B,QAAQ,KAAK;CAff,CAAC"}
@@ -0,0 +1,36 @@
1
+ import { getErrorMessage } from "../lib/error-message.js";
2
+ import { simpleStringify } from "../lib/string.js";
3
+ /**
4
+ * Asserts that a given `value` is not `null`, `undefined`, or `false`,
5
+ * and narrows its type.
6
+ *
7
+ * Unlike regular truthiness checks, `assert` only rejects `null`, `undefined`,
8
+ * and `false` while allowing other falsy values like `0`, `""`, and `NaN` to pass through.
9
+ *
10
+ * @param value - The value that shouldn't be `null`, `undefined`, or `false`.
11
+ * @param errorMessage - The error message to throw if the value is `null`, `undefined`, or `false`.
12
+ */
13
+ export const assert = (value, errorMessage) => {
14
+ if (value === undefined || value === null || value === false) {
15
+ throwTypeError(value, errorMessage, "neither null, undefined, nor false");
16
+ }
17
+ };
18
+ /**
19
+ * Asserts that a given `value` is truthy,
20
+ * and narrows its type to exclude falsy values.
21
+ *
22
+ * This function performs a standard truthiness check, rejecting
23
+ * all falsy values: `false`, `0`, `-0`, `0n`, `""`, `null`, `undefined`, and `NaN`.
24
+ *
25
+ * @param value - The value to assert the truthy check on.
26
+ * @param errorMessage - The error message to throw if the value is falsy.
27
+ */
28
+ assert.truthy = (value, errorMessage) => {
29
+ if (!value) {
30
+ throwTypeError(value, errorMessage, "truthy value");
31
+ }
32
+ };
33
+ const throwTypeError = (value, errorMessage, expectation) => {
34
+ throw new TypeError(getErrorMessage(errorMessage, () => `Assertion failed: expected ${expectation}, but got ${simpleStringify(value)}`));
35
+ };
36
+ //# sourceMappingURL=assert.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assert.js","sourceRoot":"","sources":["../../src/assert/assert.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAqB,MAAM,yBAAyB,CAAC;AAC7E,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAEnD;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,CACpB,KAAY,EACZ,YAA2B,EACkC,EAAE;IAC/D,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,KAAK,EAAE,CAAC;QAC7D,cAAc,CAAC,KAAK,EAAE,YAAY,EAAE,oCAAoC,CAAC,CAAC;IAC5E,CAAC;AACH,CAAC,CAAC;AAEF;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,GAAG,CACd,KAAc,EACd,YAA2B,EACZ,EAAE;IACjB,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,cAAc,CAAC,KAAK,EAAE,YAAY,EAAE,cAAc,CAAC,CAAC;IACtD,CAAC;AACH,CAAC,CAAC;AAEF,MAAM,cAAc,GAAG,CACrB,KAAc,EACd,YAA0B,EAC1B,WAAmB,EACnB,EAAE;IACF,MAAM,IAAI,SAAS,CACjB,eAAe,CACb,YAAY,EACZ,GAAG,EAAE,CACH,8BAA8B,WAAW,aAAa,eAAe,CAAC,KAAK,CAAC,EAAE,CACjF,CACF,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import { getErrorMessage, type ErrorMessage } from \"../lib/error-message.ts\";\nimport { simpleStringify } from \"../lib/string.ts\";\n\n/**\n * Asserts that a given `value` is not `null`, `undefined`, or `false`,\n * and narrows its type.\n *\n * Unlike regular truthiness checks, `assert` only rejects `null`, `undefined`,\n * and `false` while allowing other falsy values like `0`, `\"\"`, and `NaN` to pass through.\n *\n * @param value - The value that shouldn't be `null`, `undefined`, or `false`.\n * @param errorMessage - The error message to throw if the value is `null`, `undefined`, or `false`.\n */\nexport const assert = <Value>(\n value: Value,\n errorMessage?: ErrorMessage,\n): asserts value is NonNullable<Value> & Exclude<Value, false> => {\n if (value === undefined || value === null || value === false) {\n throwTypeError(value, errorMessage, \"neither null, undefined, nor false\");\n }\n};\n\n/**\n * Asserts that a given `value` is truthy,\n * and narrows its type to exclude falsy values.\n *\n * This function performs a standard truthiness check, rejecting\n * all falsy values: `false`, `0`, `-0`, `0n`, `\"\"`, `null`, `undefined`, and `NaN`.\n *\n * @param value - The value to assert the truthy check on.\n * @param errorMessage - The error message to throw if the value is falsy.\n */\nassert.truthy = (\n value: unknown,\n errorMessage?: ErrorMessage,\n): asserts value => {\n if (!value) {\n throwTypeError(value, errorMessage, \"truthy value\");\n }\n};\n\nconst throwTypeError = (\n value: unknown,\n errorMessage: ErrorMessage,\n expectation: string,\n) => {\n throw new TypeError(\n getErrorMessage(\n errorMessage,\n () =>\n `Assertion failed: expected ${expectation}, but got ${simpleStringify(value)}`,\n ),\n );\n};\n"]}
package/dist/env.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ export declare const env: {
2
+ readonly CI: boolean;
3
+ };
4
+ //# sourceMappingURL=env.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../src/env.ts"],"names":[],"mappings":"AAgBA,eAAO,MAAM,GAAG;;CAIf,CAAC"}
package/dist/env.js ADDED
@@ -0,0 +1,21 @@
1
+ /**
2
+ * @file Environment variable configuration.
3
+ *
4
+ * This file intentionally exports an `env` object so that it can easily be
5
+ * auto-imported just by typing `env`.
6
+ *
7
+ * Getters are used so that required env vars only throw when they are actually
8
+ * accessed. That way you do not always have to supply all env vars (e.g. when
9
+ * running only a subset of the app).
10
+ *
11
+ * However, it is strongly encouraged to destructure env vars at the top-level
12
+ * module scope so that errors are thrown immediately: `const { CI } = env;`
13
+ * Processes should fail immediately if an env var is missing.
14
+ */
15
+ import envVar from "env-var";
16
+ export const env = {
17
+ get CI() {
18
+ return envVar.get("CI").default("false").asBool();
19
+ },
20
+ };
21
+ //# sourceMappingURL=env.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"env.js","sourceRoot":"","sources":["../src/env.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,MAAM,MAAM,SAAS,CAAC;AAE7B,MAAM,CAAC,MAAM,GAAG,GAAG;IACjB,IAAI,EAAE;QACJ,OAAO,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,CAAC;IACpD,CAAC;CACF,CAAC","sourcesContent":["/**\n * @file Environment variable configuration.\n *\n * This file intentionally exports an `env` object so that it can easily be\n * auto-imported just by typing `env`.\n *\n * Getters are used so that required env vars only throw when they are actually\n * accessed. That way you do not always have to supply all env vars (e.g. when\n * running only a subset of the app).\n *\n * However, it is strongly encouraged to destructure env vars at the top-level\n * module scope so that errors are thrown immediately: `const { CI } = env;`\n * Processes should fail immediately if an env var is missing.\n */\nimport envVar from \"env-var\";\n\nexport const env = {\n get CI() {\n return envVar.get(\"CI\").default(\"false\").asBool();\n },\n};\n"]}
@@ -0,0 +1,26 @@
1
+ type ErrorMessagePrimitive = string | false | undefined;
2
+ /**
3
+ * ErrorMessage is a union of different possible error message types:
4
+ *
5
+ * - ErrorMessagePrimitive (that is string | false | undefined)
6
+ * - A function that returns a ErrorMessagePrimitive
7
+ *
8
+ * undefined and false are possible error message types so that they can
9
+ * be excluded in the production bundle via tree-shaking:
10
+ *
11
+ * import.meta.env.DEV && errorMessage
12
+ *
13
+ * Bundlers will replace import.meta.env.DEV with `false` and minifiers
14
+ * will remove the right-hand side of the && operator.
15
+ */
16
+ export type ErrorMessage = ErrorMessagePrimitive | (() => ErrorMessagePrimitive);
17
+ /**
18
+ * Returns the error message from the given error message or the default error message.
19
+ *
20
+ * @param errorMessage - The error message to return.
21
+ * @param getDefaultErrorMessage - The default error message to return if the error message doesn't evaluate to a string.
22
+ * @returns The error message.
23
+ */
24
+ export declare const getErrorMessage: (errorMessage: ErrorMessage, getDefaultErrorMessage: () => string) => string;
25
+ export {};
26
+ //# sourceMappingURL=error-message.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error-message.d.ts","sourceRoot":"","sources":["../../src/lib/error-message.ts"],"names":[],"mappings":"AAAA,KAAK,qBAAqB,GAAG,MAAM,GAAG,KAAK,GAAG,SAAS,CAAC;AAExD;;;;;;;;;;;;;GAaG;AACH,MAAM,MAAM,YAAY,GACpB,qBAAqB,GACrB,CAAC,MAAM,qBAAqB,CAAC,CAAC;AAElC;;;;;;GAMG;AACH,eAAO,MAAM,eAAe,GAC1B,cAAc,YAAY,EAC1B,wBAAwB,MAAM,MAAM,KACnC,MAOF,CAAC"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Returns the error message from the given error message or the default error message.
3
+ *
4
+ * @param errorMessage - The error message to return.
5
+ * @param getDefaultErrorMessage - The default error message to return if the error message doesn't evaluate to a string.
6
+ * @returns The error message.
7
+ */
8
+ export const getErrorMessage = (errorMessage, getDefaultErrorMessage) => {
9
+ const errorMessagePrimitive = typeof errorMessage === "function" ? errorMessage() : errorMessage;
10
+ // Behavior for falsy values is actually wanted here
11
+ // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
12
+ return errorMessagePrimitive || getDefaultErrorMessage();
13
+ };
14
+ //# sourceMappingURL=error-message.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error-message.js","sourceRoot":"","sources":["../../src/lib/error-message.ts"],"names":[],"mappings":"AAoBA;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAC7B,YAA0B,EAC1B,sBAAoC,EAC5B,EAAE;IACV,MAAM,qBAAqB,GACzB,OAAO,YAAY,KAAK,UAAU,CAAC,CAAC,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC,YAAY,CAAC;IAErE,oDAAoD;IACpD,wEAAwE;IACxE,OAAO,qBAAqB,IAAI,sBAAsB,EAAE,CAAC;AAC3D,CAAC,CAAC","sourcesContent":["type ErrorMessagePrimitive = string | false | undefined;\n\n/**\n * ErrorMessage is a union of different possible error message types:\n *\n * - ErrorMessagePrimitive (that is string | false | undefined)\n * - A function that returns a ErrorMessagePrimitive\n *\n * undefined and false are possible error message types so that they can\n * be excluded in the production bundle via tree-shaking:\n *\n * import.meta.env.DEV && errorMessage\n *\n * Bundlers will replace import.meta.env.DEV with `false` and minifiers\n * will remove the right-hand side of the && operator.\n */\nexport type ErrorMessage =\n | ErrorMessagePrimitive\n | (() => ErrorMessagePrimitive);\n\n/**\n * Returns the error message from the given error message or the default error message.\n *\n * @param errorMessage - The error message to return.\n * @param getDefaultErrorMessage - The default error message to return if the error message doesn't evaluate to a string.\n * @returns The error message.\n */\nexport const getErrorMessage = (\n errorMessage: ErrorMessage,\n getDefaultErrorMessage: () => string,\n): string => {\n const errorMessagePrimitive: ErrorMessagePrimitive =\n typeof errorMessage === \"function\" ? errorMessage() : errorMessage;\n\n // Behavior for falsy values is actually wanted here\n // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing\n return errorMessagePrimitive || getDefaultErrorMessage();\n};\n"]}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Stringify a value to a string using String(value).
3
+ *
4
+ * @param value - The value to stringify.
5
+ * @returns The stringified value.
6
+ */
7
+ export declare const simpleStringify: (value: unknown) => string;
8
+ /**
9
+ * Stringify a value to a string using JSON.stringify.
10
+ * Fallback to String(value) if JSON.stringify fails.
11
+ *
12
+ * @param value - The value to stringify.
13
+ * @param options - The options for the stringification.
14
+ * @param options.limit - The maximum number of characters to include in the string. Defaults to 50.
15
+ * @returns The stringified value.
16
+ */
17
+ export declare const stringify: (value: unknown, { limit, }?: {
18
+ limit?: number;
19
+ }) => string;
20
+ //# sourceMappingURL=string.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"string.d.ts","sourceRoot":"","sources":["../../src/lib/string.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,eAAO,MAAM,eAAe,GAAI,OAAO,OAAO,KAAG,MAKhD,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,SAAS,GACpB,OAAO,OAAO,EACd,aAEG;IACD,KAAK,CAAC,EAAE,MAAM,CAAC;CACX,WAsBP,CAAC"}
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Stringify a value to a string using String(value).
3
+ *
4
+ * @param value - The value to stringify.
5
+ * @returns The stringified value.
6
+ */
7
+ export const simpleStringify = (value) => {
8
+ if (typeof value === "string") {
9
+ return `"${value}"`;
10
+ }
11
+ return String(value);
12
+ };
13
+ /**
14
+ * Stringify a value to a string using JSON.stringify.
15
+ * Fallback to String(value) if JSON.stringify fails.
16
+ *
17
+ * @param value - The value to stringify.
18
+ * @param options - The options for the stringification.
19
+ * @param options.limit - The maximum number of characters to include in the string. Defaults to 50.
20
+ * @returns The stringified value.
21
+ */
22
+ export const stringify = (value, { limit = 50, } = {}) => {
23
+ let stringified;
24
+ try {
25
+ stringified = JSON.stringify(value);
26
+ }
27
+ catch {
28
+ // Do nothing
29
+ }
30
+ // Empty string should also use String(value)
31
+ // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
32
+ stringified ||= simpleStringify(value);
33
+ return limit === 0
34
+ ? ""
35
+ : stringified.length > limit
36
+ ? stringified.slice(0, limit) + "…"
37
+ : stringified;
38
+ };
39
+ //# sourceMappingURL=string.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"string.js","sourceRoot":"","sources":["../../src/lib/string.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,KAAc,EAAU,EAAE;IACxD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO,IAAI,KAAK,GAAG,CAAC;IACtB,CAAC;IACD,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;AACvB,CAAC,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CACvB,KAAc,EACd,EACE,KAAK,GAAG,EAAE,MAGR,EAAE,EACN,EAAE;IACF,IAAI,WAAW,CAAC;IAEhB,IAAI,CAAC;QACH,WAAW,GAAG,IAAI,CAAC,SAAS,CAC1B,KAAK,CAEN,CAAC;IACJ,CAAC;IAAC,MAAM,CAAC;QACP,aAAa;IACf,CAAC;IAED,6CAA6C;IAC7C,wEAAwE;IACxE,WAAW,KAAK,eAAe,CAAC,KAAK,CAAC,CAAC;IAEvC,OAAO,KAAK,KAAK,CAAC;QAChB,CAAC,CAAC,EAAE;QACJ,CAAC,CAAC,WAAW,CAAC,MAAM,GAAG,KAAK;YAC1B,CAAC,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,GAAG,GAAG;YACnC,CAAC,CAAC,WAAW,CAAC;AACpB,CAAC,CAAC","sourcesContent":["/**\n * Stringify a value to a string using String(value).\n *\n * @param value - The value to stringify.\n * @returns The stringified value.\n */\nexport const simpleStringify = (value: unknown): string => {\n if (typeof value === \"string\") {\n return `\"${value}\"`;\n }\n return String(value);\n};\n\n/**\n * Stringify a value to a string using JSON.stringify.\n * Fallback to String(value) if JSON.stringify fails.\n *\n * @param value - The value to stringify.\n * @param options - The options for the stringification.\n * @param options.limit - The maximum number of characters to include in the string. Defaults to 50.\n * @returns The stringified value.\n */\nexport const stringify = (\n value: unknown,\n {\n limit = 50,\n }: {\n limit?: number;\n } = {},\n) => {\n let stringified;\n\n try {\n stringified = JSON.stringify(\n value,\n // not adding indentations on purpose because we want a compact string\n );\n } catch {\n // Do nothing\n }\n\n // Empty string should also use String(value)\n // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing\n stringified ||= simpleStringify(value);\n\n return limit === 0\n ? \"\"\n : stringified.length > limit\n ? stringified.slice(0, limit) + \"…\"\n : stringified;\n};\n"]}
package/dist/main.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from "./assert/assert.ts";
2
+ //# sourceMappingURL=main.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC"}
package/dist/main.js ADDED
@@ -0,0 +1,2 @@
1
+ export * from "./assert/assert.js";
2
+ //# sourceMappingURL=main.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"main.js","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC","sourcesContent":["export * from \"./assert/assert.ts\";\n"]}
package/package.json ADDED
@@ -0,0 +1,72 @@
1
+ {
2
+ "name": "@peerigon/typescript-toolkit",
3
+ "version": "0.0.1-semantically-released",
4
+ "description": "🔧✨ Tiny helpers for TypeScript applications",
5
+ "keywords": [],
6
+ "homepage": "https://github.com/peerigon/typescript-toolkit#readme",
7
+ "bugs": {
8
+ "url": "https://github.com/peerigon/typescript-toolkit/issues"
9
+ },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/peerigon/typescript-toolkit.git"
13
+ },
14
+ "license": "MIT",
15
+ "author": "Peerigon GmbH <hello@peerigon.com>",
16
+ "sideEffects": false,
17
+ "type": "module",
18
+ "exports": {
19
+ ".": "./dist/main.js",
20
+ "./add": "./dist/add.js"
21
+ },
22
+ "main": "./dist/main.js",
23
+ "files": [
24
+ "dist",
25
+ "README.md"
26
+ ],
27
+ "scripts": {
28
+ "prepare": "husky",
29
+ "test": "run-p test:*",
30
+ "test:format": "prettier --check .",
31
+ "test:lint": "eslint --max-warnings 0 --cache .",
32
+ "test:types": "tsc",
33
+ "test:unit": "vitest --run",
34
+ "test:jsr": "jsr publish --dry-run --allow-dirty",
35
+ "test:build": "run-s build test:build:*",
36
+ "test:build:size": "size-limit",
37
+ "vitest": "vitest",
38
+ "build": "run-s build:*",
39
+ "build:clear": "rimraf dist",
40
+ "build:tsc": "tsc -p tsconfig.build.json",
41
+ "prepublishOnly": "npm run build",
42
+ "release": "semantic-release"
43
+ },
44
+ "dependencies": {
45
+ "env-var": "^7.5.0"
46
+ },
47
+ "devDependencies": {
48
+ "@djankies/vitest-mcp": "0.5.1",
49
+ "@eslint/mcp": "0.3.5",
50
+ "@peerigon/configs": "^15.4.0",
51
+ "@secretlint/secretlint-rule-preset-recommend": "^13.0.2",
52
+ "@size-limit/preset-small-lib": "^12.1.0",
53
+ "@types/node": "^25.8.0",
54
+ "@vitest/coverage-v8": "^4.1.6",
55
+ "eslint": "^9.39.2",
56
+ "husky": "^9.1.7",
57
+ "jsr": "^0.14.3",
58
+ "lint-staged": "^17.0.4",
59
+ "npm-run-all2": "^8.0.4",
60
+ "pin-github-action": "^3.4.0",
61
+ "prettier": "^3.8.3",
62
+ "rimraf": "^6.0.1",
63
+ "secretlint": "^13.0.2",
64
+ "semantic-release": "^25.0.3",
65
+ "ts-lsp-mcp": "0.1.3",
66
+ "typescript": "^5.9.3",
67
+ "vitest": "^4.1.6"
68
+ },
69
+ "publishConfig": {
70
+ "access": "public"
71
+ }
72
+ }