Skip to content

Commit

Permalink
Merge pull request #70 from ndaidong/4.0.0rc1
Browse files Browse the repository at this point in the history
v4.0.0rc1
  • Loading branch information
ndaidong authored Jun 23, 2024
2 parents be32c0e + 23a258d commit 5f6b250
Show file tree
Hide file tree
Showing 34 changed files with 771 additions and 1,016 deletions.
2 changes: 0 additions & 2 deletions .eslintignore

This file was deleted.

118 changes: 0 additions & 118 deletions .eslintrc.json

This file was deleted.

61 changes: 22 additions & 39 deletions .github/workflows/ci-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,44 +12,27 @@ jobs:

strategy:
matrix:
node_version: [18.x, 20.x, 21.x]
deno-version: [1.44.4]

steps:
- uses: actions/checkout@v4

- name: setup Node.js v${{ matrix.node_version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node_version }}

- name: run npm scripts
run: |
npm install
npm run lint
npm run test
- name: Coveralls Parallel
uses: coverallsapp/github-action@v2
with:
flag-name: run-${{ join(matrix.*, '-') }}
parallel: true
github-token: ${{ secrets.GITHUB_TOKEN }}

- name: cache node modules
uses: actions/cache@v4
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
finish:
needs: test
if: ${{ always() }}
runs-on: ubuntu-latest
steps:
- name: Coveralls Finished
uses: coverallsapp/github-action@v2
with:
parallel-finished: true
carryforward: "run-18.x,run-20.x,run-21.x"
- name: Git Checkout Deno Module
uses: actions/checkout@v4
- name: Use Deno Version ${{ matrix.deno-version }}
uses: denoland/setup-deno@v1
with:
deno-version: ${{ matrix.deno-version }}
- name: format check
run: deno fmt --check mod.ts utils/* scripts/* tests/*
- name: run linter
run: deno lint mod.ts utils/* scripts/* tests/*
- name: run test
run: deno test --allow-all --coverage=cov/

- name: Generate coverage report
run: deno coverage --lcov cov > cov.lcov

- name: Upload coverage to Coveralls.io
uses: coverallsapp/github-action@v2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: cov.lcov
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,7 @@ coverage.lcov
yarn.lock
pnpm-lock.yaml
package-lock.json

npm
cov
cov.lcov
84 changes: 43 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# txtgen
Lightweight util for generating random sentences, paragraphs and articles in English. Inspired by [Sentencer](https://github.com/kylestetz/Sentencer) and [metaphorpsum.com](http://metaphorpsum.com/).

Lightweight util for generating random sentences, paragraphs and articles in
English. Inspired by [Sentencer](https://github.com/kylestetz/Sentencer) and
[metaphorpsum.com](http://metaphorpsum.com/).

[![NPM](https://badge.fury.io/js/txtgen.svg)](https://badge.fury.io/js/txtgen)
[![CI test](https://github.com/ndaidong/txtgen/workflows/ci-test/badge.svg)](https://github.com/ndaidong/txtgen/actions)
[![Coverage Status](https://coveralls.io/repos/github/ndaidong/txtgen/badge.svg)](https://coveralls.io/github/ndaidong/txtgen)
![CodeQL](https://github.com/ndaidong/txtgen/workflows/CodeQL/badge.svg)

# Demo
Expand All @@ -28,22 +30,20 @@ Lightweight util for generating random sentences, paragraphs and articles in Eng

- ES6 Module: [txtgen.esm.js](https://unpkg.com/txtgen/dist/txtgen.esm.js)
- CommonJS: [txtgen.js](https://unpkg.com/txtgen/dist/cjs/txtgen.js)
- For old browsers: [txtgen.min.js](https://unpkg.com/txtgen/dist/txtgen.min.js)

- For old browsers:
[txtgen.min.js](https://unpkg.com/txtgen/dist/txtgen.min.js)

## Usage

### Node.js:

```js
import {
sentence
} from 'txtgen'
import { sentence } from "txtgen";

// with CommonJS environment
// const { sentence } = require('txtgen/dist/cjs/txtgen.js')

sentence()
sentence();
```

### Browsers:
Expand All @@ -69,51 +69,54 @@ 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()`
- `.lorem([Number min [, Number max]])`

- `.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
- `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.

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.
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.
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:

```js
import {
addTemplates
} from 'txtgen'
import { addTemplates } from "txtgen";

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

addTemplates(templates)
addTemplates(templates);
```

Here are the available placeholders:
Expand All @@ -124,7 +127,6 @@ Here are the available placeholders:
- `adjective`
- `an_adjective`


### Lorem ipsum

Syntax:
Expand All @@ -138,10 +140,10 @@ lorem(Number min, Number max)// set the minimum/maximum number of words
Example:

```js
import { lorem } from 'txtgen'
import { lorem } from "txtgen";

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

## Test
Expand Down
Loading

0 comments on commit 5f6b250

Please sign in to comment.