Sha256: 6142a094733597fb85140a2f3dc7b1d04d76c8a3d42d07798290100acd3792de

Contents?: true

Size: 1023 Bytes

Versions: 46

Compression:

Stored size: 1023 Bytes

Contents

'use strict';

exports = module.exports = cliWidth;

function normalizeOpts(options) {
  var defaultOpts = {
    defaultWidth: 0,
    output: process.stdout,
    tty: require('tty')
  };

  if (!options) {
    return defaultOpts;
  } else {
    Object.keys(defaultOpts).forEach(function (key) {
      if (!options[key]) {
        options[key] = defaultOpts[key];
      }
    });

    return options;
  }
}

function cliWidth(options) {
  var opts = normalizeOpts(options);

  if (opts.output.getWindowSize) {
    return opts.output.getWindowSize()[0] || opts.defaultWidth;
  } else {
    if (opts.tty.getWindowSize) {
      return opts.tty.getWindowSize()[1] || opts.defaultWidth;
    } else {
      if (opts.output.columns) {
        return opts.output.columns;
      } else {
        if (process.env.CLI_WIDTH) {
          var width = parseInt(process.env.CLI_WIDTH, 10);

          if (!isNaN(width) && width !== 0) {
            return width;
          }
        }
      }

      return opts.defaultWidth;
    }
  }
};

Version data entries

46 entries across 46 versions & 3 rubygems

Version Path
govuk_publishing_components-18.0.0 node_modules/cli-width/index.js
govuk_publishing_components-17.21.0 node_modules/cli-width/index.js
govuk_publishing_components-17.20.0 node_modules/cli-width/index.js
govuk_publishing_components-17.19.1 node_modules/cli-width/index.js
govuk_publishing_components-17.19.0 node_modules/cli-width/index.js
govuk_publishing_components-17.18.0 node_modules/cli-width/index.js
govuk_publishing_components-17.17.0 node_modules/cli-width/index.js
govuk_publishing_components-17.16.0 node_modules/cli-width/index.js
govuk_publishing_components-17.15.0 node_modules/cli-width/index.js
govuk_publishing_components-17.14.0 node_modules/cli-width/index.js
govuk_publishing_components-17.13.0 node_modules/cli-width/index.js
govuk_publishing_components-17.12.2 node_modules/cli-width/index.js
govuk_publishing_components-17.12.1 node_modules/cli-width/index.js
govuk_publishing_components-17.12.0 node_modules/cli-width/index.js
govuk_publishing_components-17.11.0 node_modules/cli-width/index.js
govuk_publishing_components-17.10.0 node_modules/cli-width/index.js
govuk_publishing_components-17.9.0 node_modules/cli-width/index.js
govuk_publishing_components-17.8.0 node_modules/cli-width/index.js
govuk_publishing_components-17.7.0 node_modules/cli-width/index.js
govuk_publishing_components-17.6.1 node_modules/cli-width/index.js