BVB Source Codes

reactide Show index.js Source code

Return Download reactide: download index.js Source code - Download reactide Source code - Type:.js
  1. /*!
  2.  * align-text <https://github.com/jonschlinkert/align-text>
  3.  *
  4.  * Copyright (c) 2015, Jon Schlinkert.
  5.  * Licensed under the MIT License.
  6.  */
  7.  
  8. 'use strict';
  9.  
  10. var typeOf = require('kind-of');
  11. var repeat = require('repeat-string');
  12. var longest = require('longest');
  13.  
  14. module.exports = function alignText(val, fn) {
  15.   var lines, type = typeOf(val);
  16.  
  17.   if (type === 'array') {
  18.     lines = val;
  19.   } else if (type === 'string') {
  20.     lines = val.split(/(?:\r\n|\n)/);
  21.   } else {
  22.     throw new TypeError('align-text expects a string or array.');
  23.   }
  24.  
  25.   var fnType = typeOf(fn);
  26.   var len = lines.length;
  27.   var max = longest(lines);
  28.   var res = [], i = 0;
  29.  
  30.   while (len--) {
  31.     var line = String(lines[i++]);
  32.     var diff;
  33.  
  34.     if (fnType === 'function') {
  35.       diff = fn(line.length, max.length, line, lines, i);
  36.     } else if (fnType === 'number') {
  37.       diff = fn;
  38.     } else {
  39.       diff = max.length - line.length;
  40.     }
  41.  
  42.     if (typeOf(diff) === 'number') {
  43.       res.push(repeat(' ', diff) + line);
  44.     } else if (typeOf(diff) === 'object') {
  45.       var result = repeat(diff.character || ' ', diff.indent || 0);
  46.       res.push((diff.prefix || '') + result + line);
  47.     }
  48.   }
  49.  
  50.   if (type === 'array') return res;
  51.   return res.join('\n');
  52. };
  53.  
downloadindex.js Source code - Download reactide Source code
Related Source Codes/Software:
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
postal - 2017-06-11
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top