Sha256: 6cfabc60c7a069b9ca720c15be6a33a05c7913655c837102e9f10c10c81880db

Contents?: true

Size: 896 Bytes

Versions: 6

Compression:

Stored size: 896 Bytes

Contents

var splitRE = /\r?\n/g
var emptyRE = /^\s*$/
var needFixRE = /^(\r?\n)*[\t\s]/

module.exports = function deindent (str) {
  if (!needFixRE.test(str)) {
    return str
  }
  var lines = str.split(splitRE)
  var min = Infinity
  var type, cur, c
  for (var i = 0; i < lines.length; i++) {
    var line = lines[i]
    if (!emptyRE.test(line)) {
      if (!type) {
        c = line.charAt(0)
        if (c === ' ' || c === '\t') {
          type = c
          cur = count(line, type)
          if (cur < min) {
            min = cur
          }
        } else {
          return str
        }
      } else {
        cur = count(line, type)
        if (cur < min) {
          min = cur
        }
      }
    }
  }
  return lines.map(function (line) {
    return line.slice(min)
  }).join('\n')
}

function count (line, type) {
  var i = 0
  while (line.charAt(i) === type) {
    i++
  }
  return i
}

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
ilog-0.4.1 node_modules/de-indent/index.js
ilog-0.4.0 node_modules/de-indent/index.js
ilog-0.3.3 node_modules/de-indent/index.js
jass-vue-0.4.0 vendor/node_modules/de-indent/index.js
jass-vue-0.3.0 vendor/node_modules/de-indent/index.js
jass-vue-0.2.1 vendor/node_modules/de-indent/index.js