├── .gitignore ├── package.json ├── example.js ├── README.md └── index.js /.gitignore: -------------------------------------------------------------------------------- 1 | .build* 2 | .idea/ -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "fake-words", 3 | "version": "0.5.3", 4 | "license": "MIT", 5 | "summary": "Random text and data generator", 6 | "repository": { 7 | "type": "git", 8 | "url": "https://github.com/anticoders/fake-words.git" 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /example.js: -------------------------------------------------------------------------------- 1 | const fake = require('./index.js'); 2 | 3 | console.log(fake.word()); 4 | console.log(); 5 | console.log(fake.sentence()); 6 | console.log(); 7 | console.log(fake.paragraph()); 8 | console.log(); 9 | console.log(fake.user()); 10 | console.log(); 11 | console.log(fake.color()); 12 | console.log(); 13 | console.log(fake.fromArray(['apple', 'banana', 'cherry'])); 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # fake text and data generator 2 | 3 | From an article about *Lorem ipsum*: 4 | 5 | > It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text (...) 6 | 7 | And here's the problem: since *Lorem ipsum* is so widely used among developers and designers, it became recognizable and is as distracting as plain English text. 8 | 9 | Random text doesn't have this problem. Every time you fill database with fake data, this package creates text randomly generated from most popular English syllabes. The result is a not distracting, random Latin-looking piece of text that still has frequencies and qualities of a typical English article. 10 | 11 | Additional utility function allow you to create a fake user object. 12 | 13 | If you need more functionality, like fake web address or geographical location, please extend the package and send me a pull request. 14 | 15 | # Usage 16 | 17 | npm install --save fake-words 18 | 19 | 20 | # API 21 | 22 | 23 |   24 | 25 |   26 | 27 | ### `fake.word()` 28 | 29 | Returns a random word. 30 | 31 | *Sample result:* 32 | 33 | > Ingbelytion 34 | 35 | 36 |   37 | 38 |   39 | 40 | ### `fake.sentence([length])` 41 | 42 | *Sample result:* 43 | 44 | > Perexnation tily ly someveraticmer sontionamagment inesersinar. 45 | 46 | *Optional params:* 47 | 48 | - `length`: number of words in the sentence 49 | 50 | 51 |   52 | 53 |   54 | 55 | ### `fake.paragraph([length])` 56 | 57 | 58 | *Sample result:* 59 | 60 | > Agepro aldeadunar cones mere exintyecar ofsub refi icerse a muter. Terasedersmag citeden tertionscomiest com ed termenttain lotione uper terpre. Bleday fiu so manen ri. Extionoter ing dity artal erexi edi. De alre ieran altic dianati com. Bani naetordecom reerly comture u reti. Oyoraing con laenter perer com titer. Lyrec tlelec mened tionfulto condide enper miscom terty tionco enterthe ertle. Etuex ingtiesrily troi inter rilow exdisuget ingre lycon tanuperpro ialardisto exes. Inuausry allyaca disna ence aget. Af atias oalthe ac nessence dyob tiveraedi enmu conni. Addytionli bleestydi mocom com naoes. Ryture deu inter mansub. 61 | 62 | *Optional params:* 63 | 64 | - `length`: number of sentences in the paragraph 65 | 66 | 67 | 68 |   69 | 70 |   71 | 72 | ### `fake.user()` 73 | 74 | *Sample result:* 75 | 76 | { 77 | "firstName": "Kate", 78 | "lastName": "Belyto", 79 | "email": "kate@proespa.com", 80 | } 81 | 82 | 83 |   84 | 85 |   86 | 87 | ### `fake.color()` 88 | 89 | Returns a random named html color. 90 | 91 | *Sample result:* 92 | 93 | > navajowhite 94 | 95 | 96 |   97 | 98 |   99 | 100 | ### `fake.fromArray(customArray)` 101 | 102 | Selects a random element from provided array. 103 | 104 | *Example:* 105 | 106 | fake.fromArray(['banana', 'apple', 'strawberry', 'raspberry', 'pear']); 107 | // 'pear' 108 | 109 | 110 | 111 | 112 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | /* ------------------------------------------------------------ */ 2 | /* Source arrays */ 3 | /* ------------------------------------------------------------ */ 4 | 5 | 6 | /* Most common syllabes in English language */ 7 | var syllabes = [ 8 | 'the','ing','er','a','ly','ed','i','es','re','tion','in','e','con','y','ter','ex','al','de','com','o','di','en','an','ty','ry','u', 9 | 'ti','ri','be','per','to','pro','ac','ad','ar','ers','ment','or','tions','ble','der','ma','na','si','un','at','dis','ca','cal','man','ap', 10 | 'po','sion','vi','el','est','la','lar','pa','ture','for','is','mer','pe','ra','so','ta','as','col','fi','ful','get','low','ni','par','son', 11 | 'tle','day','ny','pen','pre','tive','car','ci','mo','an','aus','pi','se','ten','tor','ver','ber','can','dy','et','it','mu','no','ple','cu', 12 | 'fac','fer','gen','ic','land','light','ob','of','pos','tain','den','ings','mag','ments','set','some','sub','sur','ters','tu','af','au','cy','fa','im', 13 | 'li','lo','men','min','mon','op','out','rec','ro','sen','side','tal','tic','ties','ward','age','ba','but','cit','cle','co','cov','daq','dif','ence', 14 | 'ern','eve','hap','ies','ket','lec','main','mar','mis','my','nal','ness','ning','nu','oc','pres','sup','te','ted','tem','tin','tri','tro','up', 15 | ]; 16 | 17 | /* Popular names in several English-speaking countries */ 18 | var names = [ 19 | 'Abigail','Alice','Amelia','Angelina','Ann', 20 | 'Ashley','Avery','Barbara','Brianna','Camila', 21 | 'Chloe','Dorothy','Elizabeth','Ella','Emily', 22 | 'Emma','Fiona','Florence','Gabrielle','Haley', 23 | 'Hannah','Isabella','Jasmine','Jennifer','Jessica', 24 | 'Juliette','Kate','Leah','Lily','Linda', 25 | 'Lea','Madison','Makayla','Margaret','Maria', 26 | 'Mariana','Mary','Megan','Mia','Olivia', 27 | 'Patricia','Rachel','Samantha','Sarah','Sophie', 28 | 'Susan','Taylor','Valeria','Victoria','Zoe', 29 | 'Alexander','Anthony','Benjamin','Brandon','Carter', 30 | 'Charles','Charlie','Christian','Christopher','Daniel', 31 | 'David','Deven','Dylan','Elijah','Eric', 32 | 'Ethan','Felix','Gabriel','George','Harry', 33 | 'Hudson','Hunter','Jack','Jacob','James', 34 | 'Jason','Jayden','Jeremiah','John','Joseph', 35 | 'Joshua','Justin','Kevin','Liam','Logan', 36 | 'Lucas','Matthew','Michael','Neil','Noah', 37 | 'Oliver','Owen','Raphael','Richard','Robert', 38 | 'Ryan','Samuel','Thomas','Tyler','William' 39 | ]; 40 | 41 | /* Sample colors */ 42 | /* TODO: Split them to several palettes and allow choice of which palettes to use, ie. warm, cool, grays, greens, etc. */ 43 | var colors = [ 44 | 'antiquewhite', 'brown', 'chocolate', 'coral', 'crimson', 45 | 'darkgray', 'darkred', 'darkorange', 'darksalmon', 46 | 'firebrick', 'floralwhite', 'gainsboro', 'gold', 'goldenrod', 47 | 'gray', 'indianred', 'khaki', 'lightcoral', 'lightsalmon', 'lightyellow', 48 | 'maroon', 'mistyrose', 'navajowhite', 'mocassin', 'orange', 'orangered', 49 | 'peru', 'red', 'rosybrown', 'saddlebrown', 'sandybrown', 'sienna', 50 | 'silver', 'slategray', 'tan', 'tomato', 'teal', 'navy', 'black', 51 | ]; 52 | 53 | /* Domain suffixes */ 54 | var domains = [ 55 | '.net', '.org', '.edu', '.com', 56 | '.com', '.com', '.com', '.com', 57 | ]; 58 | 59 | /* Frequency table for word lengths */ 60 | var wordLengths = [ 61 | 1, 1, 62 | 2, 2, 2, 2, 2, 2, 2, 63 | 3, 3, 3, 3, 64 | 4, 4, 65 | 5 66 | ]; 67 | 68 | /* Frequency table for random syllabes */ 69 | var syllabeCounts = [ 70 | 10, 15, 20, 25, 71 | 30, 35, 40, 45, 72 | 50, 75, 100, 125, 73 | 150, 175, 175, 175, 74 | ]; 75 | 76 | 77 | /* ------------------------------------------------------------ */ 78 | /* Utility methods */ 79 | /* ------------------------------------------------------------ */ 80 | 81 | var capitalize = function(str) { 82 | return str.slice(0,1).toUpperCase() + str.slice(1).toLowerCase(); 83 | }; 84 | 85 | var getWord = function(min, max) { 86 | var length = wordLengths[Math.floor(Math.random() * 16)]; 87 | if(min && (length < min)) length = min; 88 | if(max && (length > max)) length = max; 89 | var word = ''; 90 | for(var i = 0; i < length; ++i) { 91 | var count = syllabeCounts[Math.floor(Math.random() * 16)]; 92 | word += syllabes[Math.floor(Math.random() * count)]; 93 | } 94 | return word; 95 | }; 96 | 97 | var randomElement = function(array) { 98 | return array[Math.floor(Math.random() * array.length)]; 99 | }; 100 | 101 | 102 | /* ---------- ---------- ---------- ---------- ---------- ---------- */ 103 | /* Exported methods */ 104 | /* ---------- ---------- ---------- ---------- ---------- ---------- */ 105 | 106 | var fake = { 107 | 108 | user: function() { 109 | var name = randomElement(names); 110 | return { 111 | firstName: name, 112 | lastName: capitalize(getWord(3)), 113 | email: (name + '@' + getWord(2) + randomElement(domains)).toLowerCase(), 114 | }; 115 | }, 116 | 117 | word: function() { 118 | return capitalize(getWord()); 119 | }, 120 | 121 | sentence: function(length) { 122 | if(!length) { 123 | var length = 4 + Math.floor(Math.random() * 8); 124 | } 125 | var ending = (Math.random() < 0.95) ? '.' : (Math.random() < 0.5) ? '!' : '?'; 126 | var result = capitalize(getWord()); 127 | for(var i = 1; i < length; ++i) { 128 | result += ' ' + getWord(); 129 | } 130 | return result + ending; 131 | }, 132 | 133 | paragraph: function(length) { 134 | if(!length) { 135 | length = 6 + Math.floor(Math.random() * 8); 136 | } 137 | var result = fake.sentence(); 138 | for(var i = 1; i < length; ++i) { 139 | result += ' ' + fake.sentence(); 140 | } 141 | return result; 142 | }, 143 | 144 | fromArray: function(array) { 145 | return randomElement(array); 146 | }, 147 | 148 | color: function() { 149 | return randomElement(colors); 150 | }, 151 | 152 | }; 153 | 154 | module.exports = fake; 155 | 156 | --------------------------------------------------------------------------------