Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

align-text

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

align-text - npm Package Compare versions

Comparing version 0.1.1 to 0.1.2

17

index.js

@@ -20,3 +20,3 @@ /*!

} else if (type === 'string') {
lines = val.split(/[\r\n]/);
lines = val.split(/(?:\r\n|\n)/);
} else {

@@ -26,2 +26,3 @@ throw new TypeError('align-text expects a string or array.');

var fnType = typeOf(fn);
var len = lines.length;

@@ -32,7 +33,13 @@ var max = longest(lines);

while (len--) {
var line = lines[i++];
var diff = typeof fn === 'function'
? fn(line.length, max.length, line, lines, i)
: typeof fn === 'number' ? fn : 0;
var line = String(lines[i++]);
var diff;
if (fnType === 'function') {
diff = fn(line.length, max.length, line, lines, i);
} else if (fnType === 'number') {
diff = fn;
} else {
diff = max.length - line.length;
}
if (typeOf(diff) === 'number') {

@@ -39,0 +46,0 @@ res.push(repeat(' ', diff) + line);

{
"name": "align-text",
"description": "Align the text in a string.",
"version": "0.1.1",
"version": "0.1.2",
"homepage": "https://github.com/jonschlinkert/align-text",

@@ -17,6 +17,3 @@ "author": {

},
"license": {
"type": "MIT",
"url": "https://github.com/jonschlinkert/align-text/blob/master/LICENSE"
},
"license": "MIT",
"files": [

@@ -33,9 +30,10 @@ "index.js"

"dependencies": {
"kind-of": "^1.1.0",
"longest": "^1.0.0",
"repeat-string": "^1.5.0"
"kind-of": "^2.0.0",
"longest": "^1.0.1",
"repeat-string": "^1.5.2"
},
"devDependencies": {
"mocha": "*",
"should": "*"
"should": "*",
"word-wrap": "^1.0.3"
},

@@ -42,0 +40,0 @@ "keywords": [

@@ -1,11 +0,28 @@

# align-text [![NPM version](https://badge.fury.io/js/align-text.svg)](http://badge.fury.io/js/align-text) [![Build Status](https://travis-ci.org/jonschlinkert/align-text.svg)](https://travis-ci.org/jonschlinkert/align-text)
# align-text [![NPM version](https://badge.fury.io/js/align-text.svg)](http://badge.fury.io/js/align-text) [![Build Status](https://travis-ci.org/jonschlinkert/align-text.svg)](https://travis-ci.org/jonschlinkert/align-text)
> Align the text in a string.
## Install with [npm](npmjs.org)
**Examples**
```bash
npm i align-text --save
Align text values in an array:
```js
align([1, 2, 3, 100]);
//=> [' 1', ' 2', ' 3', '100']
```
Or [do stuff like this](./example.js):
[![screen shot 2015-06-09 at 2 08 34 am](https://cloud.githubusercontent.com/assets/383994/8051597/7b716fbc-0e4c-11e5-9aef-4493fd22db58.png)](./example.js)
Visit [the example](./example.js) to see how this works.
## Install
Install with [npm](https://www.npmjs.com/)
```sh
$ npm i align-text --save
```
## Usage

@@ -15,3 +32,2 @@

var align = require('align-text');
align(text, callback_function_or_integer);

@@ -22,4 +38,4 @@ ```

- `text` can be a **string or array**. If a string is passed, a string will be returned. If an array is passed, an array will be returned.
- `callback|integer`: if an integer, the text will be indented by that amount. If a function, it must return an integer representing the amount of leading indentation to use as `align` loops over each line.
* `text` can be a **string or array**. If a string is passed, a string will be returned. If an array is passed, an array will be returned.
* `callback|integer`: if an integer, the text will be indented by that amount. If a function, it must return an integer representing the amount of leading indentation to use as `align` loops over each line.

@@ -39,2 +55,3 @@ **Example**

```
To:

@@ -54,6 +71,6 @@

- `len` the length of the "current" line
- `longest` the length of the longest line
- `line` the current line (string) being aligned
- `lines` the array of all lines
* `len` the length of the "current" line
* `longest` the length of the longest line
* `line` the current line (string) being aligned
* `lines` the array of all lines

@@ -64,9 +81,8 @@ ### return

- an integer that represents the number of spaces to use for padding,
- or an object with the following properties:
+ `indent`: **{Number}** the amount of indentation to use. Default is `0` when an object is returned.
+ `character`: **{String}** the character to use for indentation. Default is `''` (empty string) when an object is returned.
+ `prefix`: **{String}** leading characters to use at the beginning of each line. `''` (empty string) when an object is returned.
* an integer that represents the number of spaces to use for padding,
* or an object with the following properties:
- `indent`: **{Number}** the amount of indentation to use. Default is `0` when an object is returned.
- `character`: **{String}** the character to use for indentation. Default is `''` (empty string) when an object is returned.
- `prefix`: **{String}** leading characters to use at the beginning of each line. `''` (empty string) when an object is returned.
**Integer example:**

@@ -81,2 +97,3 @@

```
**Object example:**

@@ -94,3 +111,2 @@

## Usage examples

@@ -158,2 +174,3 @@

```
Would return:

@@ -180,2 +197,3 @@

```
Would return

@@ -192,20 +210,22 @@

## Related projects
## Related projects
* [right-align](https://github.com/jonschlinkert/right-align): Right-align the text in a string.
* [center-align](https://github.com/jonschlinkert/center-align): Center-align the text in a string.
* [justify](https://github.com/bahamas10/node-justify): Left or right (or both) justify text using a custom width and character
* [word-wrap](https://github.com/jonschlinkert/word-wrap): Wrap words to a specified length.
* [longest](https://github.com/jonschlinkert/longest): Get the longest item in an array.
* [right-align](https://github.com/jonschlinkert/right-align): Right-align the text in a string.
* [repeat-string](https://github.com/jonschlinkert/repeat-string): Repeat the given string n times. Fastest implementation for repeating a string.
* [word-wrap](https://github.com/jonschlinkert/word-wrap): Wrap words to a specified length.
## Running tests
Install dev dependencies.
```bash
npm i -d && npm test
Install dev dependencies:
```sh
$ npm i -d && npm test
```
## Contributing
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/align-text/issues)
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/align-text/issues/new)

@@ -215,12 +235,13 @@ ## Author

**Jon Schlinkert**
+ [github/jonschlinkert](https://github.com/jonschlinkert)
+ [twitter/jonschlinkert](http://twitter.com/jonschlinkert)
+ [twitter/jonschlinkert](http://twitter.com/jonschlinkert)
## License
Copyright (c) 2015 Jon Schlinkert
Released under the MIT license
Copyright © 2015 Jon Schlinkert
Released under the MIT license.
***
_This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on March 07, 2015._
_This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on June 09, 2015._
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc