Skip to content

Commit b1383ef

Browse files
committed
Add backward compatibility for indent-string v2 API
1 parent 2b2cb2f commit b1383ef

1 file changed

Lines changed: 23 additions & 3 deletions

File tree

packages/npm/indent-string/index.cjs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,29 @@
11
'use strict'
22

33
module.exports = function indentString(input, count = 1, options) {
4-
const { includeEmptyLines = false, indent = ' ' } = {
5-
__proto__: null,
6-
...options,
4+
let includeEmptyLines = false
5+
let indent = ' '
6+
if (
7+
// isV2: indentString(input, indent, count) - 3 args only
8+
typeof count === 'string' &&
9+
typeof options === 'number'
10+
) {
11+
indent = count
12+
count = options
13+
} else if (
14+
// isV3: indentString(input, count, indent)
15+
typeof count === 'number' &&
16+
typeof options === 'string'
17+
) {
18+
indent = options
19+
} else if (options !== null && typeof options === 'object') {
20+
const opts = { __proto__: null, ...options }
21+
if (opts.includeEmptyLines !== undefined) {
22+
includeEmptyLines = opts.includeEmptyLines
23+
}
24+
if (opts.indent !== undefined) {
25+
indent = opts.indent
26+
}
727
}
828
if (typeof input !== 'string') {
929
throw new TypeError(

0 commit comments

Comments
 (0)