Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
1egoman committed Jun 16, 2016
0 parents commit f540cd6
Show file tree
Hide file tree
Showing 14 changed files with 515 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
EditorConfig is awesome: http://EditorConfig.org

root = true;

[*]
trim_trailing_whitespace = true
insert_final_newline = true

[*.js]
indent_style = space
indent_size = 2
7 changes: 7 additions & 0 deletions .jscsrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// See https://github.com/jscs-dev/node-jscs/tree/master/presets for
// other options (remember to re-enable esnext)
{
"preset": "google",
"maximumLineLength": null,
"esnext": true
}
57 changes: 57 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"bitwise" : true,
"camelcase" : true,
"eqeqeq" : true,
"forin" : false,
"immed" : true,
"indent" : 2,
"latedef" : true,
"newcap" : true,
"noarg" : true,
"nonbsp" : true,
"nonew" : true,
"plusplus" : false,
"undef" : true,
"unused" : true,
"strict" : false,
"maxparams" : 4,
"maxdepth" : 2,
"maxstatements" : 15,
"maxcomplexity" : 10,
"maxlen" : 100,

"asi" : false,
"boss" : false,
"debug" : false,
"eqnull" : false,
"esnext" : true,
"evil" : false,
"expr" : false,
"funcscope" : false,
"globalstrict" : false,
"iterator" : false,
"lastsemic" : false,
"loopfunc" : false,
"maxerr" : 50,
"notypeof" : false,
"proto" : false,
"scripturl" : false,
"shadow" : false,
"supernew" : false,
"validthis" : false,
"noyield" : false,

"browser" : true,
"couch" : false,
"devel" : false,
"dojo" : false,
"jquery" : false,
"mootools" : false,
"node" : true,
"nonstandard" : false,
"prototypejs" : false,
"rhino" : false,
"worker" : false,
"wsh" : false,
"yui" : false
}
86 changes: 86 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#### joe made this: https://goel.io/joe

#####=== Node ===#####

# Logs
logs
*.log

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directory
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git-
node_modules

# Debug log from npm
npm-debug.log

#####=== Linux ===#####
*~

# KDE directory preferences
.directory

# Linux trash folder which might appear on any partition or disk
.Trash-*

#####=== OSX ===#####
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon

# Thumbnails
._*

# Files that might appear on external disk
.Spotlight-V100
.Trashes

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

#####=== Windows ===#####
# Windows image file caches
Thumbs.db
ehthumbs.db

# Folder config file
Desktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Windows Installer files
*.cab
*.msi
*.msm
*.msp

# Windows shortcuts
*.lnk

Expand Down
22 changes: 22 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
The MIT License (MIT)

