diff --git a/README.md b/README.md index 51d5e2e..7b0f98c 100644 --- a/README.md +++ b/README.md @@ -49,13 +49,6 @@ import { sentence() ``` - -##### Note: - -> Since Node.js v14, ECMAScript modules [have became the official standard format](https://nodejs.org/docs/latest-v14.x/api/esm.html#esm_modules_ecmascript_modules). -> Just ensure that you are [using module system](https://nodejs.org/api/packages.html#determining-module-system) and enjoy with ES6 import/export syntax. - - ### Browsers: Currently, ECMAScript modules work fine on almost all browsers: @@ -79,18 +72,18 @@ console.log(window.txtgen.sentence()) ## APIs - - .sentence() - - .paragraph([Number totalSentences]) - - .article([Number totalParagraphs]) - - .addNouns(Array nouns) - - .addAdjectives(Array adjectives) - - .addTemplates(Array sentenceTemplates) - - .setNouns(Array nouns) - - .setAdjectives(Array adjectives) - - .setTemplates(Array sentenceTemplates) - - .getNouns() - - .getAdjectives() - - .getTemplates() + - `.sentence()` + - `.paragraph([Number totalSentences])` + - `.article([Number totalParagraphs])` + - `.addNouns(Array nouns)` + - `.addAdjectives(Array adjectives)` + - `.addTemplates(Array sentenceTemplates)` + - `.setNouns(Array nouns)` + - `.setAdjectives(Array adjectives)` + - `.setTemplates(Array sentenceTemplates)` + - `.getNouns()` + - `.getAdjectives()` + - `.getTemplates()` As their name suggests, we have 4 groups of methods: diff --git a/build.js b/build.js index b4f7f3b..9dd5b2a 100644 --- a/build.js +++ b/build.js @@ -1,7 +1,4 @@ -/** - * build.js - * @ndaidong -**/ +// build.js import { readFileSync, writeFileSync } from 'fs' import { execSync } from 'child_process' diff --git a/dist/cjs/package.json b/dist/cjs/package.json index 33e04df..f8376d6 100644 --- a/dist/cjs/package.json +++ b/dist/cjs/package.json @@ -1,5 +1,5 @@ { "name": "txtgen-cjs", - "version": "3.0.2", + "version": "3.0.3", "main": "./txtgen.js" } \ No newline at end of file diff --git a/dist/cjs/txtgen.js b/dist/cjs/txtgen.js index aa7deb0..ab46228 100644 --- a/dist/cjs/txtgen.js +++ b/dist/cjs/txtgen.js @@ -1,6 +1,6 @@ /** - * txtgen@3.0.2 - * built with esbuild at: 2022-06-03T08:39:59.112Z + * txtgen@3.0.3 + * built with esbuild at: 2022-08-10T15:41:36.738Z * repository: https://github.com/ndaidong/txtgen * maintainer: @ndaidong * License: MIT diff --git a/dist/txtgen.esm.js b/dist/txtgen.esm.js index ed0310c..617377b 100644 --- a/dist/txtgen.esm.js +++ b/dist/txtgen.esm.js @@ -1,6 +1,6 @@ /** - * txtgen@3.0.2 - * built with esbuild at: 2022-06-03T08:39:59.112Z + * txtgen@3.0.3 + * built with esbuild at: 2022-08-10T15:41:36.738Z * repository: https://github.com/ndaidong/txtgen * maintainer: @ndaidong * License: MIT diff --git a/dist/txtgen.min.js b/dist/txtgen.min.js index 4a06bba..beb216c 100644 --- a/dist/txtgen.min.js +++ b/dist/txtgen.min.js @@ -1,4 +1,4 @@ -// txtgen@3.0.2, by @ndaidong - built with esbuild at 2022-06-03T08:39:59.112Z - published under MIT license +// txtgen@3.0.3, by @ndaidong - built with esbuild at 2022-08-10T15:41:36.738Z - published under MIT license var txtgen=(()=>{var u=Object.defineProperty;var $=Object.getOwnPropertyDescriptor;var P=Object.getOwnPropertyNames;var L=Object.prototype.hasOwnProperty;var R=(e,t)=>{for(var n in t)u(e,n,{get:t[n],enumerable:!0})},W=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of P(t))!L.call(e,o)&&o!==n&&u(e,o,{get:()=>t[o],enumerable:!(r=$(t,o))||r.enumerable});return e};var C=e=>W(u({},"__esModule",{value:!0}),e);var I={};R(I,{addAdjectives:()=>v,addNouns:()=>b,addTemplates:()=>y,article:()=>H,getAdjectives:()=>z,getNouns:()=>j,getTemplates:()=>A,paragraph:()=>_,sentence:()=>M,setAdjectives:()=>x,setNouns:()=>w,setRandom:()=>h,setTemplates:()=>k});var a=["alligator","ant","bear","bee","bird","camel","cat","cheetah","chicken","chimpanzee","cow","crocodile","deer","dog","dolphin","duck","eagle","elephant","fish","fly","fox","frog","giraffe","goat","goldfish","hamster","hippopotamus","horse","kangaroo","kitten","lion","lobster","monkey","octopus","owl","panda","pig","puppy","rabbit","rat","scorpion","seal","shark","sheep","snail","snake","spider","squirrel","tiger","turtle","wolf","zebra","apple","apricot","banana","blackberry","blueberry","cherry","cranberry","currant","fig","grape","grapefruit","grapes","kiwi","kumquat","lemon","lime","melon","nectarine","orange","peach","pear","persimmon","pineapple","plum","pomegranate","prune","raspberry","strawberry","tangerine","watermelon"],i=["adaptable","adventurous","affable","affectionate","agreeable","alert","alluring","ambitious","ambitious","amiable","amicable","amused","amusing","boundless","brave","brave","bright","bright","broad-minded","calm","calm","capable","careful","charming","charming","cheerful","coherent","comfortable","communicative","compassionate","confident","conscientious","considerate","convivial","cooperative","courageous","courageous","courteous","creative","credible","cultured","dashing","dazzling","debonair","decisive","decisive","decorous","delightful","detailed","determined","determined","diligent","diligent","diplomatic","discreet","discreet","dynamic","dynamic","eager","easygoing","efficient","elated","eminent","emotional","enchanting","encouraging","endurable","energetic","energetic","entertaining","enthusiastic","enthusiastic","excellent","excited","exclusive","exuberant","exuberant","fabulous","fair","fair-minded","faithful","faithful","fantastic","fearless","fearless","fine","forceful","frank","frank","friendly","friendly","funny","funny","generous","generous","gentle","gentle","glorious","good","good","gregarious","happy","hard-working","harmonious","helpful","helpful","hilarious","honest","honorable","humorous","imaginative","impartial","impartial","independent","industrious","instinctive","intellectual","intelligent","intuitive","inventive","jolly","joyous","kind","kind","kind-hearted","knowledgeable","level","likeable","lively","lovely","loving","loving","loyal","lucky","mature","modern","modest","neat","nice","nice","obedient","optimistic","painstaking","passionate","patient","peaceful","perfect","persistent","philosophical","pioneering","placid","placid","plausible","pleasant","plucky","plucky","polite","powerful","practical","pro-active","productive","protective","proud","punctual","quick-witted","quiet","quiet","rational","receptive","reflective","reliable","relieved","reserved","resolute","resourceful","responsible","rhetorical","righteous","romantic","romantic","sedate","seemly","selective","self-assured","self-confident","self-disciplined","sensible","sensitive","sensitive","shrewd","shy","silly","sincere","sincere","skillful","smiling","sociable","splendid","steadfast","stimulating","straightforward","successful","succinct","sympathetic","talented","thoughtful","thoughtful","thrifty","tidy","tough","tough","trustworthy","unassuming","unbiased","understanding","unusual","upbeat","versatile","vigorous","vivacious","warm","warmhearted","willing","willing","wise","witty","witty","wonderful"],m=["a","e","i","o","u","y"],l=["however, {{nouns}} have begun to rent {{nouns}} over the past few months, specifically for {{nouns}} associated with their {{nouns}}"],f=["to be more specific, ","in recent years, ","however, ","by the way","of course, ","some assert that ","if this was somewhat unclear, ","unfortunately, that is wrong; on the contrary, ","it's very tricky, if not impossible, ","this could be, or perhaps ","this is not to discredit the idea that ","we know that ","it's an undeniable fact, really; ","framed in a different way, ","what we don't know for sure is whether or not ","as far as we can estimate, ","as far as he is concerned, ","the zeitgeist contends that ","though we assume the latter, ","far from the truth, ","extending this logic, ","nowhere is it disputed that ","in modern times ","in ancient times ","recent controversy aside, ","washing and polishing the car,","having been a gymnast, ","after a long day at school and work, ","waking to the buzz of the alarm clock, ","draped neatly on a hanger, ","shouting with happiness, "],p=(e=[],t=[])=>[...new Set([...e,...t])],b=(e=[])=>(a=p(a,e),a.length),v=(e=[])=>(i=p(i,e),i.length),y=(e=[])=>(l=p(l,e),l.length),w=(e=[])=>(a=[...new Set([...e])],a.length),x=(e=[])=>(i=[...new Set([...e])],i.length),k=(e=[])=>(l=[...new Set([...e])],l.length),j=()=>[...a],z=()=>[...i],A=()=>[...l];var N,h=e=>{N=e};h(Math.random);var d=()=>N(),c=(e,t)=>{let n=e,r=t-e+1;return Math.floor(d()*r)+n},s=e=>{let t;for(;!t;)t=e[c(0,e.length-1)];return t},S=()=>{let e=".......!?!?;...".split("");return s(e)},F=e=>e.endsWith("s")?e:(e.match(/(ss|ish|ch|x|us)$/)?e+="e":e.endsWith("y")&&!m.includes(e.charAt(e.length-2))&&(e=e.slice(0,e.length-1),e+="ie"),e+"s"),T=e=>{let t="a";return e.match(/^(a|e|heir|herb|hour|i|o)/)&&(t="an"),`${t} ${e}`},q={noun:()=>s(a),a_noun:()=>T(s(a)),nouns:()=>F(s(a)),adjective:()=>s(i),an_adjective:()=>T(s(i))};var U=["noun","a_noun","nouns","adjective","an_adjective"],B=e=>e.replace(/^[\s\xa0]+|[\s\xa0]+$/g,"").replace(/\r?\n|\r/g," ").replace(/\s\s+|\r/g," "),D=e=>{let t=e,n=e.match(/\{\{(.+?)\}\}/g);if(n&&n.length)for(let r=0;rd()<.33?s(f):"",G=()=>D(s(l));var M=()=>{let t=E()+G();return t=t.charAt(0).toUpperCase()+t.slice(1),t+=S(),t},_=(e=0)=>{e||(e=c(3,10));let t=Math.min(e,15),n=[];for(;n.length{e||(e=c(3,10));let t=Math.min(e,15),n=[];for(;n.length ', sentence()) +console.log('Generate sentence ') +console.log('-'.repeat(100)) +console.log(sentence()) +console.log('-'.repeat(100)) + +console.log('Generate paragraph ') +console.log('+'.repeat(100)) +console.log(paragraph()) +console.log('+'.repeat(100)) + +console.log('Generate article ') +console.log('*'.repeat(100)) +console.log(article()) +console.log('*'.repeat(100)) diff --git a/package.json b/package.json index 6716554..8c48480 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "version": "3.0.2", + "version": "3.0.3", "name": "txtgen", "description": "Util for generating random sentences, paragraphs and articles in English", "homepage": "http://ndaidong.github.io/txtgen", @@ -8,9 +8,7 @@ "url": "https://github.com/ndaidong/txtgen" }, "author": "@ndaidong", - "main": "./dist/cjs/txtgen.js", - "module": "./src/main.js", - "browser": "./dist/txtgen.min.js", + "main": "./src/main.js", "type": "module", "engines": { "node": ">= 14" @@ -19,7 +17,7 @@ "dtslint": "dtslint types", "lint": "standard .", "pretest": "npm run lint", - "test": "NODE_ENV=test NODE_OPTIONS=--experimental-vm-modules jest --verbose --coverage=true --unhandled-rejections=strict --detectOpenHandles --env=jsdom", + "test": "NODE_ENV=test NODE_OPTIONS=--experimental-vm-modules jest --coverage=true --env=jsdom", "build": "node build.js src/main.js", "eval": "node eval", "reset": "node reset" diff --git a/reset.js b/reset.js index c1e5032..40572ac 100644 --- a/reset.js +++ b/reset.js @@ -1,7 +1,5 @@ -/** - * reset.js - * @ndaidong -**/ +// reset.js +// to clean generated content import { existsSync, diff --git a/src/main.js b/src/main.js index d266e81..871765a 100755 --- a/src/main.js +++ b/src/main.js @@ -1,7 +1,4 @@ -/** - * txtgen - * @ndaidong -**/ +// main import { sentenceTemplates,