UNPKG

@noeldemartin/faker

Version:

Generate massive amounts of fake contextual data

4 lines (3 loc) 1.73 kB
"use strict";var i=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var p=Object.prototype.hasOwnProperty;var f=(s,r)=>{for(var e in r)i(s,e,{get:r[e],enumerable:!0})},u=(s,r,e,t)=>{if(r&&typeof r=="object"||typeof r=="function")for(let n of m(r))!p.call(s,n)&&n!==e&&i(s,n,{get:()=>r[n],enumerable:!(t=h(r,n))||t.enumerable});return s};var g=s=>u(i({},"__esModule",{value:!0}),s);var l={};f(l,{LoremModule:()=>a});module.exports=g(l);var o=require("../word/filterWordListByLength");class a{constructor(r){this.faker=r;for(const e of Object.getOwnPropertyNames(a.prototype))e==="constructor"||typeof this[e]!="function"||(this[e]=this[e].bind(this))}word(r={}){const e=typeof r=="number"?{length:r}:r;return this.faker.helpers.arrayElement((0,o.filterWordListByLength)({...e,wordList:this.faker.definitions.lorem.words}))}words(r=3){const e=[];for(let t=0;t<r;t++)e.push(this.word());return e.join(" ")}sentence(r){r==null&&(r=this.faker.datatype.number({min:3,max:10}));const e=this.words(r);return`${e.charAt(0).toUpperCase()+e.slice(1)}.`}slug(r){const e=this.words(r);return this.faker.helpers.slugify(e)}sentences(r,e=" "){r==null&&(r=this.faker.datatype.number({min:2,max:6}));const t=[];for(r;r>0;r--)t.push(this.sentence());return t.join(e)}paragraph(r=3){return this.sentences(r+this.faker.datatype.number(3))}paragraphs(r=3,e=` `){const t=[];for(r;r>0;r--)t.push(this.paragraph());return t.join(e)}text(){const r=["word","words","sentence","sentences","paragraph","paragraphs","lines"],e=this.faker.helpers.arrayElement(r);return`${this[e]()}`}lines(r){return r==null&&(r=this.faker.datatype.number({min:1,max:5})),this.sentences(r,` `)}}0&&(module.exports={LoremModule});