Copyright (c) 2016 Ryan Gaus

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# funnies
[![Travis build status](http://img.shields.io/travis/1egoman/funnies.svg?style=flat)](https://travis-ci.org/1egoman/funnies)
[![Code Climate](https://codeclimate.com/github/1egoman/funnies/badges/gpa.svg)](https://codeclimate.com/github/1egoman/funnies)
[![Test Coverage](https://codeclimate.com/github/1egoman/funnies/badges/coverage.svg)](https://codeclimate.com/github/1egoman/funnies)
[![Dependency Status](https://david-dm.org/1egoman/funnies.svg)](https://david-dm.org/1egoman/funnies)
[![devDependency Status](https://david-dm.org/1egoman/funnies/dev-status.svg)](https://david-dm.org/1egoman/funnies#info=devDependencies)

Make user's laugh when your app is loading.
91 changes: 91 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
const gulp = require('gulp');
const $ = require('gulp-load-plugins')();
const del = require('del');
const path = require('path');
const mkdirp = require('mkdirp');
const isparta = require('isparta');

const manifest = require('./package.json');
const config = manifest.nodeBoilerplateOptions;
const mainFile = manifest.main;
const destinationFolder = path.dirname(mainFile);

// Remove the built files
gulp.task('clean', function(cb) {
del([destinationFolder], cb);
});

// Send a notification when JSHint fails,
// so that you know your changes didn't build
function jshintNotify(file) {
if (!file.jshint) { return; }
return file.jshint.success ? false : 'JSHint failed';
}

function jscsNotify(file) {
if (!file.jscs) { return; }
return file.jscs.success ? false : 'JSCS failed';
}

function createLintTask(taskName, files) {
gulp.task(taskName, function() {
return gulp.src(files)
.pipe($.plumber())
.pipe($.jshint())
.pipe($.jshint.reporter('jshint-stylish'))
.pipe($.notify(jshintNotify))
.pipe($.jscs())
.pipe($.notify(jscsNotify))
.pipe($.jshint.reporter('fail'));
});
}

// Lint our source code
createLintTask('lint-src', ['src/**/*.js'])

// Lint our test code
createLintTask('lint-test', ['test/**/*.js'])

// Build two versions of the library
gulp.task('build', ['lint-src', 'clean'], function() {

// Create our output directory
mkdirp.sync(destinationFolder);
return gulp.src('src/**/*.js')
.pipe($.plumber())
.pipe($.babel({ blacklist: ['useStrict'] }))
.pipe(gulp.dest(destinationFolder));
});

function test() {
return gulp.src(['test/setup/node.js', 'test/unit/**/*.js'], {read: false})
.pipe($.plumber())
.pipe($.mocha({reporter: 'dot', globals: config.mochaGlobals}));
}

// Make babel preprocess the scripts the user tries to import from here on.
require('babel/register');

gulp.task('coverage', function(done) {
gulp.src(['src/*.js'])
.pipe($.plumber())
.pipe($.istanbul({ instrumenter: isparta.Instrumenter }))
.pipe($.istanbul.hookRequire())
.on('finish', function() {
return test()
.pipe($.istanbul.writeReports())
.on('end', done);
});
});


// Lint and run our tests
gulp.task('test', ['lint-src', 'lint-test'], test);

// Run the headless unit tests as you make changes.
gulp.task('watch', ['test'], function() {
gulp.watch(['src/**/*', 'test/**/*', 'package.json', '**/.jshintrc', '.jscsrc'], ['test']);
});

// An alias of test
gulp.task('default', ['test']);
62 changes: 62 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"name": "funnies",
"version": "0.0.1",
"description": "Make user's laugh when your app is loading.",
"main": "dist/index.js",
"scripts": {
"test": "gulp",
"build": "gulp build",
"coverage": "gulp coverage",
"prepublish": "npm run build"
},
"repository": {
"type": "git",
"url": "https://github.com/1egoman/funnies.git"
},
"keywords": [
"funny",
"funnies",
"loading message",
"loading",
"funny loading",
"jeopardy",
"thinking"
],
"author": "Ryan Gaus",
"license": "MIT",
"bugs": {
"url": "https://github.com/1egoman/funnies/issues"
},
"homepage": "https://github.com/1egoman/funnies",
"devDependencies": {
"babel": "^5.0.0",
"chai": "^2.0.0",
"del": "^1.1.1",
"gulp": "^3.8.10",
"gulp-babel": "^5.0.0",
"gulp-istanbul": "^0.6.0",
"gulp-jscs": "^1.4.0",
"gulp-jshint": "^1.9.0",
"gulp-load-plugins": "^0.8.0",
"gulp-mocha": "^2.0.0",
"gulp-notify": "^2.1.0",
"gulp-plumber": "^0.6.6",
"isparta": "^2.0.0",
"jshint-stylish": "^1.0.0",
"mkdirp": "^0.5.0",
"mocha": "^2.1.0",
"sinon": "^1.12.2",
"sinon-chai": "^2.7.0"
},
"nodeBoilerplateOptions": {
"mochaGlobals": [
"stub",
"spy",
"expect"
]
},
"dependencies": {
"babel-preset-es2015": "^6.9.0",
"lodash": "^4.13.1"
}
}
Binary file added spinner.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
42 changes: 42 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import _ from 'lodash';
import defaultMessages from './funnies';

export default class Funnies {
constructor(messages=[]) {
this.messages = defaultMessages.concat(messages);

// convert messages into a map of message to how many times it has been
// used.
this.record = {};
this.messages.forEach(message => {
this.record[message] = 0;
});
}

// pick the smallest of the freqencies for a message to get a more random
// distribution
message() {
let smallestMessage = this.messages.reduce((smallest, message) => {
if (this.record[smallest] > this.record[message]) {
return message;
} else if (this.record[smallest] === this.record[message]) {
return _.sample([smallest, message]);
} else {
return smallest;
}
});

// update the recrd to show that this message was picked
this.record[smallestMessage] += 1;
return smallestMessage;
}

messageHTML() {
let message = this.message();
let html = `<div class="loading">
<img src="spinner.gif" />
<span class="loading-funny">${message}</span>
</div>`.replace(/(\r?\n|^ +)/gm, '');
return {message, html};
}
}
Loading

0 comments on commit f540cd6

Please sign in to comment.