-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit f540cd6
Showing
14 changed files
with
515 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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']); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}; | ||
} | ||
} |
Oops, something went wrong.