{"id":17312608,"url":"https://github.com/ndaidong/txtgen","last_synced_at":"2025-04-07T06:07:32.747Z","repository":{"id":8809860,"uuid":"59826646","full_name":"ndaidong/txtgen","owner":"ndaidong","description":"Util for generating random sentences, paragraphs and articles in English","archived":false,"fork":false,"pushed_at":"2024-06-23T07:55:59.000Z","size":380,"stargazers_count":86,"open_issues_count":0,"forks_count":17,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-31T04:07:06.447Z","etag":null,"topics":["content-generator","generator","javascript","nodejs","random-text","text-generator"],"latest_commit_sha":null,"homepage":"https://ndaidong.github.io/txtgen","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ndaidong.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-05-27T10:29:33.000Z","updated_at":"2024-12-17T11:05:29.000Z","dependencies_parsed_at":"2024-06-18T14:01:11.321Z","dependency_job_id":"7e42d81e-eb6e-4e1e-90e5-8312e4fc8630","html_url":"https://github.com/ndaidong/txtgen","commit_stats":{"total_commits":70,"total_committers":5,"mean_commits":14.0,"dds":0.08571428571428574,"last_synced_commit":"be32c0e4e1a7e09eac042a72df34da58d96b25f7"},"previous_names":[],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ndaidong%2Ftxtgen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ndaidong%2Ftxtgen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ndaidong%2Ftxtgen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ndaidong%2Ftxtgen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ndaidong","download_url":"https://codeload.github.com/ndaidong/txtgen/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247601448,"owners_count":20964864,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["content-generator","generator","javascript","nodejs","random-text","text-generator"],"created_at":"2024-10-15T12:44:03.379Z","updated_at":"2025-04-07T06:07:32.723Z","avatar_url":"https://github.com/ndaidong.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# txtgen\n\nLightweight util for generating random sentences, paragraphs and articles in\nEnglish. Inspired by [Sentencer](https://github.com/kylestetz/Sentencer) and\n[metaphorpsum.com](http://metaphorpsum.com/).\n\n![CodeQL](https://github.com/ndaidong/txtgen/workflows/CodeQL/badge.svg)\n[![CI test](https://github.com/ndaidong/txtgen/workflows/ci-test/badge.svg)](https://github.com/ndaidong/txtgen/actions)\n[![Coverage Status](https://coveralls.io/repos/github/ndaidong/txtgen/badge.svg)](https://coveralls.io/github/ndaidong/txtgen)\n[![NPM](https://img.shields.io/npm/v/%40ndaidong%2Ftxtgen?color=32bb24)](https://www.npmjs.com/package/@ndaidong/txtgen)\n[![JSR](https://jsr.io/badges/@ndaidong/txtgen?color=32bb24)](https://jsr.io/@ndaidong/txtgen)\n\n# Demo\n\n- [Want to see how it works?](https://ndaidong.github.io/txtgen/)\n\n## Setup \u0026 Usage\n\n### Deno\n\nhttps://jsr.io/@ndaidong/txtgen\n\n```sh\ndeno add @ndaidong/txtgen\n\n# npm (use any of npx, yarn dlx, pnpm dlx, or bunx)\nnpx jsr add @ndaidong/txtgen\n```\n\n```ts\nimport { sentence } from \"@ndaidong/txtgen\";\n\nfor (let i = 0; i \u003c 5; i++) {\n  console.log(sentence());\n}\n```\n\nYou can use JSR packages without an install step using `jsr:` specifiers:\n\n```ts\nimport { sentence } from \"jsr:@ndaidong/txtgen\";\n\nfor (let i = 0; i \u003c 5; i++) {\n  console.log(sentence());\n}\n```\n\nYou can also use `npm:` specifiers as before:\n\n```ts\nimport { sentence } from \"npm:@ndaidong/txtgen\";\n\nfor (let i = 0; i \u003c 5; i++) {\n  console.log(sentence());\n}\n```\n\nOr import from esm.sh\n\n```ts\nimport { sentence } from \"https://esm.sh/@ndaidong/txtgen\";\n\nfor (let i = 0; i \u003c 5; i++) {\n  console.log(sentence());\n}\n```\n\n### Node.js \u0026 Bun\n\nhttps://www.npmjs.com/package/@ndaidong/txtgen\n\n```bash\nnpm i @ndaidong/txtgen\n# pnpm\npnpm i @ndaidong/txtgen\n# yarn\nyarn add @ndaidong/txtgen\n# bun\nbun add @ndaidong/txtgen\n```\n\n```js\nimport { sentence } from \"@ndaidong/txtgen\";\n\nfor (let i = 0; i \u003c 5; i++) {\n  console.log(sentence());\n}\n```\n\nYou can also use CJS style:\n\n```js\nconst { sentence } = require(\"@ndaidong/txtgen\");\n\nfor (let i = 0; i \u003c 5; i++) {\n  console.log(sentence());\n}\n```\n\n### Browsers:\n\n```html\n\u003cscript type=\"module\"\u003e\nimport { sentence } from \"https://esm.sh/@ndaidong/txtgen\";\n// import { sentence } from 'https://unpkg.com/@ndaidong/txtgen/esm/mod.js';\n\nfor (let i = 0; i \u003c 5; i++) {\n  console.log(sentence());\n}\n\u003c/script\u003e\n```\n\n## APIs\n\n- `.sentence()`\n- `.paragraph([Number totalSentences])`\n- `.article([Number totalParagraphs])`\n- `.addNouns(Array nouns)`\n- `.addAdjectives(Array adjectives)`\n- `.addTemplates(Array sentenceTemplates)`\n- `.setNouns(Array nouns)`\n- `.setAdjectives(Array adjectives)`\n- `.setTemplates(Array sentenceTemplates)`\n- `.getNouns()`\n- `.getAdjectives()`\n- `.getTemplates()`\n- `.lorem([Number min [, Number max]])`\n\nAs their name suggests, we have 4 groups of methods:\n\n- `sentence()`, `paragraph()`, `article()`: generate text by given grammatical\n  unit\n- `addNouns()`, `addAdjectives()`, `addTemplates()`: add more samples to current\n  sample set\n- `setNouns()`, `setAdjectives()`, `setTemplates()`: replace current sample set\n  with new ones\n- `getNouns()`, `getAdjectives()`, `getTemplates()`: get current sample set\n\nThe `set*` and `get*` methods were added in v2.2.3 to help you customize your\nsample data.\n\nIn addition, we've added `lorem()` method since v3.0.5 to generate lorem ipsum\ntext.\n\n### Template\n\nIf you want to add more kinds of sentences, just use the `.addTemplates()`\nmethod; it expects a list of sentence templates. Each sentence template is an\nEnglish sentence, containing placeholders that can be replaced with any\nalternative word.\n\nFor example:\n\n```js\nimport { addTemplates } from \"@ndaidong/txtgen\";\n\nconst templates = [\n  \"{{a_noun}} is {{a_noun}} from the right perspective\",\n  \"the {{noun}} of {{a_noun}} becomes {{an_adjective}} {{noun}}\",\n];\n\naddTemplates(templates);\n```\n\nHere are the available placeholders:\n\n- `noun`\n- `nouns`\n- `a_noun`\n- `adjective`\n- `an_adjective`\n\n### Lorem ipsum\n\nSyntax:\n\n```js\nlorem() // generate a random phrase with length from 2 to 24 words of lorem ipsum\nlorem(Number min) // set the minimum number of words\nlorem(Number min, Number max)// set the minimum/maximum number of words\n```\n\nExample:\n\n```js\nimport { lorem } from \"@ndaidong/txtgen\";\n\nconst phrase = lorem();\nconsole.log(phrase); // =\u003e nisi blandit feugiat tempus imperdiet etiam eu mus augue\n```\n\n## Development\n\nSince v4.x.x, we switched to [Deno](https://docs.deno.com/runtime/manual/)\nplatform, and use [DNT](https://github.com/denoland/dnt) to build Node.js\npackages.\n\n```bash\ngit clone https://github.com/ndaidong/txtgen.git\ncd txtgen\n\n# test\ndeno test\n\n# build npm packages\ndeno task build\n\ncd npm\nnode test_runner.js\n```\n\n# License\n\nThe MIT License (MIT)\n\n---\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fndaidong%2Ftxtgen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fndaidong%2Ftxtgen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fndaidong%2Ftxtgen/lists"}