Git Product home page Git Product logo

node-ts-dedent's People

Contributors

armaant avatar avivahl avatar dependabot[bot] avatar eirslett avatar hipstersmoothie avatar tamino-martinius avatar whoaa512 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

node-ts-dedent's Issues

Could you please explain exactly what it does in the docs?

Based on the examples, I think it removes a starting bare newline, and then removes the number of whitespace characters on the first line that starts with whitespace characters. Or does it remove the number of whitespace characters on the line with the fewest leading whitespace characters?

A quick summary of what the algorithm is would make it easier than having to look in the code or try stuff.

Handle interpolations properly

import dedent from 'ts-dedent'

const fieldDocs = dedent`
  * a
  * b
  * c
`

const a = dedent`
  /**
   ${fieldIntro()}
   *
   ${fieldDocs}
   *
   ${fieldExample()} 
   */
`

function fieldIntro() {
  return dedent`
    * 0
  `
}
function fieldExample() {
  return dedent`
    * d
  `
}

console.log(a)

Expected

/**
 * 0
 *
 * a
 * b
 * c
 *
 * d 
 */

Actual

/**
 * 0
 *
 * a
* b
* c
 *
 * d 
 */

ts typings error

Got error :

error TS7016: Could not find a declaration file for module 'dedent'. '.../node_modules/dedent/dist/dedent.js' implicitly has an 'any' type.
Try npm install @types/dedent if it exists or add a new declaration (.d.ts) file containing declare module 'dedent';

Can you please publish @types/ts-dedent? That would help.

Dedenting doesn't work when using on stored strings

I had my string stored in a variable, and used dedent on it.

        const string = `
        Leading and trailing lines will be trimmed, so you can write something like
        this and have it work as you expect:
       
          * how convenient it is
          * that I can use an indented list
              - and still have it do the right thing
       
        That's all.
      `;
        const dedentedString1 = dedent`
        Leading and trailing lines will be trimmed, so you can write something like
        this and have it work as you expect:
       
          * how convenient it is
          * that I can use an indented list
              - and still have it do the right thing
       
        That's all.
      `;
        const dedentedString2 = dedent`
      ${string}
    `;

dedentedString2 did not dedent the string at all.

        Leading and trailing lines will be trimmed, so you can write something like
        this and have it work as you expect:
       
          * how convenient it is
          * that I can use an indented list
              - and still have it do the right thing
       
        That's all.

Not sure if this is a feature request or a bug.

Remove trailing spaces on empty lines in interpolated text

See indentjs/endent#12 for an example failing test.

const insertion = "indented 1\n\nindented 2";
const output = endent`
  foo
    ${insertion}
`;
const current = output === "foo\n  indented 1\n  \n  indented 2"
const desired = output === "foo\n  indented 1\n\n  indented 2"

I have worked around this by tacking .replaceAll(/\n\s*\n/gi, '\n\n') at the end of our dedent() calls in a wrapper function.

Unicode Escape Sequence Handling

Feature request: unicode escape sequence handling.

import dedent from 'dedent';

console.log(`\u00E4`); // Prints ä
console.log(dedent`\u00E4`); // Prints \u00E4 - expected ä

Backticks (possibly) cause no dedent

I've got a weird one for you, one that seems to be a problem in the older dedent package as well (dmnd/dedent#26). Escaped backticks result in no dedent-ing.

const content = '    [APBannerManager showBannerWithTitle:@"Title"\n' +
    '                                          subtitle:@"Subtitle"\n' +
    '                                          body:@"Body"\n' +
    '                                          image:[UIImage imageNamed:@"myPicture"]\n' +
    '                                          actionBlock:^(APBannerActionType type) {\n' +
    '                                            switch (type) {\n' +
    '                                              case APBannerActionTypeTap:\n' +
    '                                                NSLog(@"TAP");\n' +
    '                                                break;\n' +
    '                                              case APBannerActionTypeDismiss:\n' +
    '                                                NSLog(@"DISMISS");\n' +
    '                                                break;\n' +
    '                                            }\n' +
    '                                          }];';
   dedent(`\`\`\`
${content}
\`\`\``);

What we end up with is:

\`\`\`
    [APBannerManager showBannerWithTitle:@"Title"
                                          subtitle:@"Subtitle"
                                          body:@"Body"
                                          image:[UIImage imageNamed:@"myPicture"]
                                          actionBlock:^(APBannerActionType type) {
                                            switch (type) {
                                              case APBannerActionTypeTap:
                                                NSLog(@"TAP");
                                                break;
                                              case APBannerActionTypeDismiss:
                                                NSLog(@"DISMISS");
                                                break;
                                            }
                                          }];
\`\`\`

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.