How to use trim-trailing-lines - 5 common examples

To help you get started, we’ve selected a few trim-trailing-lines examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github GitbookIO / markup-it / __tests__ / all.js View on Github external
function serializeWith(syntax, props) {
        const parser = State.create(syntax, props);
        const out = parser.serializeDocument(inputDocument);

        // Trim to avoid newlines being compared at the end
        return trimTrailingLines(out);
    }
github GitbookIO / markup-it / __tests__ / all.js View on Github external
function readFileOutput(fileName) {
    const ext = path.extname(fileName);
    const content = fs.readFileSync(fileName, { encoding: 'utf8' });

    switch (ext) {
        case '.md':
        case '.adoc':
        case '.html':
            // We trim to avoid newlines being compared at the end
            return trimTrailingLines(content);
        case '.js':
            return Value.create({
                document: require(fileName).default
            }).document;
        default:
            throw new Error(`Unknown extension ${ext}`);
    }
}
github GitbookIO / markup-it / src / markdown / blocks / list.js View on Github external
const isChecked = item.data.get('checked');

    // Is it a loose list?
    const loose = item.nodes.some(child => child.type === BLOCKS.PARAGRAPH);

    // Is it the last item from the list?
    const last = list.nodes.size - 1 === index;

    // Calcul bullet to use
    const bullet = list.type === BLOCKS.OL_LIST ? `${index + 1}.` : '*';

    // Indent all lignes
    const indent = bullet.length + 1;
    let body = state.use('block').serialize(item.nodes);
    // Remove unwanted empty lines added by sub-blocks
    body = `${trimTrailingLines(body)}\n`;

    body = indentString(body, indent, { indent: ' ' }).slice(indent);

    if (loose || last) {
        // Add empty line
        body += '\n';
    }

    if (hasChecked) {
        body = `${isChecked ? '[x]' : '[ ]'} ${body}`;
    }

    return `${bullet} ${body}`;
}
github nteract / nteract / packages / markdown / src / remark-math / block.ts View on Github external
character = value.charAt(index);

        if (character === C_NEWLINE) {
          break;
        }

        closing += character;
        exdentedClosing += character;
        index++;
      }

      break;
    }

    subvalue += content + closing;
    const trimmedContent = trim(exdentedContent);
    return eat(subvalue)({
      type: "math",
      value: trimmedContent,
      data: {
        hName: "div",
        hProperties: {
          className: "math"
        },
        hChildren: [
          {
            type: "text",
            value: trimmedContent
          }
        ]
      }
    });
github mosjs / mos / packages / mos-core / src / parse / block-tokenizers / renderers / code-block.ts View on Github external
export default function renderCodeBlock (value: string, language?: string): CodeNode {
  return {
    type: 'code',
    lang: language || null,
    value: trimTrailingLines(value || ''),
  }
}

trim-trailing-lines

Remove final line feeds from a string

MIT
Latest version published 2 years ago

Package Health Score

65 / 100
Full package analysis

Popular trim-trailing-lines functions