New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

format-people

Package Overview
Dependencies
Maintainers
2
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

format-people - npm Package Compare versions

Comparing version 0.1.4 to 1.0.0

158

index.js
'use strict';
var extend = require('extend-shallow');
var formatters = require('./lib/formatters');
/**

@@ -11,24 +8,153 @@ * Format a list of people like objects (e.g. authors, contributors, and collaborators)

* ```js
* var people = [
* { name: 'Brian Woodward' }
* ];
* var table = format(people, {format: 'table'});
* const people = [ { name: 'Brian Woodward' } ];
* const table = format(people, 'table');
* console.log(table);
* ```
* @param {Array} `arr` Array of people objects.
* @param {Object} `options` Additional options
* @param {String} `options.format` Formatter function used to format the array. See [formatters](#formatters) for more details.
* @return {Mixed} Formatted array of people. Returned type depends on formatter.
* @param {Array} `arr` Array of people objects.
* @param {String} `format` The format "type" to use. Valid types are `table`, `list` and `aligned`. If no type is passed, `table` will be used automatically.
* @return {String} Formatted
* @api public
*/
module.exports = function format(arr, options) {
var opts = extend({format: 'noop'}, options);
return formatters[opts.format](arr);
const format = (arr, name) => {
return format[name] ? format[name](arr) : format.table(arr);
};
/**
* Expose formatters object.
* Returns the array of people formatted as a markdown table.
*
* ```js
* const people = [
* { login: 'doowb', contributions: 100, html_url: 'https://github.com/doowb' },
* { login: 'jonschlinkert', contributions: 50, html_url: 'https://github.com/jonschlinkert' }
* ];
* console.log(format.table(people));
* //=> | **Commits** | **Contributor**<br/> |
* //=> | --- | --- |
* //=> | 100 | [doowb](https://github.com/doowb) |
* //=> | 50 | [jonschlinkert](https://github.com/jonschlinkert) |
* ```
* @param {Array} `arr` Array of people to format.
* @return {String} Markdown table
* @api public
*/
module.exports.formatters = formatters;
format.table = list => {
let arr = [].concat(list || []);
if (arr.length === 0) {
return '';
}
let max = longest(arr, 'contributions');
let res = '| **Commits** | **Contributor** | ';
res += '\n';
res += '| --- | --- | ';
res += '\n';
arr.forEach(person => {
res += '| ';
res += String(person.contributions || '').padEnd(max, ' ');
res += ' | ';
res += link(person.login, person.html_url);
res += ' | ';
res += '\n';
});
return res;
};
/**
* Returns the array of people formatted as a markdown list.
*
* ```js
* const people = [
* { login: 'doowb', contributions: 100, html_url: 'https://github.com/doowb' },
* { login: 'jonschlinkert', contributions: 50, html_url: 'https://github.com/jonschlinkert' }
* ];
* console.log(format.list(people));
* //=> **Commits** / **Contributor**
* //=> + 100 [doowb](https://github.com/doowb)
* //=> + 50 [jonschlinkert](https://github.com/jonschlinkert)
* ```
* @param {Array} `arr` Array of people to format.
* @return {String} Markdown list
* @api public
*/
format.list = list => {
let arr = [].concat(list || []);
if (arr.length === 0) {
return '';
}
let max = longest(arr, 'contributions');
let res = '**Commits** / **Contributor**\n';
arr.forEach(person => {
res += '+ ';
res += String(person.contributions || '').padEnd(max, ' ');
res += ' ';
res += link(person.login, person.html_url);
res += '\n';
});
return res;
};
/**
* Returns the array of people formatted as a GitHub Flavored Markdown fenced code block,
* with aligned columns.
*
* ```js
* const people = [
* { login: 'doowb', contributions: 100, html_url: 'https://github.com/doowb' },
* { login: 'jonschlinkert', contributions: 50, html_url: 'https://github.com/jonschlinkert' }
* ];
* console.log(format.aligned(people));
* //=> COMMITS / CONTRIBUTOR
* //=> ------- | -----------
* //=> 100 doowb
* //=> 50 jonschlinkert
* ```
* @param {Array} `arr` Array of people to format.
* @return {String} Markdown code block with aligned columns.
* @api public
*/
format.aligned = list => {
let arr = [].concat(list || []);
if (arr.length === 0) {
return '';
}
let max = longest(arr, 'contributions');
let res = '```bash\n';
res += 'COMMITS / CONTRIBUTOR\n';
res += '------- | -----------\n';
arr.forEach(person => {
res += String(person.contributions || '').padEnd(max, ' ');
res += ' ';
res += person.login;
res += '\n';
});
res += '```\n';
return res;
};
function longest(arr, prop) {
return arr.reduce((n, c) => Math.max((c[prop] + '').length, n), 0);
}
function link(anchor, href, title) {
return anchor && href ? `[${anchor}](${href}${title ? ` "${title}"` : ''})` : '';
}
/**
* Expose format
*/
module.exports = format;

13

package.json
{
"name": "format-people",
"description": "Format a list of authors, contributors, or collaborators.",
"version": "0.1.4",
"version": "1.0.0",
"homepage": "https://github.com/doowb/format-people",

@@ -18,3 +18,3 @@ "author": "Brian Woodward (https://github.com/doowb)",

"engines": {
"node": ">=0.10.0"
"node": ">=4.0"
},

@@ -24,10 +24,5 @@ "scripts": {

},
"dependencies": {
"extend-shallow": "^2.0.1",
"markdown-utils": "^0.7.3",
"right-pad-values": "^0.3.1"
},
"devDependencies": {
"gulp-format-md": "^0.1.10",
"mocha": "^3.0.2"
"gulp-format-md": "^1.0.0",
"mocha": "^3.5.3"
},

@@ -34,0 +29,0 @@ "keywords": [

@@ -1,5 +0,7 @@

# format-people [![NPM version](https://img.shields.io/npm/v/format-people.svg?style=flat)](https://www.npmjs.com/package/format-people) [![NPM downloads](https://img.shields.io/npm/dm/format-people.svg?style=flat)](https://npmjs.org/package/format-people) [![Build Status](https://img.shields.io/travis/doowb/format-people.svg?style=flat)](https://travis-ci.org/doowb/format-people)
# format-people [![NPM version](https://img.shields.io/npm/v/format-people.svg?style=flat)](https://www.npmjs.com/package/format-people) [![NPM monthly downloads](https://img.shields.io/npm/dm/format-people.svg?style=flat)](https://npmjs.org/package/format-people) [![NPM total downloads](https://img.shields.io/npm/dt/format-people.svg?style=flat)](https://npmjs.org/package/format-people) [![Linux Build Status](https://img.shields.io/travis/doowb/format-people.svg?style=flat&label=Travis)](https://travis-ci.org/doowb/format-people)
> Format a list of authors, contributors, or collaborators.
Please consider following this project's author, [Brian Woodward](https://github.com/doowb), and consider starring the project to show your :heart: and support.
## Install

@@ -16,3 +18,3 @@

```js
var format = require('format-people');
const format = require('format-people');
```

@@ -22,12 +24,7 @@

### [format](index.js#L24)
Format a list of people like objects (e.g. authors, contributors, and collaborators) into the specified format.
**Params**
* `arr` **{Array}**: Array of people objects.
* `options` **{Object}**: Additional options
* `options.format` **{String}**: Formatter function used to format the array. See [formatters](#formatters) for more details.
* `returns` **{Mixed}**: Formatted array of people. Returned type depends on formatter.
* `format` **{String}**: The format "type" to use. Valid types are `table`, `list` and `aligned`. If no type is passed, `table` will be used automatically.
* `returns` **{String}**: Formatted

@@ -37,33 +34,9 @@ **Example**

```js
var people = [
{ name: 'Brian Woodward' }
];
var table = format(people, {format: 'table'});
const people = [ { name: 'Brian Woodward' } ];
const table = format(people, 'table');
console.log(table);
```
## Formatters
### [.table](index.js#L41)
### [.noop](lib/formatters.js#L24)
Returns the array as-is without any formatting.
**Params**
* `arr` **{Array}**: Array of people to format.
* `returns` **{Array}**: Unmodified array of people.
**Example**
```js
var people = [
{ login: 'doowb' }
];
var formatted = formatters.noop(people);
console.log(formatted);
//=> [{login: 'doowb'}]
```
### [.table](lib/formatters.js#L48)
Returns the array of people formatted as a markdown table.

@@ -79,8 +52,7 @@

```js
var people = [
const people = [
{ login: 'doowb', contributions: 100, html_url: 'https://github.com/doowb' },
{ login: 'jonschlinkert', contributions: 50, html_url: 'https://github.com/jonschlinkert' }
];
var formatted = formatters.table(people);
console.log(formatted);
console.log(format.table(people));
//=> | **Commits** | **Contributor**<br/> |

@@ -92,3 +64,3 @@ //=> | --- | --- |

### [.list](lib/formatters.js#L89)
### [.list](index.js#L84)

@@ -105,8 +77,7 @@ Returns the array of people formatted as a markdown list.

```js
var people = [
const people = [
{ login: 'doowb', contributions: 100, html_url: 'https://github.com/doowb' },
{ login: 'jonschlinkert', contributions: 50, html_url: 'https://github.com/jonschlinkert' }
];
var formatted = formatters.list(people);
console.log(formatted);
console.log(format.list(people));
//=> **Commits** / **Contributor**

@@ -117,5 +88,5 @@ //=> + 100 [doowb](https://github.com/doowb)

### [.aligned](lib/formatters.js#L127)
### [.aligned](index.js#L124)
Returns the array of people formatted as an aligned code block.
Returns the array of people formatted as a GitHub Flavored Markdown fenced code block, with aligned columns.

@@ -125,3 +96,3 @@ **Params**

* `arr` **{Array}**: Array of people to format.
* `returns` **{String}**: Markdown code block for alignment
* `returns` **{String}**: Markdown code block with aligned columns.

@@ -131,8 +102,7 @@ **Example**

```js
var people = [
const people = [
{ login: 'doowb', contributions: 100, html_url: 'https://github.com/doowb' },
{ login: 'jonschlinkert', contributions: 50, html_url: 'https://github.com/jonschlinkert' }
];
var formatted = formatters.aligned(people);
console.log(formatted);
console.log(format.aligned(people));
//=> COMMITS / CONTRIBUTOR

@@ -146,31 +116,49 @@ //=> ------- | -----------

### Related projects
<details>
<summary><strong>Contributing</strong></summary>
* [github-base](https://www.npmjs.com/package/github-base): JavaScript wrapper that greatly simplifies working with GitHub's API. | [homepage](https://github.com/jonschlinkert/github-base "JavaScript wrapper that greatly simplifies working with GitHub's API.")
* [github-contributors](https://www.npmjs.com/package/github-contributors): Generate a markdown or JSON list of contributors for a project using the GitHub API. | [homepage](https://github.com/jonschlinkert/github-contributors "Generate a markdown or JSON list of contributors for a project using the GitHub API.")
### Contributing
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
Please read the [contributing guide](.github/contributing.md) for avice on opening issues, pull requests, and coding standards.
Please read the [contributing guide](.github/contributing.md) for advice on opening issues, pull requests, and coding standards.
### Building docs
</details>
_(This document was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme) (a [verb](https://github.com/verbose/verb) generator), please don't edit the readme directly. Any changes to the readme must be made in [.verb.md](.verb.md).)_
<details>
<summary><strong>Running Tests</strong></summary>
To generate the readme and API documentation with [verb](https://github.com/verbose/verb):
Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
```sh
$ npm install -g verb verb-generate-readme && verb
$ npm install && npm test
```
### Running tests
</details>
Install dev dependencies:
<details>
<summary><strong>Building docs</strong></summary>
_(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_
To generate the readme, run the following command:
```sh
$ npm install -d && npm test
$ npm install -g verbose/verb#dev verb-generate-readme && verb
```
</details>
### Related projects
You might also be interested in these projects:
* [github-base](https://www.npmjs.com/package/github-base): Low-level methods for working with the GitHub API in node.js/JavaScript. | [homepage](https://github.com/jonschlinkert/github-base "Low-level methods for working with the GitHub API in node.js/JavaScript.")
* [github-contributors](https://www.npmjs.com/package/github-contributors): Generate a markdown or JSON list of contributors for a project using the GitHub API. | [homepage](https://github.com/jonschlinkert/github-contributors "Generate a markdown or JSON list of contributors for a project using the GitHub API.")
### Contributors
| **Commits** | **Contributor** |
| --- | --- |
| 11 | [doowb](https://github.com/doowb) |
| 8 | [jonschlinkert](https://github.com/jonschlinkert) |
### Author

@@ -180,12 +168,13 @@

* [github/doowb](https://github.com/doowb)
* [twitter/doowb](http://twitter.com/doowb)
* [GitHub Profile](https://github.com/doowb)
* [Twitter Profile](https://twitter.com/doowb)
* [LinkedIn Profile](https://linkedin.com/in/jonschlinkert)
### License
Copyright © 2016, [Brian Woodward](https://github.com/doowb).
Released under the [MIT license](https://github.com/doowb/format-people/blob/master/LICENSE).
Copyright © 2018, [Brian Woodward](https://github.com/doowb).
Released under the [MIT License](LICENSE).
***
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.1.31, on September 21, 2016._
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on August 14, 2018._

Sorry, the diff of this file is not supported yet

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