[Pkg-javascript-commits] [node-indent-string] 01/07: Import Upstream version 3.0.0

Sarath M S sarathms-guest at moszumanska.debian.org
Tue Nov 1 18:15:04 UTC 2016


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

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

commit 00122964d3cc2bd819702fc1fe65ee1d2c1a7ec9
Author: Sarath M S <debian at sarathms.me>
Date:   Fri Oct 28 10:24:08 2016 +0530

    Import Upstream version 3.0.0
---
 .editorconfig  | 12 ++++++++++++
 .gitattributes |  1 +
 .gitignore     |  1 +
 .travis.yml    |  5 +++++
 index.js       | 27 ++++++++++++++++++++++++++
 license        | 21 ++++++++++++++++++++
 package.json   | 40 ++++++++++++++++++++++++++++++++++++++
 readme.md      | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 test.js        | 34 ++++++++++++++++++++++++++++++++
 9 files changed, 202 insertions(+)

diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 0000000..98a761d
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,12 @@
+root = true
+
+[*]
+indent_style = tab
+end_of_line = lf
+charset = utf-8
+trim_trailing_whitespace = true
+insert_final_newline = true
+
+[{package.json,*.yml}]
+indent_style = space
+indent_size = 2
diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 0000000..176a458
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1 @@
+* text=auto
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..3c3629e
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+node_modules
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..b18bae5
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,5 @@
+sudo: false
+language: node_js
+node_js:
+  - '6'
+  - '4'
diff --git a/index.js b/index.js
new file mode 100644
index 0000000..e82c562
--- /dev/null
+++ b/index.js
@@ -0,0 +1,27 @@
+'use strict';
+const repeating = require('repeating');
+
+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 (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) {
+		return str;
+	}
+
+	indent = count > 1 ? repeating(count, indent) : indent;
+
+	return str.replace(/^(?!\s*$)/mg, indent);
+};
diff --git a/license b/license
new file mode 100644
index 0000000..654d0bf
--- /dev/null
+++ b/license
@@ -0,0 +1,21 @@
+The MIT License (MIT)
+
+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:
+
+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.
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..d8e44cc
--- /dev/null
+++ b/package.json
@@ -0,0 +1,40 @@
+{
+  "name": "indent-string",
+  "version": "3.0.0",
+  "description": "Indent each line in a string",
+  "license": "MIT",
+  "repository": "sindresorhus/indent-string",
+  "author": {
+    "name": "Sindre Sorhus",
+    "email": "sindresorhus at gmail.com",
+    "url": "sindresorhus.com"
+  },
+  "engines": {
+    "node": ">=4"
+  },
+  "scripts": {
+    "test": "xo && ava"
+  },
+  "files": [
+    "index.js"
+  ],
+  "keywords": [
+    "indent",
+    "string",
+    "str",
+    "pad",
+    "align",
+    "line",
+    "text"
+  ],
+  "dependencies": {
+    "repeating": "^3.0.0"
+  },
+  "devDependencies": {
+    "ava": "*",
+    "xo": "*"
+  },
+  "xo": {
+    "esnext": true
+  }
+}
diff --git a/readme.md b/readme.md
new file mode 100644
index 0000000..bc47456
--- /dev/null
+++ b/readme.md
@@ -0,0 +1,61 @@
+# indent-string [![Build Status](https://travis-ci.org/sindresorhus/indent-string.svg?branch=master)](https://travis-ci.org/sindresorhus/indent-string)
+
+> Indent each line in a string
+
+
+## Install
+
+```
+$ npm install --save indent-string
+```
+
+
+## Usage
+
+```js
+const indentString = require('indent-string');
+
+indentString('Unicorns\nRainbows', 4);
+//=> '    Unicorns'
+//=> '    Rainbows'
+
+indentString('Unicorns\nRainbows', 4, '♥');
+//=> '♥♥♥♥Unicorns'
+//=> '♥♥♥♥Rainbows'
+```
+
+
+## API
+
+### indentString(input, [count], [indent])
+
+#### input
+
+Type: `string`
+
+String you want to indent.
+
+#### count
+
+Type: `number`<br>
+Default: `1`
+
+How many times you want `indent` repeated.
+
+#### indent
+
+Type: `string`<br>
+Default: `' '`
+
+String to use for the indent.
+
+
+## Related
+
+- [indent-string-cli](https://github.com/sindresorhus/indent-string-cli) - CLI for this module
+- [strip-indent](https://github.com/sindresorhus/strip-indent) - Strip leading whitespace from every line in a string
+
+
+## License
+
+MIT © [Sindre Sorhus](https://sindresorhus.com)
diff --git a/test.js b/test.js
new file mode 100644
index 0000000..2e4e238
--- /dev/null
+++ b/test.js
@@ -0,0 +1,34 @@
+import test from 'ava';
+import m from './';
+
+test('throw if input is not a string', t => {
+	t.throws(() => m(5), 'Expected `input` to be a `string`, got `number`');
+	t.throws(() => m(true), 'Expected `input` to be a `string`, got `boolean`');
+});
+
+test('throw if count is not a number', t => {
+	t.throws(() => m('foo', 'bar'), 'Expected `count` to be a `number`, got `string`');
+});
+
+test('throw if indent is not a string', t => {
+	t.throws(() => m('foo', 1, 1), 'Expected `indent` to be a `string`, got `number`');
+});
+
+test('indent each line in a string', t => {
+	t.is(m('foo\nbar'), ' foo\n bar');
+	t.is(m('foo\nbar', 1), ' foo\n bar');
+	t.is(m('foo\r\nbar', 1), ' foo\r\n bar');
+	t.is(m('foo\nbar', 4), '    foo\n    bar');
+});
+
+test('not indent whitespace only lines', t => {
+	t.is(m('foo\nbar\n', 1), ' foo\n bar\n');
+});
+
+test('indent with leading whitespace', t => {
+	t.is(m(' foo\n bar\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