chocolate
Version:
A full stack Node.js web framework built using Coffeescript
128 lines (124 loc) • 5.46 kB
JavaScript
// Generated by CoffeeScript 1.12.6
(function() {
var _module, lorem;
_module = typeof window !== "undefined" && window !== null ? window : module;
_module[_module.exports != null ? "exports" : "Loremlite"] = lorem = (function() {
var face, image, paragraph, paragraphs, random, sentence, sentences, thesaurus, word, words;
thesaurus = ['lorem', 'ipsum', 'dolor', 'sit', 'amet,', 'consectetur', 'adipiscing', 'elit', 'ut', 'aliquam,', 'purus', 'sit', 'amet', 'luctus', 'venenatis,', 'lectus', 'magna', 'fringilla', 'urna,', 'porttitor', 'rhoncus', 'dolor', 'purus', 'non', 'enim', 'praesent', 'elementum', 'facilisis', 'leo,', 'vel', 'fringilla', 'est', 'ullamcorper', 'eget', 'nulla', 'facilisi', 'etiam', 'dignissim', 'diam', 'quis', 'enim', 'lobortis', 'scelerisque', 'fermentum', 'dui', 'faucibus', 'in', 'ornare', 'quam', 'viverra', 'orci', 'sagittis', 'eu', 'volutpat', 'odio', 'facilisis', 'mauris', 'sit', 'amet', 'massa', 'vitae', 'tortor', 'condimentum', 'lacinia', 'quis', 'vel', 'eros', 'donec', 'ac', 'odio', 'tempor', 'orci', 'dapibus', 'ultrices', 'in', 'iaculis', 'nunc', 'sed', 'augue', 'lacus,', 'viverra', 'vitae', 'congue', 'eu,', 'consequat', 'ac', 'felis', 'donec', 'et', 'odio', 'pellentesque', 'diam', 'volutpat', 'commodo', 'sed', 'egestas', 'egestas', 'fringilla', 'phasellus', 'faucibus', 'scelerisque', 'eleifend', 'donec', 'pretium', 'vulputate', 'sapien', 'nec', 'sagittis', 'aliquam', 'malesuada', 'bibendum', 'arcu', 'vitae', 'elementum', 'curabitur', 'vitae', 'nunc', 'sed', 'velit', 'dignissim', 'sodales', 'ut', 'eu', 'sem', 'integer', 'vitae', 'justo', 'eget', 'magna', 'fermentum', 'iaculis', 'eu', 'non', 'diam', 'phasellus', 'vestibulum'];
random = function(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
};
word = function() {
return lorem.words(1);
};
words = function(count) {
var index;
if (count == null) {
count = 3;
}
index = lorem.random(0, lorem.thesaurus.length - count - 1);
return lorem.thesaurus.slice(index, index + count).join(' ').replace(/[\.\,]/g, '');
};
sentence = function() {
return lorem.sentences(1);
};
sentences = function(count) {
var i, j, ref, str;
if (count == null) {
count = 6;
}
sentences = [];
for (i = j = 0, ref = count; 0 <= ref ? j < ref : j > ref; i = 0 <= ref ? ++j : --j) {
words = lorem.words(lorem.random(5, 10)).split(' ');
words[0] = words[0].substr(0, 1).toUpperCase() + words[0].substr(1);
str = words.join(' ');
sentences.push(str);
}
return sentences.join('. ') + '.';
};
paragraph = function() {
return lorem.paragraphs(1);
};
paragraphs = function(count) {
var i, j, ref;
if (count == null) {
count = 3;
}
paragraphs = [];
for (i = j = 0, ref = count; 0 <= ref ? j < ref : j > ref; i = 0 <= ref ? ++j : --j) {
paragraph = lorem.sentences(lorem.random(10, 20));
paragraphs.push(paragraph);
}
if (count > 1) {
return paragraphs.join('\n');
} else {
return paragraphs[0];
}
};
image = function(options) {
var path, ref, ref1, ref2, ref3, ref4, ref5;
if (options == null) {
options = {};
}
if (typeof options === 'string') {
options = {
type: options
};
}
if (options.type != null) {
path = '';
path += '/' + ((ref = options.width) != null ? ref : "400");
path += '/' + ((ref1 = options.height) != null ? ref1 : "200");
path += '/' + ((ref2 = options.type) != null ? ref2 : 'any');
if (options.color) {
path += '/' + options.color;
}
path += '?cache=' + ((ref3 = options.id) != null ? ref3 : (1 + Math.random()).toString().substr(2));
return 'https://placeimg.com' + path;
} else {
path = '';
if (options.color === 'grayscale') {
path += '/g';
}
path += '/' + ((ref4 = options.width) != null ? ref4 : "400");
path += '/' + ((ref5 = options.height) != null ? ref5 : "200");
path += options.id != null ? "?image=" + options.id : '?cache=' + (1 + Math.random()).toString().substr(2);
path += options.blur ? (path.indexOf('?') >= 0 ? '&' : '?') + "blur" : '';
path += options.gravity ? (path.indexOf('?') >= 0 ? '&' : '?') + "gravity=" + options.gravity : '';
return 'https://picsum.photos' + path;
}
};
face = function(gender, options) {
var ref;
if (typeof gender !== 'string') {
options = gender;
gender = null;
}
if (options == null) {
options = {};
}
if (gender == null) {
gender = options.gender;
}
if (gender === 'man') {
gender = 'men';
}
if (gender === 'woman') {
gender = 'women';
}
return "https://randomuser.me/api/portraits/" + (gender != null ? gender : (lorem.random(0, 1) === 0 ? 'women' : 'men')) + "/" + ((ref = options.id) != null ? ref : lorem.random(0, 99)) + ".jpg";
};
return {
word: word,
words: words,
sentence: sentence,
sentences: sentences,
paragraph: paragraph,
paragraphs: paragraphs,
image: image,
face: face,
random: random,
thesaurus: thesaurus
};
})();
}).call(this);