string-escape-spacing
    TypeScript icon, indicating that this package has built-in type declarations

    0.0.4 • Public • Published

    string-escape-spacing

    Background

    A small javascript package for escaping special characters interpreted as spacing in strings.

    Imagine you're writing a code snippet in a template string.

    const code = `fmt.Printf("%06d\n",1)`;

    If you then did a console.log (or any other outputting), you'd get

    fmt.Printf("%06d
    ",1)
    

    Hey, that's not what you wanted! 😭

    Obviously, you could escape the backslash (\n\\n) but that's not how you'd actually write the code.

    Enter string-escape-spacing! It works by looking for unescaped spacing characters (i.e. \n, \r, \t, \v ) enclosed in string characters ("The\tdog\twas\tlazy") whilst ignoring the string if it had no quotes around it (The\tdog\twas\tlazy).

    Usage

    Installation

    yarn add string-escape-spacing
    npm install string-escape-spacing
    

    Example

    import escapeString from "string-escape-spacing";
     
    const string = `"The\tdog\twas\tlazy"`;
    console.log(escapeString(string));
    // output:`"The\\tdog\\twas\\tlazy"`

    API

    const escaped = escapeString(stringToEscape, options);

    Options

    options = {
      quotes: "single" | "double",
    };

    Install

    npm i string-escape-spacing

    DownloadsWeekly Downloads

    5

    Version

    0.0.4

    License

    MIT

    Unpacked Size

    5.89 kB

    Total Files

    8

    Last publish

    Collaborators

    • morsby