[Pkg-javascript-commits] [node-indent-string] 01/04: New upstream version 3.2.0

Praveen Arimbrathodiyil praveen at moszumanska.debian.org
Fri Feb 9 13:46:52 UTC 2018


This is an automated email from the git hooks/post-receive script.

praveen pushed a commit to branch master
in repository node-indent-string.

commit 0e0270f14c13b42c8a0c328108879c2bf425e6e9
Author: Pirate Praveen <praveen at debian.org>
Date:   Fri Feb 9 19:07:05 2018 +0530

    New upstream version 3.2.0
---
 .editorconfig  |  2 +-
 .gitattributes |  1 +
 .gitignore     |  1 +
 .npmrc         |  1 +
 .travis.yml    |  2 +-
 index.js       | 20 ++++++++++----------
 license        | 20 ++++----------------
 package.json   | 12 ++++--------
 readme.md      | 19 +++++++++++++++----
 test.js        | 19 +++++++++++++++++--
 10 files changed, 55 insertions(+), 42 deletions(-)

diff --git a/.editorconfig b/.editorconfig
index 98a761d..1c6314a 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -7,6 +7,6 @@ charset = utf-8
 trim_trailing_whitespace = true
 insert_final_newline = true
 
-[{package.json,*.yml}]
+[*.yml]
 indent_style = space
 indent_size = 2
diff --git a/.gitattributes b/.gitattributes
index 176a458..391f0a4 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -1 +1,2 @@
 * text=auto
+*.js text eol=lf
diff --git a/.gitignore b/.gitignore
index 3c3629e..239ecff 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,2 @@
 node_modules
+yarn.lock
diff --git a/.npmrc b/.npmrc
new file mode 100644
index 0000000..43c97e7
--- /dev/null
+++ b/.npmrc
@@ -0,0 +1 @@
+package-lock=false
diff --git a/.travis.yml b/.travis.yml
index b18bae5..7d69d74 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,5 +1,5 @@
-sudo: false
 language: node_js
 node_js:
+  - '8'
   - '6'
   - '4'
diff --git a/index.js b/index.js
index e82c562..a48199c 100644
--- a/index.js
+++ b/index.js
@@ -1,8 +1,8 @@
 'use strict';
-const repeating = require('repeating');
-
-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') {
@@ -13,15 +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;
 	}
 
-	indent = count > 1 ? repeating(count, indent) : indent;
-
-	return str.replace(/^(?!\s*$)/mg, indent);
-};
+	const regex = options.includeEmptyLines ? /^/mg : /^(?!\s*$)/mg;
+	return str.replace(regex, options.indent.repeat(count));
+}
+;
diff --git a/license b/license
index 654d0bf..e7af2f7 100644
--- a/license
+++ b/license
@@ -1,21 +1,9 @@
-The MIT License (MIT)
+MIT License
 
 Copyright (c) Sindre Sorhus <sindresorhus at gmail.com> (sindresorhus.com)
 
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
 
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
 
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/package.json b/package.json
index d8e44cc..e2a938b 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
   "name": "indent-string",
-  "version": "3.0.0",
+  "version": "3.2.0",
   "description": "Indent each line in a string",
   "license": "MIT",
   "repository": "sindresorhus/indent-string",
@@ -25,16 +25,12 @@
     "pad",
     "align",
     "line",
-    "text"
+    "text",
+    "each",
+    "every"
   ],
-  "dependencies": {
-    "repeating": "^3.0.0"
-  },
   "devDependencies": {
     "ava": "*",
     "xo": "*"
-  },
-  "xo": {
-    "esnext": true
   }
 }
diff --git a/readme.md b/readme.md
index bc47456..d2592d7 100644
--- a/readme.md
+++ b/readme.md
@@ -6,7 +6,7 @@
 ## Install
 
 ```
-$ npm install --save indent-string
+$ npm install indent-string
 ```
 
 
@@ -19,7 +19,7 @@ indentString('Unicorns\nRainbows', 4);
 //=> '    Unicorns'
 //=> '    Rainbows'
 
-indentString('Unicorns\nRainbows', 4, '♥');
+indentString('Unicorns\nRainbows', 4, {indent: '♥'});
 //=> '♥♥♥♥Unicorns'
 //=> '♥♥♥♥Rainbows'
 ```
@@ -27,7 +27,7 @@ indentString('Unicorns\nRainbows', 4, '♥');
 
 ## API
 
-### indentString(input, [count], [indent])
+### indentString(input, [count], [options])
 
 #### input
 
@@ -42,13 +42,24 @@ Default: `1`
 
 How many times you want `indent` repeated.
 
-#### indent
+#### options
+
+Type: `Object`<br>
+
+##### indent
 
 Type: `string`<br>
 Default: `' '`
 
 String to use for the indent.
 
+##### includeEmptyLines
+
+Type: `boolean`<br>
+Default: `false`
+
+Also indent empty lines.
+
 
 ## Related
 
diff --git a/test.js b/test.js
index 2e4e238..6f601a5 100644
--- a/test.js
+++ b/test.js
@@ -1,5 +1,5 @@
 import test from 'ava';
-import m from './';
+import m from '.';
 
 test('throw if input is not a string', t => {
 	t.throws(() => m(5), 'Expected `input` to be a `string`, got `number`');
@@ -11,7 +11,8 @@ test('throw if count is not a number', t => {
 });
 
 test('throw if indent is not a string', t => {
-	t.throws(() => m('foo', 1, 1), 'Expected `indent` to be a `string`, got `number`');
+	t.throws(() => m('foo', 1, 1), 'Expected `options.indent` to be a `string`, got `number`'); // Old syntax
+	t.throws(() => m('foo', 1, {indent: 1}), 'Expected `options.indent` to be a `string`, got `number`');
 });
 
 test('indent each line in a string', t => {
@@ -23,12 +24,26 @@ test('indent each line in a string', t => {
 
 test('not indent whitespace only lines', t => {
 	t.is(m('foo\nbar\n', 1), ' foo\n bar\n');
+	t.is(m('foo\nbar\n', 1, {includeEmptyLines: false}), ' foo\n bar\n');
+	t.is(m('foo\nbar\n', 1, {includeEmptyLines: null}), ' foo\n bar\n');
+});
+
+test('indent every line if options.blank is true', t => {
+	t.is(m('foo\n\nbar\n	', 1, {includeEmptyLines: true}), ' foo\n \n bar\n 	');
 });
 
 test('indent with leading whitespace', t => {
 	t.is(m(' foo\n bar\n', 1), '  foo\n  bar\n');
 });
 
+test('indent with custom string', t => {
+	t.is(m('foo\nbar\n', 1, {indent: '♥'}), '♥foo\n♥bar\n');
+});
+
+test('indent with custom string and old syntax', t => {
+	t.is(m('foo\nbar\n', 1, '#'), '#foo\n#bar\n');
+});
+
 test('not indent when count is 0', t => {
 	t.is(m('foo\nbar\n', 0), 'foo\nbar\n');
 });

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-indent-string.git



More information about the Pkg-javascript-commits mailing list