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

avatar-initials

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

avatar-initials - npm Package Compare versions

Comparing version 1.0.0 to 1.2.0

.travis.yml

2

avatar.jquery.json
{
"name": "avatar",
"title": "Avatar",
"version": "1.0.0",
"version": "1.2.0",
"description": "JavaScript library for showing Gravatars or generating user avatars from initials.",

@@ -6,0 +6,0 @@ "keywords": [

{
"name": "avatar",
"main": "avatar.js",
"version": "1.0.0",
"version": "1.2.0",
"homepage": "https://github.com/MatthewCallis/avatar",

@@ -20,2 +19,6 @@ "authors": [

"license": "MIT",
"main": [
"./build/avatar.js",
"./vendor/md5.js"
],
"ignore": [

@@ -22,0 +25,0 @@ "**/.*",

@@ -0,3 +1,15 @@

## 1.2.0 (March 12, 2015)
* Added many more tests.
* Added Travis CI Integration
* Added Code Coverage
* Added GitHub Support
* Added Avatars.io Support
## 1.0.1 (March 3, 2015)
* Add main files to `main` property of `bower.json`.
## 1.0 (December 18, 2014)
* First release.

@@ -5,6 +5,6 @@ {

"description": "JavaScript library for showing Gravatars or generating user avatars from initials.",
"version": "1.0.0",
"version": "1.2.0",
"keywords": ["image", "avatar", "gravatar", "initials"],
"scripts": ["avatar.js"],
"scripts": ["./build/avatar.js"],
"license": "MIT"
}
{
"name": "avatar-initials",
"version": "1.0.0",
"version": "1.2.0",
"description": "JavaScript library for showing Gravatars or generating user avatars from initials.",

@@ -12,3 +12,6 @@ "author": "Matthew Callis <Matthew Callis>",

],
"main": "avatar.js",
"main": [
"./build/avatar.js",
"./vendor/md5.js"
],
"repository": {

@@ -24,9 +27,39 @@ "type": "git",

"gravatar",
"initials"
"initials",
"profile photo"
],
"dependencies": {},
"devDependencies": {},
"devDependencies": {
"MD5": "*",
"chai": "*",
"chai-as-promised": "*",
"codeclimate-test-reporter": "*",
"coffee-script": "*",
"coveralls": "*",
"jquery": "^2",
"jsdom": "*",
"mocha": "*",
"mocha-istanbul": "*",
"mocha-jsdom": "*",
"mocha-lcov-reporter": "*",
"mocha-phantomjs": "^3.5.3",
"sinon": "*",
"sinon-chai": "*"
},
"preferGlobal": false,
"private": false,
"license": "MIT"
"license": "MIT",
"jam": {
"dependencies": {}
},
"scripts": {
"instrument": "istanbul instrument --output build-coverage build/",
"coverage": "istanbul instrument --output build-coverage build/ && istanbul cover _mocha -- test/*_spec.js -R spec",
"coverage-report": "istanbul report --root coverage lcov",
"lint": "coffeelint src/*.coffee",
"make": "coffee --compile --output build/ src/*",
"test": "coffee --compile --output test/ test/*.coffee && ./node_modules/mocha/bin/mocha --globals md5",
"test-phantomjs": "mocha-phantomjs --setting localToRemoteUrlAccessEnabled=true --setting webSecurityEnabled=false test/index.html --hooks ./phantom_hooks.js --timeout 25000"
},
"github": "https://github.com/MatthewCallis/avatar"
}
# [Avatar](http://matthewcallis.github.io/avatar/)
[![Build Status](https://travis-ci.org/MatthewCallis/avatar.svg)](https://travis-ci.org/MatthewCallis/avatar)
[![Dependency Status](https://david-dm.org/MatthewCallis/avatar.svg)](https://david-dm.org/MatthewCallis/avatar)
[![devDependency Status](https://david-dm.org/MatthewCallis/avatar/dev-status.svg?style=flat)](https://david-dm.org/MatthewCallis/avatar#info=devDependencies)
[![Test Coverage](https://codeclimate.com/github/MatthewCallis/avatar/badges/coverage.svg)](https://codeclimate.com/github/MatthewCallis/avatar)
[![Coverage Status](https://coveralls.io/repos/MatthewCallis/avatar/badge.svg)](https://coveralls.io/r/MatthewCallis/avatar)
Avatar is a JavaScript library for showing Gravatars or generating user avatars.

@@ -51,2 +57,15 @@

allowGravatarFallback: false # Use Gravatars fallback, not fallbackImage
# GitHub Specific
github_id: null # GitHub User ID.
# Avatars.io Specific
use_avatars_io: false # Enable Avatars.io Support
avatars_io:
user_id: null # Avatars.io User ID
identifier: null # Avatars.io Avatar Identifier
twitter: null # Twitter ID or Username
facebook: null # Facebook ID or Username
instagram: null # Instagram ID or Username
size: 'medium' # Size: small, medium, large
```

@@ -61,3 +80,3 @@

Avatar expects a `window.md5()` function to be defined in order to generate the hashes needed for Gravatar. One is provided as a sperate file if you would like to use your own or don't plan on using Gravatar.
Avatar expects a `window.md5()` function to be defined in order to generate the hashes needed for Gravatar. One is provided as a seperate file if you would like to use your own or don't plan on using Gravatar.

@@ -84,4 +103,14 @@ ## Running Tests

## Package Managers
There are a lot of these and keeping up with them is hard, so here's a list:
* [npm](https://www.npmjs.com/) - [avatar-initials](https://www.npmjs.com/package/avatar-initials) - `package.json`
* [bower](http://bower.io/) - `bower.json`
* [jQuery Plugins](http://plugins.jquery.com/) - `avatar.jquery.json`
* [Jam](http://jamjs.org/) - [avatar-initials](http://jamjs.org/packages/#/details/avatar-initials) - `package.json`
* [Duo](http://duojs.org/) - `component.json`
### License
Avatar is [MIT licensed](./LICENSE).

@@ -1,6 +0,28 @@

// Generated by CoffeeScript 1.8.0
// Generated by CoffeeScript 1.9.1
(function() {
var Avatar, chai, chaiAsPromised, expect, jsdom, md5, should, sinon, sinonChai;
if (typeof require !== "undefined" && require !== null) {
sinon = require('sinon');
sinonChai = require('sinon-chai');
chai = require('chai');
chaiAsPromised = require('chai-as-promised');
jsdom = require('mocha-jsdom');
Avatar = require('../build/avatar').Avatar;
md5 = require('MD5');
should = chai.should();
expect = chai.expect;
chai.should();
chai.use(sinonChai);
chai.use(chaiAsPromised);
jsdom();
} else {
Avatar = window.Avatar;
sinon = window.sinon;
}
describe("Avatar", function() {
var avatar, error_spy, image, load_spy;
avatar = image = load_spy = error_spy = null;
var avatar, gravatar_timeout, image, old_md5;
avatar = image = null;
gravatar_timeout = 1600;
before(function() {

@@ -20,5 +42,9 @@ image = document.createElement('img');

describe('#constructor', function() {
it('should throw an error without an element', function() {
Avatar.should["throw"](Error);
Avatar.should["throw"]('No image element provided.');
});
it('should render', function() {
avatar = new Avatar(image);
return avatar.settings.useGravatar.should.be["true"];
avatar.settings.useGravatar.should.be["true"];
});

@@ -29,9 +55,19 @@ it('should allow options', function() {

});
return avatar.settings.useGravatar.should.not.be["true"];
avatar.settings.useGravatar.should.not.be["true"];
});
it('should allow Gravatar fallbacks', function() {
avatar = new Avatar(image, {
useGravatar: true,
allowGravatarFallback: true
});
avatar.settings.useGravatar.should.be["true"];
avatar.settings.allowGravatarFallback.should.be["true"];
});
return it('should render a canvas', function() {
avatar = new Avatar(image, {
useGravatar: false,
initials: 'MC'
});
return avatar.settings.useGravatar.should.be["true"];
avatar.settings.useGravatar.should.not.be["true"];
avatar.settings.useGravatar.should.not.equal('MC');
});

@@ -47,3 +83,3 @@ });

avatar.setSource();
return image.src.should.equal('http://placekitten.com/200/300');
image.src.should.equal('http://placekitten.com/200/300');
});

@@ -53,10 +89,124 @@ });

beforeEach(function() {
return avatar = new Avatar(image);
avatar = new Avatar(image);
});
return it('should return a PNG', function() {
var png;
png = avatar.initialAvatar('MC', avatar.settings);
return png.should.match(/^data:image\/png;base64,iV/);
if ((typeof window !== "undefined" && window !== null) && document.createElement('canvas').getContext && document.createElement('canvas').getContext('2d')) {
return it('should return a PNG', function() {
var png;
png = avatar.initialAvatar('MC', avatar.settings);
png.should.match(/^data:image\/png;base64,iV/);
});
}
});
describe('#githubAvatar', function() {
beforeEach(function() {
avatar = new Avatar(image, {
useGravatar: false,
github_id: 67945
});
});
return it('should return a GitHub Avatar URL', function() {
var github_url;
github_url = avatar.githubAvatar({
github_id: 67945,
size: 80
});
github_url.should.match(/https:\/\/avatars[0-3].githubusercontent.com\/u\/67945\?v=3&s=[0-9]{1,4}/i);
});
});
describe('#avatarsioAvatar', function() {
it('should return an Avatars.io Avatar URL', function() {
var github_url;
avatar = new Avatar(image, {
useGravatar: false,
use_avatars_io: true,
avatars_io: {
user_id: 12345,
identifier: 'custom-id',
size: 'small'
}
});
github_url = avatar.avatarsioAvatar({
avatars_io: {
user_id: 12345,
identifier: 'custom-id',
size: 'small'
}
});
github_url.should.equal('http://avatars.io/12345/custom-id?size=small');
});
it('should return an Avatars.io Avatar URL with a custom size', function() {
var github_url;
avatar = new Avatar(image, {
useGravatar: false,
use_avatars_io: true,
avatars_io: {
user_id: 12345,
identifier: 'custom-id',
size: 'medium'
}
});
github_url = avatar.avatarsioAvatar({
avatars_io: {
user_id: 12345,
identifier: 'custom-id',
size: 'medium'
}
});
github_url.should.equal('http://avatars.io/12345/custom-id?size=medium');
});
it('should return an Avatars.io Facebook Avatar URL', function() {
var github_url;
avatar = new Avatar(image, {
useGravatar: false,
use_avatars_io: true,
avatars_io: {
facebook: 'matthew.callis',
size: 'small'
}
});
github_url = avatar.avatarsioAvatar({
avatars_io: {
facebook: 'matthew.callis',
size: 'small'
}
});
github_url.should.equal('http://avatars.io/facebook/matthew.callis?size=small');
});
it('should return an Avatars.io Twitter Avatar URL', function() {
var github_url;
avatar = new Avatar(image, {
useGravatar: false,
use_avatars_io: true,
avatars_io: {
twitter: 'superfamicom',
size: 'small'
}
});
github_url = avatar.avatarsioAvatar({
avatars_io: {
twitter: 'superfamicom',
size: 'small'
}
});
github_url.should.equal('http://avatars.io/twitter/superfamicom?size=small');
});
return it('should return an Avatars.io Instagram Avatar URL', function() {
var github_url;
avatar = new Avatar(image, {
useGravatar: false,
use_avatars_io: true,
avatars_io: {
instagram: 'matthewcallis',
size: 'small'
}
});
github_url = avatar.avatarsioAvatar({
avatars_io: {
instagram: 'matthewcallis',
size: 'small'
}
});
github_url.should.equal('http://avatars.io/instagram/matthewcallis?size=small');
});
});
describe('#gravatarUrl', function() {

@@ -68,4 +218,7 @@ it('should return a Gravatar URL with an email address', function() {

});
if (!(window && window.md5)) {
avatar.md5 = md5;
}
url = avatar.gravatarUrl(avatar.settings);
return url.should.equal('https://secure.gravatar.com/avatar/b642b4217b34b1e8d3bd915fc65c4452?s=80&d=mm&r=x');
url.should.equal('https://secure.gravatar.com/avatar/b642b4217b34b1e8d3bd915fc65c4452?s=80&d=mm&r=x');
});

@@ -78,3 +231,3 @@ it('should return a Gravatar URL with an hash', function() {

url = avatar.gravatarUrl(avatar.settings);
return url.should.equal('https://secure.gravatar.com/avatar/b642b4217b34b1e8d3bd915fc65c4452?s=80&d=mm&r=x');
url.should.equal('https://secure.gravatar.com/avatar/b642b4217b34b1e8d3bd915fc65c4452?s=80&d=mm&r=x');
});

@@ -85,3 +238,3 @@ it('should return a Gravatar URL with nothing', function() {

url = avatar.gravatarUrl(avatar.settings);
return url.should.equal('https://secure.gravatar.com/avatar/00000000000000000000000000000000?s=80&d=mm&r=x');
url.should.equal('https://secure.gravatar.com/avatar/00000000000000000000000000000000?s=80&d=mm&r=x');
});

@@ -99,3 +252,13 @@ it('should return a Gravatar URL with a custom size', function() {

url = avatar.gravatarUrl(avatar.settings);
return url.should.equal('https://secure.gravatar.com/avatar/00000000000000000000000000000000?s=100&d=mm&r=x');
url.should.equal('https://secure.gravatar.com/avatar/00000000000000000000000000000000?s=100&d=mm&r=x');
avatar = new Avatar(image, {
size: 0
});
url = avatar.gravatarUrl(avatar.settings);
url.should.equal('https://secure.gravatar.com/avatar/00000000000000000000000000000000?s=80&d=mm&r=x');
avatar = new Avatar(image, {
size: 4000
});
url = avatar.gravatarUrl(avatar.settings);
url.should.equal('https://secure.gravatar.com/avatar/00000000000000000000000000000000?s=80&d=mm&r=x');
});

@@ -108,3 +271,3 @@ it('should return a Gravatar URL with a custom fallback', function() {

url = avatar.gravatarUrl(avatar.settings);
return url.should.equal('https://secure.gravatar.com/avatar/00000000000000000000000000000000?s=80&d=test&r=x');
url.should.equal('https://secure.gravatar.com/avatar/00000000000000000000000000000000?s=80&d=test&r=x');
});

@@ -117,7 +280,144 @@ return it('should return a Gravatar URL with a custom rating', function() {

url = avatar.gravatarUrl(avatar.settings);
return url.should.equal('https://secure.gravatar.com/avatar/00000000000000000000000000000000?s=80&d=mm&r=g');
url.should.equal('https://secure.gravatar.com/avatar/00000000000000000000000000000000?s=80&d=mm&r=g');
});
});
if ((typeof window !== "undefined" && window !== null) && (window.Image != null)) {
describe('#gravatarValid', function() {
var call_spy, error_spy, load_spy;
this.timeout(16000);
avatar = load_spy = error_spy = call_spy = null;
describe('Invalid Gravatar Hash', function() {
before(function(done) {
avatar = new Avatar(image, {
useGravatar: true,
hash: '00000000000000000000000000000000'
});
call_spy = sinon.spy(avatar, 'gravatarValid');
load_spy = sinon.spy(avatar, 'gravatarValidOnLoad');
error_spy = sinon.spy(avatar, 'gravatarValidOnError');
avatar.gravatarValid({
hash: '00000000000000000000000000000000'
});
setTimeout(done, gravatar_timeout);
});
it('should return an error', function() {
call_spy.callCount.should.equal(1);
load_spy.callCount.should.equal(0);
error_spy.callCount.should.equal(1);
});
});
describe('Valid Gravatar Hash', function() {
before(function(done) {
avatar = new Avatar(image, {
useGravatar: true,
hash: '12929016fffb0b3af98bc440acf0bfe2'
});
call_spy = sinon.spy(avatar, 'gravatarValid');
load_spy = sinon.spy(avatar, 'gravatarValidOnLoad');
error_spy = sinon.spy(avatar, 'gravatarValidOnError');
avatar.gravatarValid({
hash: '12929016fffb0b3af98bc440acf0bfe2'
});
setTimeout(done, gravatar_timeout);
});
it('should not return an error', function() {
call_spy.callCount.should.equal(1);
load_spy.callCount.should.equal(1);
error_spy.callCount.should.equal(0);
});
});
describe('Invalid Gravatar Email', function() {
before(function(done) {
avatar = new Avatar(image, {
useGravatar: true,
email: 'test@test.com'
});
if (!(window && window.md5)) {
avatar.md5 = md5;
}
call_spy = sinon.spy(avatar, 'gravatarValid');
load_spy = sinon.spy(avatar, 'gravatarValidOnLoad');
error_spy = sinon.spy(avatar, 'gravatarValidOnError');
avatar.gravatarValid({
email: 'test@test.com'
});
setTimeout(done, gravatar_timeout);
});
it('should return an error', function() {
call_spy.callCount.should.equal(1);
load_spy.callCount.should.equal(0);
error_spy.callCount.should.equal(1);
});
});
return describe('Valid Gravatar Email', function() {
before(function(done) {
avatar = new Avatar(image, {
useGravatar: true,
email: 'matthew@apptentive.com'
});
if (!(window && window.md5)) {
avatar.md5 = md5;
}
call_spy = sinon.spy(avatar, 'gravatarValid');
load_spy = sinon.spy(avatar, 'gravatarValidOnLoad');
error_spy = sinon.spy(avatar, 'gravatarValidOnError');
avatar.gravatarValid({
email: 'matthew@apptentive.com'
});
setTimeout(done, gravatar_timeout);
});
it('should not return an error', function() {
call_spy.callCount.should.equal(1);
load_spy.callCount.should.equal(1);
error_spy.callCount.should.equal(0);
});
});
});
}
describe('#gravatarValidOnLoad', function() {
var call_spy, load_spy;
this.timeout(16000);
call_spy = load_spy = null;
before(function(done) {
avatar = new Avatar(image, {
useGravatar: false
});
call_spy = sinon.spy(avatar, 'gravatarValidOnLoad');
load_spy = sinon.spy(avatar, 'setSource');
avatar.gravatarValidOnLoad();
setTimeout(done, gravatar_timeout);
});
return it('should call gravatarUrl with settings', function() {
call_spy.callCount.should.equal(1);
load_spy.callCount.should.equal(1);
});
});
describe('#gravatarValidOnError', function() {
var call_spy, init_spy, load_spy;
call_spy = load_spy = init_spy = null;
beforeEach(function() {
avatar = new Avatar(image, {
useGravatar: false
});
call_spy = sinon.spy(avatar, 'gravatarValidOnError');
load_spy = sinon.spy(avatar, 'setSource');
init_spy = sinon.spy(avatar, 'initialAvatar');
});
it('should draw an avatar if we have initials', function() {
avatar.settings.initials = 'MCFUCKYEAH';
avatar.gravatarValidOnError();
call_spy.callCount.should.equal(1);
load_spy.callCount.should.equal(1);
init_spy.callCount.should.equal(1);
});
return it('should use the fallback image without initials', function() {
avatar.settings.initials = '';
avatar.gravatarValidOnError();
call_spy.callCount.should.equal(1);
load_spy.callCount.should.equal(1);
init_spy.callCount.should.equal(0);
});
});
describe('#merge', function() {
return it('should merge objects', function() {
it('should merge objects', function() {
var defaults, options, output;

@@ -141,3 +441,12 @@ avatar = new Avatar(image);

fallbackImage: '',
debug: false
debug: false,
github_id: null,
use_avatars_io: false,
avatars_io: {
user_id: null,
identifier: null,
twitter: null,
facebook: null,
instagram: null
}
};

@@ -160,19 +469,51 @@ options = {

fallbackImage: 'nah',
debug: false
debug: false,
github_id: 1,
use_avatars_io: true,
avatars_io: {
user_id: 1,
identifier: 2,
twitter: 3,
facebook: 4,
instagram: 5
}
};
output = avatar.merge(defaults, options);
return output.should.deep.equal(options);
output.should.deep.equal(options);
});
});
return describe('jQuery Helper', function() {
return it('should create an avatar with options', function() {
$('#avatar-1').avatar({
useGravatar: false,
initials: 'MC'
if ((typeof window !== "undefined" && window !== null) && (window.md5 != null)) {
old_md5 = window.md5;
after(function() {
window.md5 = old_md5;
});
describe('#md5', function() {
it('should have an md5 function', function() {
var md5_sum;
avatar = new Avatar(image);
md5_sum = avatar.md5('test');
md5_sum.should.equal('098f6bcd4621d373cade4e832627b4f6');
});
return $('#avatar-1').attr('src').should.match(/^data:image\/png;base64,iV/);
return it('should fall back to a default when there is no global md5', function() {
var md5_sum;
window.md5 = null;
avatar = new Avatar(image);
md5_sum = avatar.md5('test');
md5_sum.should.equal('00000000000000000000000000000000');
});
});
});
}
if (typeof jQuery === 'function' && typeof window === 'object') {
return describe('#jQueryHelper', function() {
it('should create an avatar with options', function() {
$('#avatar-1').avatar({
useGravatar: false,
initials: 'MC'
});
$('#avatar-1').attr('src').should.match(/^data:image\/png;base64,iV/);
});
});
}
});
}).call(this);

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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