aboutsummaryrefslogtreecommitdiff
path: root/node_modules/indent-string/index.js
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2017-08-14 05:01:11 +0200
committerFlorian Dold <florian.dold@gmail.com>2017-08-14 05:02:09 +0200
commit363723fc84f7b8477592e0105aeb331ec9a017af (patch)
tree29f92724f34131bac64d6a318dd7e30612e631c7 /node_modules/indent-string/index.js
parent5634e77ad96bfe1818f6b6ee70b7379652e5487f (diff)
node_modules
Diffstat (limited to 'node_modules/indent-string/index.js')
-rw-r--r--node_modules/indent-string/index.js16
1 files changed, 10 insertions, 6 deletions
diff --git a/node_modules/indent-string/index.js b/node_modules/indent-string/index.js
index b6ab264ae..a48199ca5 100644
--- a/node_modules/indent-string/index.js
+++ b/node_modules/indent-string/index.js
@@ -1,6 +1,8 @@
'use strict';
-module.exports = (str, count, indent) => {
- indent = indent === undefined ? ' ' : indent;
+module.exports = (str, count, opts) => {
+ // Support older versions: use the third parameter as options.indent
+ // TODO: Remove the workaround in the next major version
+ const options = typeof opts === 'object' ? Object.assign({indent: ' '}, opts) : {indent: opts || ' '};
count = count === undefined ? 1 : count;
if (typeof str !== 'string') {
@@ -11,13 +13,15 @@ module.exports = (str, count, indent) => {
throw new TypeError(`Expected \`count\` to be a \`number\`, got \`${typeof count}\``);
}
- if (typeof indent !== 'string') {
- throw new TypeError(`Expected \`indent\` to be a \`string\`, got \`${typeof indent}\``);
+ if (typeof options.indent !== 'string') {
+ throw new TypeError(`Expected \`options.indent\` to be a \`string\`, got \`${typeof options.indent}\``);
}
if (count === 0) {
return str;
}
- return str.replace(/^(?!\s*$)/mg, indent.repeat(count));
-};
+ const regex = options.includeEmptyLines ? /^/mg : /^(?!\s*$)/mg;
+ return str.replace(regex, options.indent.repeat(count));
+}
+;