indent-string
Advanced tools
Comparing version 2.1.0 to 3.0.0
21
index.js
'use strict'; | ||
var repeating = require('repeating'); | ||
const repeating = require('repeating'); | ||
module.exports = function (str, indent, count) { | ||
if (typeof str !== 'string' || typeof indent !== 'string') { | ||
throw new TypeError('`string` and `indent` should be strings'); | ||
module.exports = (str, count, indent) => { | ||
indent = indent === undefined ? ' ' : indent; | ||
count = count === undefined ? 1 : count; | ||
if (typeof str !== 'string') { | ||
throw new TypeError(`Expected \`input\` to be a \`string\`, got \`${typeof str}\``); | ||
} | ||
if (count != null && typeof count !== 'number') { | ||
throw new TypeError('`count` should be a number'); | ||
if (typeof count !== 'number') { | ||
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 (count === 0) { | ||
@@ -17,5 +24,5 @@ return str; | ||
indent = count > 1 ? repeating(indent, count) : indent; | ||
indent = count > 1 ? repeating(count, indent) : indent; | ||
return str.replace(/^(?!\s*$)/mg, indent); | ||
}; |
{ | ||
"name": "indent-string", | ||
"version": "2.1.0", | ||
"version": "3.0.0", | ||
"description": "Indent each line in a string", | ||
@@ -13,6 +13,6 @@ "license": "MIT", | ||
"engines": { | ||
"node": ">=0.10.0" | ||
"node": ">=4" | ||
}, | ||
"scripts": { | ||
"test": "mocha" | ||
"test": "xo && ava" | ||
}, | ||
@@ -32,7 +32,11 @@ "files": [ | ||
"dependencies": { | ||
"repeating": "^2.0.0" | ||
"repeating": "^3.0.0" | ||
}, | ||
"devDependencies": { | ||
"mocha": "*" | ||
"ava": "*", | ||
"xo": "*" | ||
}, | ||
"xo": { | ||
"esnext": true | ||
} | ||
} |
@@ -16,7 +16,11 @@ # indent-string [![Build Status](https://travis-ci.org/sindresorhus/indent-string.svg?branch=master)](https://travis-ci.org/sindresorhus/indent-string) | ||
```js | ||
var indentString = require('indent-string'); | ||
const indentString = require('indent-string'); | ||
indentString('Unicorns\nRainbows', '♥', 4); | ||
//=> ♥♥♥♥Unicorns | ||
//=> ♥♥♥♥Rainbows | ||
indentString('Unicorns\nRainbows', 4); | ||
//=> ' Unicorns' | ||
//=> ' Rainbows' | ||
indentString('Unicorns\nRainbows', 4, '♥'); | ||
//=> '♥♥♥♥Unicorns' | ||
//=> '♥♥♥♥Rainbows' | ||
``` | ||
@@ -27,21 +31,13 @@ | ||
### indentString(string, indent, count) | ||
### indentString(input, [count], [indent]) | ||
#### string | ||
#### input | ||
**Required** | ||
Type: `string` | ||
The string you want to indent. | ||
String you want to indent. | ||
#### indent | ||
**Required** | ||
Type: `string` | ||
The string to use for the indent. | ||
#### count | ||
Type: `number` | ||
Type: `number`<br> | ||
Default: `1` | ||
@@ -51,3 +47,10 @@ | ||
#### indent | ||
Type: `string`<br> | ||
Default: `' '` | ||
String to use for the indent. | ||
## Related | ||
@@ -61,2 +64,2 @@ | ||
MIT © [Sindre Sorhus](http://sindresorhus.com) | ||
MIT © [Sindre Sorhus](https://sindresorhus.com) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3539
20
62
2
+ Addedrepeating@3.0.0(transitive)
- Removedis-finite@1.1.0(transitive)
- Removedrepeating@2.0.1(transitive)
Updatedrepeating@^3.0.0