Files
react-native-devtools-frontend/node_modules/remark-parse/lib/util/remove-indentation.js
T
Mathias Bynens 79e2cf0633 Add stylelint dependency
This also adds CC-BY-4.0 to the list of accepted licenses.

DISABLE_THIRD_PARTY_CHECK=update dependencies

Bug: chromium:1083142
Change-Id: I8612de2fba52dae32eeb71af79d5aacfde52142b
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2220097
Reviewed-by: Paul Lewis <aerotwist@chromium.org>
Commit-Queue: Mathias Bynens <mathias@chromium.org>
2020-06-11 06:20:04 +00:00

65 lines
1.3 KiB
JavaScript

'use strict'
var trim = require('trim')
var repeat = require('repeat-string')
var getIndent = require('./get-indentation')
module.exports = indentation
var lineFeed = '\n'
var space = ' '
var exclamationMark = '!'
// Remove the minimum indent from every line in `value`. Supports both tab,
// spaced, and mixed indentation (as well as possible).
function indentation(value, maximum) {
var values = value.split(lineFeed)
var position = values.length + 1
var minIndent = Infinity
var matrix = []
var index
var indentation
var stops
values.unshift(repeat(space, maximum) + exclamationMark)
while (position--) {
indentation = getIndent(values[position])
matrix[position] = indentation.stops
if (trim(values[position]).length === 0) {
continue
}
if (indentation.indent) {
if (indentation.indent > 0 && indentation.indent < minIndent) {
minIndent = indentation.indent
}
} else {
minIndent = Infinity
break
}
}
if (minIndent !== Infinity) {
position = values.length
while (position--) {
stops = matrix[position]
index = minIndent
while (index && !(index in stops)) {
index--
}
values[position] = values[position].slice(stops[index] + 1)
}
}
values.shift()
return values.join(lineFeed)
}