# multi-avatar

> Package to fetch user avatars from various social-sites

Latest version **0.1.8** (published 2016-11-02) · MIT license · 0 weekly downloads

## Install

```sh
npm install multi-avatar
pnpm add multi-avatar
yarn add multi-avatar
bun add multi-avatar
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.8 |
| Published | 2016-11-02 |
| First published | 2016-06-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Maxim Kurbatov |
| Maintainers | maksimkurb |
| Keywords | avatar, promise, facebook, vk, twitter, g+ |

## Links

- npm: https://www.npmjs.com/package/multi-avatar
- Repository: https://github.com/maksimkurb/multi-avatar
- Homepage: https://github.com/maksimkurb/multi-avatar#readme
- Issues: https://github.com/maksimkurb/multi-avatar/issues
- npm.io page: https://npm.io/package/multi-avatar

## Dependencies (2)

- [node-fetch](https://npm.io/package/node-fetch.md) ^1.5.3
- [any-promise](https://npm.io/package/any-promise.md) ^1.3.0

## Alternatives

- [lodash.startswith](https://npm.io/package/lodash.startswith.md) — 769.7K weekly downloads
- [@tarojs/service](https://npm.io/package/@tarojs/service.md) — 33.9K weekly downloads
- [io.extendreality.tilia.indicators.spatialtargets.unity](https://npm.io/package/io.extendreality.tilia.indicators.spatialtargets.unity.md) — 131 weekly downloads
- [@rtarojs/taro](https://npm.io/package/@rtarojs/taro.md) — 90 weekly downloads
- [node-branch-io](https://npm.io/package/node-branch-io.md) — 50 weekly downloads

## Recent versions

- 0.1.8 (latest) — 2016-11-02
- 0.1.7 — 2016-06-02
- 0.1.6 — 2016-06-01
- 0.1.5 — 2016-06-01
- 0.1.4 — 2016-06-01
- 0.1.3 — 2016-06-01
- 0.1.2 — 2016-06-01
- 0.1.1 — 2016-06-01
- 0.1.0 — 2016-06-01

## README

# MultiAvatar - a nice way to fetch avatars
[![Build Status](https://img.shields.io/travis/maksimkurb/multi-avatar/master.svg?maxAge=2592000&style=flat-square)](https://travis-ci.org/maksimkurb/multi-avatar)
[![GitHub issues](https://img.shields.io/github/issues/maksimkurb/multi-avatar.svg?maxAge=2592000&style=flat-square)](https://github.com/maksimkurb/multi-avatar/issues)
[![David](https://img.shields.io/david/maksimkurb/multi-avatar.svg?maxAge=2592000&style=flat-square)](https://david-dm.org/maksimkurb/multi-avatar#info=dependencies)
[![David](https://img.shields.io/david/dev/maksimkurb/multi-avatar.svg?maxAge=2592000&style=flat-square)](https://david-dm.org/maksimkurb/multi-avatar#info=devDependencies)
[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg?maxAge=2592000&style=flat-square)](https://raw.githubusercontent.com/maksimkurb/multi-avatar/master/LICENSE)
___

This library allows you to get user avatar URLs from various social-networks without diving into their APIs.

### Supported providers
* Facebook
```js
  new FacebookAvatarProvider('FacebookUserID')
```
* Google
```js
  new GoogleAvatarProvider('GoogleUserID')
```
* Twitter
```js
  new TwitterAvatarProvider('TwitterUsername') // without '@', e.g. 'IGN' or 'pcgamer'
```
* Vkontakte
```js
  new VkAvatarProvider('VkID')
```

## Installation
```
npm install multi-avatar
```

## How to fetch user avatar URL
Some services forces us to make a API-requests. This is why library uses Promises ([any-promise](https://github.com/kevinbeaty/any-promise)) and URLs caching.
_(Caching works only if you use the same instance of AvatarProvider between avatar requests)_

```js
import multiAvatar, { FacebookAvatarProvider, GoogleAvatarProvider } from 'multi-avatar'; // ES7
// or
var multiAvatar = require('multi-avatar'),
  FacebookAvatarProvider = multiAvatar.FacebookAvatarProvider,
  GoogleAvatarProvider = multiAvatar.GoogleAvatarProvider;


// Basic using:
multiAvatar(new FacebookAvatarProvider('100008343750912')) // ID should be always a string, because it can be larger, than Number.MAX_VALUE
  .withSize(64)
  .then(function (avatars) {
    console.log('URL:', avatars.facebook); // URL: https://graph.facebook.com/.../picture?width=64
  });


// Fetching multiple avatars from different providers
multiAvatar([
  new FacebookAvatarProvider('100008343750912'),
  new GoogleAvatarProvider('116933859726289749306')
])
  .withSize(512)
  .then(function (avatars) {
    console.log(avatars);
    // Output:
    // {
    //   facebook: 'https://graph.facebook.com/100008343750912/picture?width=512',
    //   google: 'https://lh3.googleusercontent.com/-t4mT2nC4NkI/AAAAAAAAAAI/AAAAAAAAAAA/4DSxgN3cZmY/s512-c/116933859726289749306.jpg'
    // }
  });


// Fetching several sizes of avatar
multiAvatar([
  new FacebookAvatarProvider('100008343750912')
])
  .withSizes([64, 120]) // Note "s" at the end
  .then(function (avatars) {
    console.log(avatars);
    // Output:
    // {
    //   facebook: {
    //      '64': 'https://graph.facebook.com/100008343750912/picture?width=64',
    //      '120': 'https://graph.facebook.com/100008343750912/picture?width=120'
    //   }
    // }
  });


// Fetching several sizes of avatar from several providers
multiAvatar([
  new FacebookAvatarProvider('100008343750912'),
  new GoogleAvatarProvider('116933859726289749306')
])
  .withSizes([50, 150])
  .then(function (avatars) {
    console.log(avatars);
    // Output:
    // {
    //   facebook: {
    //     '50': 'https://graph.facebook.com/100008343750912/picture?width=50',
    //     '150': 'https://graph.facebook.com/100008343750912/picture?width=150'
    //   },
    //   google: {
    //     '50': 'https://lh3.googleusercontent.com/-t4mT2nC4NkI/AAAAAAAAAAI/AAAAAAAAAAA/4DSxgN3cZmY/s50-c/116933859726289749306.jpg',
    //     '150': 'https://lh3.googleusercontent.com/-t4mT2nC4NkI/AAAAAAAAAAI/AAAAAAAAAAA/4DSxgN3cZmY/s150-c/116933859726289749306.jpg'
    //   }
    // }
  });

  // Error handling:
  multiAvatar(new GoogleAvatarProvider('non_exists_user'))
    .withSize(64)
    .then(function (avatars) {
      console.log(avatars);
      // {
      //   google: null
      // }
    });

```
__NOTE__: *only google and vk can return null, because they
depends on JSON-request, so we can determine,
that user is not exists. Other providers just return
broken image or something like that.*

## Contribute
1. Fork it!
2. Create new branch: `git checkout -b my-new-feature`
3. Commit changes: `git commit -m 'Add new feature'`
4. Push it: `git push origin my-new-feature`
5. Submit a pull request!

---
_Source: https://npm.io/package/multi-avatar · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
