How to use word-wrap - 10 common examples

To help you get started, we’ve selected a few word-wrap 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 ediardo / kmdr-cli / src / console.ts View on Github external
public print(msg: string, options = this.defaultPrintOptions) {
    // tslint:disable-next-line: prefer-const
    let { margin, prependNewLine, appendNewLine, wrap } = options;

    if (margin === undefined) {
      margin = 2;
    }

    const spaces = " ".repeat(margin);

    if (prependNewLine === true) {
      console.log();
    }

    if (wrap) {
      const wrappedMsg = WordWrap(msg, { indent: spaces, width: this.width - margin * 2 });
      console.log(wrappedMsg);
    } else {
      console.log(`${spaces}${msg}`);
    }

    if (appendNewLine === true) {
      console.log();
    }
  }
github pixeloven / pixeloven / packages / pixeloven / cz-simplified-changelog / src / engine.ts View on Github external
]).then((answers: SimplifiedAnswers) => {
                const wrapOptions = {
                    cut: false,
                    indent: "",
                    newline: "\n",
                    trim: true,
                    width: options.maxLineWidth,
                };
                const issues = answers.issues
                    ? wrap(answers.issues, wrapOptions)
                    : "";
                const scope = issues ? "(" + issues + ")" : "";

                // Hard limit this line in the validate
                const subject = answers.type + scope + ": " + answers.subject;

                // Wrap these lines at options.maxLineWidth characters
                const body = answers.body
                    ? wrap(answers.body, wrapOptions)
                    : "";

                commit(filter([subject, body]).join("\n\n"));
            });
        },
github DefinitelyTyped / DefinitelyTyped / types / word-wrap / word-wrap-tests.ts View on Github external
import wrap from "word-wrap";

const str =
    "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut " +
    "labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco " +
    "laboris nisi ut aliquip ex ea commodo consequat.";

wrap(str, { width: 60 });

wrap(str, { indent: "      " });

wrap(str, { newline: "\n\n" });

wrap(str, {
    escape: str => str.toLowerCase()
});

wrap(str, { trim: true });

wrap(str, { cut: true });

wrap(str);
github forivall / tacoscript / packages / tacoscript / src / cli / usage / comal.js View on Github external
if (optConf.shorthand) opts.push("-" + optConf.shorthand);

    console.log(wrap(opts.join(', '), {indent: '  ', width: 78}));

    if (extra.default && optConf.default && (!isArray(optConf.default) || optConf.default.length)) {
      console.log(wrap(`(default: ${optConf.default})`, {indent: '      ', width: 74}));
    }

    if (optConf.description) {
      console.log(wrap(optConf.description, {indent: '    ', width: 76}));
    }

    console.log();
  }

  if (extra.after) console.log("\n" + wrap(extra.after, {width: 80}));

  cb({code: 0});
}
github forivall / tacoscript / packages / tacoscript / src / cli / usage / comal.js View on Github external
console.log("Advanced Options:\n");

  if (extra.before) console.log(wrap(extra.before, {width: 80}) + "\n");

  for (let optName in coreOptions) {
    let optConf = coreOptions[optName];
    if (optConf.hidden) continue;

    let opts = ["--" + kebabCase(optName)].concat(transform(coreOptions, (aliases, aliasConf, aliasName) => {
      if (aliasConf.alias === optName) aliases.push("--" + kebabCase(aliasName))
    }, []));

    if (optConf.shorthand) opts.push("-" + optConf.shorthand);

    console.log(wrap(opts.join(', '), {indent: '  ', width: 78}));

    if (extra.default && optConf.default && (!isArray(optConf.default) || optConf.default.length)) {
      console.log(wrap(`(default: ${optConf.default})`, {indent: '      ', width: 74}));
    }

    if (optConf.description) {
      console.log(wrap(optConf.description, {indent: '    ', width: 76}));
    }

    console.log();
  }

  if (extra.after) console.log("\n" + wrap(extra.after, {width: 80}));

  cb({code: 0});
}
github forivall / tacoscript / packages / tacoscript / src / cli / usage / comal.js View on Github external
export default function(argConf, ...rest) {
  const cb = rest.pop();
  const extra = rest[0] || {};

  console.log("Advanced Options:\n");

  if (extra.before) console.log(wrap(extra.before, {width: 80}) + "\n");

  for (let optName in coreOptions) {
    let optConf = coreOptions[optName];
    if (optConf.hidden) continue;

    let opts = ["--" + kebabCase(optName)].concat(transform(coreOptions, (aliases, aliasConf, aliasName) => {
      if (aliasConf.alias === optName) aliases.push("--" + kebabCase(aliasName))
    }, []));

    if (optConf.shorthand) opts.push("-" + optConf.shorthand);

    console.log(wrap(opts.join(', '), {indent: '  ', width: 78}));

    if (extra.default && optConf.default && (!isArray(optConf.default) || optConf.default.length)) {
      console.log(wrap(`(default: ${optConf.default})`, {indent: '      ', width: 74}));
    }
github andreypopp / console-ui / src / index.js View on Github external
function _format(context: Context, element: Element, options: Options): string {
  if (typeof element === 'string') {
    element = paragraph(element);
  }
  if (Array.isArray(element)) {
    return element
      .map(element => _format(context, element, options))
      .join('');
  } else if (element.type === 'paragraph') {
    let text = _formatInline(element.children);
    return wrapString(text, {
      width: context.width,
      indent: _formatIndent(context.indent),
    }) + '\n\n';
  } else if (element.type === 'indent') {
    let nextContext = {...context, indent: context.indent + options.indentSize};
    return _format(nextContext, element.children, options);
  } else if (element.type === 'listItem') {
    let out = _format(context, indent(element.children), options);
    out = '- ' + out.slice(2);
    return out;
  } else {
    invariant(false, 'Unknown element: %s', element);
  }
}
github gajus / slonik / src / interceptors / createBenchmarkingInterceptor.js View on Github external
queries = queries.map((summary) => {
        return [
          wordWrap(stripComments(summary.sql), {
            indent: '',
            width: 60
          }),
          summary.executionCount,
          prettyMs(summary.average),
          prettyMs(summary.total)
        ];
      });
github buildkite / frontend / app / components / user / graphql / GraphQLExplorerDocumentation / Comment.js View on Github external
render() {
    return (
      <div style="{{">
        {wrap(this.props.text || "n/a", { width: 70, indent: '' }).replace(/(^|\n)/g, "$1# ")}
      </div>
    );
  }
}
github jonschlinkert / utils / lib / string / wordwrap.js View on Github external
module.exports = function wordwrap(str) {
  if (!isString(str)) return '';
  return wrap.apply(wrap, arguments);
};

word-wrap

Wrap words to a specified length.

MIT
Latest version published 1 year ago

Package Health Score

74 / 100
Full package analysis

Popular word-wrap functions