Front end of the Slack clone application.

index.js 1023B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. 'use strict';
  2. exports = module.exports = cliWidth;
  3. function normalizeOpts(options) {
  4. var defaultOpts = {
  5. defaultWidth: 0,
  6. output: process.stdout,
  7. tty: require('tty')
  8. };
  9. if (!options) {
  10. return defaultOpts;
  11. } else {
  12. Object.keys(defaultOpts).forEach(function (key) {
  13. if (!options[key]) {
  14. options[key] = defaultOpts[key];
  15. }
  16. });
  17. return options;
  18. }
  19. }
  20. function cliWidth(options) {
  21. var opts = normalizeOpts(options);
  22. if (opts.output.getWindowSize) {
  23. return opts.output.getWindowSize()[0] || opts.defaultWidth;
  24. } else {
  25. if (opts.tty.getWindowSize) {
  26. return opts.tty.getWindowSize()[1] || opts.defaultWidth;
  27. } else {
  28. if (opts.output.columns) {
  29. return opts.output.columns;
  30. } else {
  31. if (process.env.CLI_WIDTH) {
  32. var width = parseInt(process.env.CLI_WIDTH, 10);
  33. if (!isNaN(width) && width !== 0) {
  34. return width;
  35. }
  36. }
  37. }
  38. return opts.defaultWidth;
  39. }
  40. }
  41. };