Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update README #71

Merged
merged 1 commit into from
Jun 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 59 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,67 +6,80 @@ English. Inspired by [Sentencer](https://github.com/kylestetz/Sentencer) and

[![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

- [Want to see how it works?](https://ndaidong.github.io/txtgen/)

## Setup
## Setup & Usage

- Node.js
### Deno

```bash
npm i txtgen
```sh
deno add @ndaidong/txtgen

# pnpm
pnpm i txtgen
# npm (use any of npx, yarn dlx, pnpm dlx, or bunx)
npx jsr add @ndaidong/txtgen
```

```ts
import { sentence } from '@ndaidong/txtgen';
sentence();
```

In Deno, you can optionally use JSR packages without an install step using `jsr:` specifiers:

```ts
import { sentence } from 'jsr:@ndaidong/txtgen';
sentence();
```

# yarn
yarn add txtgen
```
You can still use `npm:` specifiers as before:

- CDN
```ts
import { sentence } from 'npm:txtgen';
sentence();
```

- 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)
Or import from esm.sh

## Usage
```ts
import { sentence } from 'https://esm.sh/txtgen';
sentence();
```

### Node.js:
### Node.js & Bun

```bash
npm i txtgen
# pnpm
pnpm i txtgen
# yarn
yarn add txtgen
# bun
bun add txtgen
```

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

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

sentence();
```

### Browsers:

Currently, ECMAScript modules work fine on almost all browsers:

```html
<script type="module">
import { sentence } from 'https://unpkg.com/txtgen/dist/txtgen.esm.js'
import { sentence } from 'https://unpkg.com/txtgen/esm/mod.js'
console.log(sentence())
</script>
```

With outdated browsers, we can use the traditional method:

```html
<script type="text/javascript" src="https://unpkg.com/txtgen/dist/txtgen.min.js"></script>

<script>
console.log(window.txtgen.sentence())
</script>
```

## APIs

- `.sentence()`
Expand Down Expand Up @@ -146,15 +159,26 @@ const phrase = lorem();
console.log(phrase); // => nisi blandit feugiat tempus imperdiet etiam eu mus augue
```

## Test
## Development

Since v4.x.x, we switched to [Deno](https://docs.deno.com/runtime/manual/) platform, and use [DNT](https://github.com/denoland/dnt) to build Node.js packages.

```bash
git clone https://github.com/ndaidong/txtgen.git
cd txtgen
npm install
npm test

# test
deno test

# build npm packages
deno task build

cd npm
node test_runner.js
```

# License

The MIT License (MIT)

---
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"version": "4.0.0rc1",
"name": "txtgen",
"version": "4.0.0rc1",
"description": "Util for generating random sentences, paragraphs and articles in English",
"homepage": "https://github.com/ndaidong/txtgen",
"repository": {
Expand Down
Loading