lorem-ipsum
Advanced tools
Comparing version 1.0.4 to 1.0.5
#!/usr/bin/env node | ||
var optimist = require('optimist') | ||
var minimist = require('minimist') | ||
, generator = require('./../lib/generator') | ||
@@ -8,3 +8,3 @@ , clipper = require('./../lib/clipper'); | ||
var options = {} | ||
, arguments = optimist.argv | ||
, arguments = minimist(process.argv.slice(2)) | ||
, loremIpsum = ''; | ||
@@ -22,3 +22,3 @@ | ||
options.copy = arguments.copy ? true : false; | ||
options.format = arguments.format || 'plain'; | ||
options.format = arguments.format || 'plain'; | ||
@@ -34,2 +34,2 @@ // Generate the lorem ipsum text and print it out. | ||
process.exit(); // Successful exit. | ||
} | ||
} |
@@ -5,24 +5,24 @@ var execute = require('child_process').exec; | ||
var clipper = function(text, next) { | ||
statement = 'echo "' + text + '" | '; | ||
statement = 'echo "' + text + '" | '; | ||
switch (process.platform) { | ||
case 'darwin': | ||
statement = statement + 'pbcopy'; | ||
break; | ||
case 'win32': | ||
statement = statement + 'clip'; | ||
break; | ||
case 'linux': | ||
default: | ||
statement = statement + 'xclip -selection clipboard'; | ||
} | ||
switch (process.platform) { | ||
case 'darwin': | ||
statement = statement + 'pbcopy'; | ||
break; | ||
case 'win32': | ||
statement = statement + 'clip'; | ||
break; | ||
case 'linux': | ||
default: | ||
statement = statement + 'xclip -selection clipboard'; | ||
} | ||
execute(statement, function(err, stdout, stderr) { | ||
if (err) { | ||
next(new Error('Failed to copy data to clipboard')); | ||
} | ||
next(null); | ||
}); | ||
execute(statement, function(err, stdout, stderr) { | ||
if (err) { | ||
next(new Error('Failed to copy data to clipboard')); | ||
} | ||
next(null); | ||
}); | ||
}; | ||
module.exports = clipper; | ||
module.exports = clipper; |
@@ -64,6 +64,6 @@ var dictionary = { | ||
'veniam', | ||
'voluptate' | ||
'voluptate' | ||
] | ||
}; | ||
module.exports = dictionary; | ||
module.exports = dictionary; |
@@ -1,2 +0,2 @@ | ||
var generator = function() { | ||
function generator() { | ||
var options = (arguments.length) ? arguments[0] : {} | ||
@@ -27,11 +27,11 @@ , count = options.count || 1 | ||
var randomInteger = function(min, max) { | ||
function randomInteger(min, max) { | ||
return Math.floor(random() * (max - min + 1) + min); | ||
}; | ||
var randomWord = function(words) { | ||
function randomWord(words) { | ||
return words[randomInteger(0, words.length - 1)]; | ||
}; | ||
var randomSentence = function(words, lowerBound, upperBound) { | ||
function randomSentence(words, lowerBound, upperBound) { | ||
var sentence = '' | ||
@@ -41,4 +41,4 @@ , bounds = {min: 0, max: randomInteger(lowerBound, upperBound)}; | ||
while (bounds.min < bounds.max) { | ||
sentence = sentence + ' ' + randomWord(words); | ||
bounds.min = bounds.min + 1; | ||
sentence += ' ' + randomWord(words); | ||
bounds.min++; | ||
} | ||
@@ -54,3 +54,3 @@ | ||
var randomParagraph = function(words, lowerBound, upperBound, sentenceLowerBound, sentenceUpperBound) { | ||
function randomParagraph(words, lowerBound, upperBound, sentenceLowerBound, sentenceUpperBound) { | ||
var paragraph = '' | ||
@@ -60,4 +60,4 @@ , bounds = {min: 0, max: randomInteger(lowerBound, upperBound)}; | ||
while (bounds.min < bounds.max) { | ||
paragraph = paragraph + '. ' + randomSentence(words, sentenceLowerBound, sentenceUpperBound); | ||
bounds.min = bounds.min + 1; | ||
paragraph += '. ' + randomSentence(words, sentenceLowerBound, sentenceUpperBound); | ||
bounds.min++; | ||
} | ||
@@ -67,3 +67,3 @@ | ||
paragraph = paragraph.slice(2); | ||
paragraph = paragraph + '.'; | ||
paragraph += '.'; | ||
} | ||
@@ -81,3 +81,3 @@ | ||
if (format == 'html') { | ||
if (format === 'html') { | ||
openingTag = '<p>'; | ||
@@ -90,6 +90,6 @@ closingTag = '</p>'; | ||
case 'words': | ||
string = string + ' ' + randomWord(words); | ||
string += ' ' + randomWord(words); | ||
break; | ||
case 'sentences': | ||
string = string + '. ' + randomSentence(words, sentenceLowerBound, sentenceUpperBound); | ||
string += '. ' + randomSentence(words, sentenceLowerBound, sentenceUpperBound); | ||
break; | ||
@@ -99,12 +99,12 @@ case 'paragraphs': | ||
if (format == 'html') { | ||
if (format === 'html') { | ||
nextString = openingTag + nextString + closingTag; | ||
if (bounds.min < bounds.max - 1) { | ||
nextString = nextString + suffix; // Each paragraph on a new line | ||
nextString += suffix; // Each paragraph on a new line | ||
} | ||
} else if (bounds.min < bounds.max - 1) { | ||
nextString = nextString + suffix + suffix; // Double-up the EOL character to make distinct paragraphs, like carriage return | ||
nextString += suffix + suffix; // Double-up the EOL character to make distinct paragraphs, like carriage return | ||
} | ||
string = string + nextString; | ||
string += nextString; | ||
@@ -114,3 +114,3 @@ break; | ||
bounds.min = bounds.min + 1; | ||
bounds.min++; | ||
} | ||
@@ -121,5 +121,5 @@ | ||
if (string.indexOf('. ') == 0) { | ||
if (string.indexOf('. ') === 0) { | ||
pos = 2; | ||
} else if (string.indexOf('.') == 0 || string.indexOf(' ') == 0) { | ||
} else if (string.indexOf('.') === 0 || string.indexOf(' ') === 0) { | ||
pos = 1; | ||
@@ -130,4 +130,4 @@ } | ||
if (units == 'sentences') { | ||
string = string + '.'; | ||
if (units === 'sentences') { | ||
string += '.'; | ||
} | ||
@@ -134,0 +134,0 @@ } |
{ | ||
"name": "lorem-ipsum", | ||
"version": "1.0.4", | ||
"description": "Generates passages of lorem ipsum text suitable for use as placeholder copy in web pages, graphics, and more.", | ||
"version": "1.0.5", | ||
"description": "Generates passages of lorem ipsum text suitable for use as placeholder copy in web pages, graphics, and more. Works in the browser, NodeJS, and React Native.", | ||
"author": "Nickolas Kenyeres <nkenyeres@gmail.com> (http://knicklabs.github.com)", | ||
"license": "MIT/X11", | ||
"license": "MIT", | ||
"main": "./lib/generator", | ||
"dependencies": { | ||
"optimist": "~0.3.5" | ||
"minimist": "~1.2.0" | ||
}, | ||
"devDependencies": { | ||
"alea": "0.0.9" | ||
"alea": "0.0.9", | ||
"mocha": "^5.2.0" | ||
}, | ||
@@ -19,3 +20,3 @@ "optionalDependencies": {}, | ||
"scripts": { | ||
"test": "nodeunit test" | ||
"test": "./node_modules/mocha/bin/mocha" | ||
}, | ||
@@ -22,0 +23,0 @@ "repository": { |
### lorem-ipsum.js | ||
lorem-ipsum.js is a Node.js and Component.js module for generating passages of lorem ipsum text. Lorem ipsum text is commonly used as placeholder text in publishing, graphic design, and web development. | ||
lorem-ipsum.js is a Node.js, Component.js, and React Native module for generating passages of lorem ipsum text. Lorem ipsum text is commonly used as placeholder text in publishing, graphic design, and web development. | ||
@@ -5,0 +5,0 @@ ### Using the Module (Node.js) |
/* | ||
* Series of unit tests to test randomness of output. | ||
*/ | ||
module.exports = { | ||
setUp: function(callback) { | ||
this.generator = require('./../lib/generator'); | ||
this.random = Math.random; | ||
callback(); | ||
}, | ||
var assert = require('assert'); | ||
var generator = require('../lib/generator'); | ||
var random = Math.random; | ||
/* | ||
* Test that using Math.random() gives us unique output. | ||
*/ | ||
testForUniqueOutput: function(test) { | ||
test.notDeepEqual(generateWords(null), generateWords(null)); | ||
test.done(); | ||
}, | ||
/* | ||
* Test that we can use a custom pseduo random number generator | ||
* and still have unique output. | ||
*/ | ||
testForUniqueOutputWithCustomGenerator: function(test) { | ||
var alea = new (require('alea')); | ||
test.notDeepEqual(generateWords(alea), generateWords(alea)); | ||
test.done(); | ||
}, | ||
/* | ||
* Test that we can create reproducible pseudo random output by | ||
* seeding a custom PNRG. | ||
*/ | ||
testForReproducibleOutputWithCustomGenerator: function(test) { | ||
var alea1 = new (require('alea'))('seed'); | ||
var alea2 = new (require('alea'))('seed'); | ||
test.deepEqual(generateWords(alea1), generateWords(alea2)); | ||
test.done(); | ||
}, | ||
/* | ||
* Test that we can create pseudo random output by using unique | ||
* seeds for a custom PNRG. | ||
*/ | ||
testForUniqueOutputWithCustomGeneratorWithUniqueSeeds: function(test) { | ||
var alea1 = new (require('alea'))('seed'); | ||
var alea2 = new (require('alea'))('different-seed'); | ||
test.notDeepEqual(generateWords(alea1), generateWords(alea2)); | ||
test.done(); | ||
} | ||
}; | ||
/* | ||
@@ -71,2 +24,27 @@ * Helpers | ||
return words.join(', '); | ||
} | ||
} | ||
describe('generator', function() { | ||
it('should give us unique output using Math.random()', function() { | ||
assert.notEqual(generateWords(null), generateWords(null)); | ||
}); | ||
it('should use a custom pseudo random number generator and still have unique output', function() { | ||
var alea = new (require('alea')); | ||
assert.notEqual(generateWords(alea), generateWords(alea)); | ||
}); | ||
it('should create reproducible pseudo random output by seeding a custom PNRG', function() { | ||
var alea1 = new (require('alea'))('seed'); | ||
var alea2 = new (require('alea'))('seed'); | ||
assert.equal(generateWords(alea1), generateWords(alea2)); | ||
}); | ||
it('should create pseudo random output by using unique seeds for a custom PNRG', function () { | ||
var alea1 = new (require('alea'))('seed'); | ||
var alea2 = new (require('alea'))('different-seed'); | ||
assert.notEqual(generateWords(alea1), generateWords(alea2)); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Misc. License Issues
License(Experimental) A package's licensing information has fine-grained problems.
Found 1 instance in 1 package
0
13595
2
279
+ Addedminimist@~1.2.0
+ Addedminimist@1.2.8(transitive)
- Removedoptimist@~0.3.5
- Removedoptimist@0.3.7(transitive)
- Removedwordwrap@0.0.3(transitive)