@autoplay/utils
Advanced tools
Comparing version 0.0.11 to 0.0.12
@@ -31,2 +31,4 @@ /** | ||
record(key: string, value: unknown): DevString; | ||
/** experimental: Throw a new error with this dev string as the display */ | ||
invariantThrow(): never; | ||
toDisplay(): string; | ||
@@ -33,0 +35,0 @@ toString(): string; |
import { devStringify } from "./devStringify"; | ||
import { invariantThrow } from "./invariant"; | ||
/** | ||
@@ -46,2 +47,6 @@ * Future: maybe replaceable during build to create smaller packages. | ||
} | ||
/** experimental: Throw a new error with this dev string as the display */ | ||
invariantThrow() { | ||
invariantThrow(this); | ||
} | ||
// Notice that `"" + {toString() { return 1}} === "1"` | ||
@@ -52,3 +57,3 @@ toDisplay() { | ||
? `#${this._templateOrID}: ${stringSubs.join("; ")}` // if dev calls are replaced with message identifiers (this is speculative) | ||
: String.raw(this._templateOrID, stringSubs); | ||
: String.raw(this._templateOrID, ...stringSubs); | ||
if (this._values) { | ||
@@ -55,0 +60,0 @@ if (this._values.cause) { |
@@ -0,1 +1,2 @@ | ||
import { DevString } from "./DevString"; | ||
import { tightJsonStringify } from "./tightJsonStringify"; | ||
@@ -20,2 +21,5 @@ /** | ||
} | ||
else if (display && input instanceof DevString) { | ||
return input.toDisplay(); | ||
} | ||
else if (typeof input === "function" || input instanceof Error) { | ||
@@ -47,3 +51,3 @@ return input.toString(); | ||
// return stack; | ||
return stack | ||
return (stack | ||
// replace private paths before node_modules | ||
@@ -54,3 +58,3 @@ .replace(/(\(|\sat )\/[^\)\s]+node_modules\//gm, "$1node_modules/") | ||
return beforeQuote + `"` + inside.split(/\\n/g).join("\n" + " ".repeat(beforeQuote.length)) + '"'; | ||
}); | ||
})); | ||
} |
{ | ||
"name": "@autoplay/utils", | ||
"version": "0.0.11", | ||
"version": "0.0.12", | ||
"description": "Utilities designed for error management, parsing, and TypeScript domain modeling.", | ||
@@ -5,0 +5,0 @@ "keywords": [], |
import { devStringify } from "./devStringify"; | ||
import { invariantThrow } from "./invariant"; | ||
@@ -55,2 +56,7 @@ /** | ||
/** experimental: Throw a new error with this dev string as the display */ | ||
invariantThrow(): never { | ||
invariantThrow(this); | ||
} | ||
// Notice that `"" + {toString() { return 1}} === "1"` | ||
@@ -62,3 +68,3 @@ toDisplay() { | ||
? `#${this._templateOrID}: ${stringSubs.join("; ")}` // if dev calls are replaced with message identifiers (this is speculative) | ||
: String.raw(this._templateOrID as TemplateStringsArray, stringSubs); | ||
: String.raw(this._templateOrID as TemplateStringsArray, ...stringSubs); | ||
if (this._values) { | ||
@@ -65,0 +71,0 @@ if (this._values.cause) { |
@@ -0,1 +1,2 @@ | ||
import { DevString } from "./DevString"; | ||
import { tightJsonStringify } from "./tightJsonStringify"; | ||
@@ -19,2 +20,4 @@ | ||
return input; | ||
} else if (display && input instanceof DevString) { | ||
return input.toDisplay(); | ||
} else if (typeof input === "function" || input instanceof Error) { | ||
@@ -46,9 +49,11 @@ return input.toString(); | ||
// return stack; | ||
return stack | ||
// replace private paths before node_modules | ||
.replace(/(\(|\sat )\/[^\)\s]+node_modules\//gm, "$1node_modules/") | ||
// replace escaped newlines in strings | ||
.replace(/(.+?)"(.*\\n(.(?!\\"))+|\\")*"/gm, (_fullMatch, beforeQuote, inside) => { | ||
return beforeQuote + `"` + inside.split(/\\n/g).join("\n" + " ".repeat(beforeQuote.length)) + '"'; | ||
}); | ||
return ( | ||
stack | ||
// replace private paths before node_modules | ||
.replace(/(\(|\sat )\/[^\)\s]+node_modules\//gm, "$1node_modules/") | ||
// replace escaped newlines in strings | ||
.replace(/(.+?)"(.*\\n(.(?!\\"))+|\\")*"/gm, (_fullMatch, beforeQuote, inside) => { | ||
return beforeQuote + `"` + inside.split(/\\n/g).join("\n" + " ".repeat(beforeQuote.length)) + '"'; | ||
}) | ||
); | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
97427
2053