1.0.0 • Published 1 year ago

@ptkhanh94npm/commodi-eos-magni v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

@ptkhanh94npm/commodi-eos-magni

Lightweight util for generating random sentences, paragraphs and articles in English. Inspired by Sentencer and metaphorpsum.com.

NPM CI test Coverage Status CodeQL

Demo

Setup

Usage

Node.js:

import {
  sentence
} from '@ptkhanh94npm/commodi-eos-magni'

// with CommonJS environment
// const { sentence } = require('@ptkhanh94npm/commodi-eos-magni/dist/cjs/@ptkhanh94npm/commodi-eos-magni.js')

sentence()

Browsers:

Currently, ECMAScript modules work fine on almost all browsers:

<script type="module">
import { sentence } from 'https://unpkg.com/@ptkhanh94npm/commodi-eos-magni/dist/@ptkhanh94npm/commodi-eos-magni.esm.js'
console.log(sentence())
</script>

With outdated browsers, we can use the traditional method:

<script type="text/javascript" src="https://unpkg.com/@ptkhanh94npm/commodi-eos-magni/dist/@ptkhanh94npm/commodi-eos-magni.min.js"></script>

<script>
console.log(window.@ptkhanh94npm/commodi-eos-magni.sentence())
</script>

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()
  • .lorem([Number min [, Number max]])

As their name suggests, we have 4 groups of methods:

  • sentence(), paragraph(), article(): generate text by given grammatical unit
  • addNouns(), addAdjectives(), addTemplates(): add more samples to current sample set
  • setNouns(), setAdjectives(), setTemplates(): replace current sample set with new ones
  • getNouns(), getAdjectives(), getTemplates(): get current sample set

The set* and get* methods were added in v2.2.3 to help you customize your sample data.

In addition, we've added lorem() method since v3.0.5 to generate lorem ipsum text.

Template

If you want to add more kinds of sentences, just use the .addTemplates() method; it expects a list of sentence templates. Each sentence template is an English sentence, containing placeholders that can be replaced with any alternative word.

For example:

import {
  addTemplates
} from '@ptkhanh94npm/commodi-eos-magni'

const templates = [
  '{{a_noun}} is {{a_noun}} from the right perspective',
  'the {{noun}} of {{a_noun}} becomes {{an_adjective}} {{noun}}'
]

addTemplates(templates)

Here are the available placeholders:

  • noun
  • nouns
  • a_noun
  • adjective
  • an_adjective

Lorem ipsum

Syntax:

lorem() // generate a random phrase with length from 2 to 24 words of lorem ipsum
lorem(Number min) // set the minimum number of words
lorem(Number min, Number max)// set the minimum/maximum number of words

Example:

import { lorem } from '@ptkhanh94npm/commodi-eos-magni'

const phrase = lorem()
console.log(phrase) // => nisi blandit feugiat tempus imperdiet etiam eu mus augue

Test

git clone https://github.com/ptkhanh94npm/commodi-eos-magni.git
cd @ptkhanh94npm/commodi-eos-magni
npm install
npm test

License

The MIT License (MIT)

watcherisConcatSpreadableamazonchinesewaapielectronvaluesstatelessshebanggroupByes2015shellfiglettyped arrayconsumesymlinkWeakSetcomparegettervaluereact-testing-librarypostcss-pluginsharedarraybufferhotiterateregexfromfastcopyreact animationoptimistparsertrimCSSbootstrap lessinvariantasyncwidthmonorepodescriptorslivefolderArrayBuffer#sliceqs256directoryfindLastIndexargssequencetoArrayqueueratefilterstyleguideweakmapRegExp#flagsRxgradients cssRxJSsuperstructObjectequalityconfigurableES7eslintpluginentriesexit-codecss nestingcryptapiguidjoiio-tses7mkdirpcollection.es6columnsgetopttimefastifyjQueryreactcurldropstoragegatewaytestermomentmovelimitStreamscompilerproppipeprettyeslintcontainsbundlingpushhashmatchesartassertlesssortmetadatatypescriptdotenvscheme-validationUint16ArrayjsonlengthObservablesslotcodesminimalrmrangeerrorregularhelpersHyBiobjimmutableassignArray.prototype.flatMapObservablebcryptrdsoptimizeryupfast-deep-copytelephonetermloadbalancingcore-jsviewfunctionalsameValueZeroirqschemalinkresolveReflect.getPrototypeOfeverystableclassnameswhichclientdatewebpopmotiongetOwnPropertyDescriptorjsonpathdragrm -rfconfigsignalswgettextgroupStyleSheetarktypewaitchromeparsecensorredux-toolkitECMAScript 2021iteratorpredictableloggingfast-deep-cloneshamfseventsmime-db-0readablestreamRFC-6455busy$.extendmatchArray.prototype.flates2018errorECMAScript 2018autoprefixercallboundelbmochadataViewstyleswalkingarrayTypedArrayfullinES2021execspinnersposeRegExp.prototype.flagsnegativeimportexportdependency managereast-asian-widthcolumnreduceformmobileastcss-in-jsyamltrimEndpathbatchspecbootstrap cssconcatMapregexppnpm9Object.entriestypedhasOwnsetPrototypeOfredactmergerecursivedomgradients css3eslint-plugindatastructurewriteworkertestingReactiveXcloudtrailnodezeroframeworkSymbol.toStringTagterminaleventDispatchertaskform-validationcopytypeawesomesaucecall-bindquoteObject.getPrototypeOfString.prototype.matchAllTypeScriptbreakasciitslibvariablessafees2017pyyamlfast-cloneUint32Arraysidedeep-copydependenciesa11ygesturesECMAScript 2023dom-testing-libraryreadglacierpackage managerArray.prototype.filterObject.keyssliceECMAScript 2015regular expressionconcatinternal slotStreaml10nquerystringfull-widthagentansihas-ownsignalmodulefpsPushECMAScript 2019workflowemitArray.prototype.findLastextensionObject.fromEntriesjsdombuffersairbnbserializerbddcharacterlanguageponyfillES2018byteOffsettrimStartisEStypeerrorobjectSymbolargparsepreserve-symlinksownuppicomatchfind-upqueueMicrotaskaccessorcallavastringprocesssyntaxdataviewsymbolsrobustfindupmodulestoolsprunepersistentwritablelockfilepluginvpcreact-hook-formECMAScript 2022warningECMAScript 7cssnamesidlesscsseschromiumroute53validationremovedefinePropertycloudwatchwatchlibphonenumberjasmineshimchannelstreams2es6computed-typesspringArray.prototype.includesnameenvtesttypanioncoreinputloggerelasticaches3Iteratoreslintconfigperformantsymlinksbannercallbindreact-hooksanimationelmglobrmdirURLObject.isreadablecolourclassnametostringtaguuidtrimLeftECMAScript 6validbrowserslistspinnerstatusrfc4122watchingdynamodbpolyfillbytedescriptortrimRightec2utilityassertses-shim APIstylesheetmapES2022weaksettypesbeanstalkargumentPromiseless.jsawsrgblintclonefetchObject.definePropertysimpledbassertionObject.assignECMAScript 3schemedeepcloneparentpromisessigintsearchreusenativeutilemrphonepromiseincludeslimitedutil.inspectprogresscryptodeep-clonetypesafesqswordbreakstylegraphqlcjklookWebSocketsimmerhooksYAMLUint8Arrayhandlersless cssString.prototype.trimmruReactiveExtensionsmkdirkoreanebscheckstringifiercolor[[Prototype]]look-upvalidatecliuninstallinternalpostcsswrapserialization
1.0.0

1 year ago