@thi.ng/strings
Version:
Various string formatting & utility functions
51 lines • 1.29 kB
TypeScript
import type { Stringer } from "./api.js";
/**
* Higher order version of `JSON.stringify()` with the option to treat top-level
* strings and numbers differently (i.e. NOT if they're nested values!). If
* `all` is `false` (default), strings and numbers are simply converted using
* `String(x)`. If `indent` is given, it will be used for `JSON.stringify(x,
* null, indent)`
*
* @remarks
* Special treatment for the following types:
*
* - `Error`: uses `.stack` or `.message` string properties
* - `RegExp`: use `.source` string property
*
* @example
* ```ts tangle:../export/stringify.ts
* import { stringify } from "@thi.ng/strings";
*
* console.log(
* stringify()("hello")
* );
* // hello
*
* console.log(
* stringify(true)("hello")
* );
* // "hello"
*
* console.log(
* stringify()({ a: "hello" })
* );
* // { "a": "hello" }
*
* console.log(
* stringify()(/\/abc/)
* );
* // "\\/abc"
*
* try {
* throw new Error("eek");
* } catch(e) {
* console.log(stringify()(e));
* }
* // "Error: eek\n at <...>/stringify.ts:22:13\n at moduleEvaluation (native:1:11)..."
* ```
*
* @param all -
* @param indent -
*/
export declare const stringify: (all?: boolean, indent?: number) => Stringer<any>;
//# sourceMappingURL=stringify.d.ts.map