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-17.6.0 node_modules/cli-width/index.js
govuk_publishing_components-17.5.0 node_modules/cli-width/index.js
govuk_publishing_components-17.4.0 node_modules/cli-width/index.js
govuk_publishing_components-17.3.0 node_modules/cli-width/index.js
govuk_publishing_components-17.2.0 node_modules/cli-width/index.js
govuk_publishing_components-17.1.1 node_modules/cli-width/index.js
govuk_publishing_components-17.1.0 node_modules/cli-width/index.js
govuk_publishing_components-17.0.0 node_modules/cli-width/index.js
govuk_publishing_components-16.29.0 node_modules/cli-width/index.js
govuk_publishing_components-16.28.0 node_modules/cli-width/index.js
govuk_publishing_components-16.27.1 node_modules/cli-width/index.js
govuk_publishing_components-16.27.0 node_modules/cli-width/index.js
govuk_publishing_components-16.26.0 node_modules/cli-width/index.js
govuk_publishing_components-16.25.0 node_modules/cli-width/index.js
govuk_publishing_components-16.24.0 node_modules/cli-width/index.js
govuk_publishing_components-16.23.0 node_modules/cli-width/index.js
govuk_publishing_components-16.22.0 node_modules/cli-width/index.js
govuk_publishing_components-16.21.0 node_modules/cli-width/index.js
govuk_publishing_components-16.20.1 node_modules/cli-width/index.js
govuk_publishing_components-16.20.0 node_modules/cli-width/index.js