UNPKG

right-pad-values

Version:

Right pad the values of a given property for each object in an array. Useful for creating text columns or tables.

134 lines (99 loc) 3.74 kB
# right-pad-values [![NPM version](https://img.shields.io/npm/v/right-pad-values.svg)](https://www.npmjs.com/package/right-pad-values) [![Build Status](https://img.shields.io/travis/jonschlinkert/right-pad-values.svg)](https://travis-ci.org/jonschlinkert/right-pad-values) > Right pad the values of a given property for each object in an array. Useful for creating text columns or tables. - [Install](#install) - [Usage](#usage) - [API](#api) - [Related projects](#related-projects) - [Running tests](#running-tests) - [Contributing](#contributing) - [Author](#author) - [License](#license) _(TOC generated by [verb](https://github.com/verbose/verb) using [markdown-toc](https://github.com/jonschlinkert/markdown-toc))_ ## Install Install with [npm](https://www.npmjs.com/): ```sh $ npm i right-pad-values --save ``` ## Usage **object** ```js pad({ a: 'b', c: 'dddddd', e: 'fff', g: 'hhhhh' }); ``` Results in: ```js { a: 'b ', c: 'dddddd', e: 'fff ', g: 'hhhhh ', }; ``` **Specific property in object of objects** ```js pad('foo', { a: { foo: 'a', bar: 'z' }, b: { foo: 'aaaaaaa', bar: 'z' }, c: { foo: 'aaa', bar: 'z' } }); ``` Results in: ```js { a: { foo: 'a ', bar: 'z' }, b: { foo: 'aaaaaaa', bar: 'z' }, c: { foo: 'aaa ', bar: 'z' } } ``` **array of objects** Pass an array and specify the property with the value to pad: ```js var pad = require('right-pad-values'); var arr = [{a: 'b'}, {a: 'bb'}, {a: 'bbbb'}, {a: 'bbb'}, {a: 'bb'}]; pad(arr, 'a'); ``` Results in: ```js [ {a: 'b '}, {a: 'bb '}, {a: 'bbbb'}, {a: 'bbb '}, {a: 'bb '} ]; ``` ## Related projects * [longest](https://www.npmjs.com/package/longest): Get the longest item in an array. | [homepage](https://github.com/jonschlinkert/longest) * [longest-value](https://www.npmjs.com/package/longest-value): Get the longest value for the given property from an array of objects, or the… [more](https://www.npmjs.com/package/longest-value) | [homepage](https://github.com/jonschlinkert/longest-value) * [pad-left](https://www.npmjs.com/package/pad-left): Left pad a string with zeros or a specified string. Fastest implementation. | [homepage](https://github.com/jonschlinkert/pad-left) * [pad-right](https://www.npmjs.com/package/pad-right): Right pad a string with zeros or a specified string. Fastest implementation. | [homepage](https://github.com/jonschlinkert/pad-right) * [repeat-element](https://www.npmjs.com/package/repeat-element): Create an array by repeating the given value n times. | [homepage](https://github.com/jonschlinkert/repeat-element) * [repeat-string](https://www.npmjs.com/package/repeat-string): Repeat the given string n times. Fastest implementation for repeating a string. | [homepage](https://github.com/jonschlinkert/repeat-string) * [right-align-values](https://www.npmjs.com/package/right-align-values): Right align the values of a given property for each object in an array. Useful… [more](https://www.npmjs.com/package/right-align-values) | [homepage](https://github.com/jonschlinkert/right-align-values) ## Running tests 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/right-pad-values/issues/new). ## Author **Jon Schlinkert** * [github/jonschlinkert](https://github.com/jonschlinkert) * [twitter/jonschlinkert](http://twitter.com/jonschlinkert) ## License Copyright © 2015 [Jon Schlinkert](https://github.com/jonschlinkert) Released under the MIT license. *** _This file was generated by [verb](https://github.com/verbose/verb) on December 27, 2015._