Skip to content

Commit

Permalink
Merge pull request #64 from ndaidong/3.0.5
Browse files Browse the repository at this point in the history
v3.0.5
  • Loading branch information
ndaidong authored Mar 8, 2023
2 parents dc23567 + fe261ea commit 1db1503
Show file tree
Hide file tree
Showing 19 changed files with 229 additions and 47 deletions.
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
dist
118 changes: 118 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
{
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"env": {
"es6": true,
"node": true,
"jest": true
},
"globals": {},
"plugins": [],
"overrides": [],
"extends": ["eslint:recommended"],
"rules": {
"arrow-spacing": ["error", { "before": true, "after": true }],
"block-spacing": ["error", "always"],
"brace-style": ["error", "1tbs", { "allowSingleLine": true }],
"camelcase": ["error", {
"allow": ["^UNSAFE_"],
"properties": "never",
"ignoreGlobals": true
}],
"comma-dangle": ["error", {
"arrays": "always-multiline",
"objects": "always-multiline",
"imports": "never",
"exports": "never",
"functions": "never"
}],
"comma-spacing": ["error", { "before": false, "after": true }],
"eol-last": "error",
"eqeqeq": ["error", "always", { "null": "ignore" }],
"func-call-spacing": ["error", "never"],
"indent": [
"error",
2,
{
"MemberExpression": 1,
"FunctionDeclaration": {
"body": 1,
"parameters": 2
},
"SwitchCase": 1
}
],
"key-spacing": ["error", { "beforeColon": false, "afterColon": true }],
"keyword-spacing": ["error", { "before": true, "after": true }],
"lines-between-class-members": ["error", "always", { "exceptAfterSingleLine": true }],
"max-len": [
"error",
{
"code": 120,
"ignoreTrailingComments": true,
"ignoreComments": true,
"ignoreUrls": true
}
],
"max-lines": [
"error",
{
"max": 360,
"skipBlankLines": true,
"skipComments": false
}
],
"max-lines-per-function": [
"error",
{
"max": 250,
"skipBlankLines": true
}
],
"max-params": ["error", 3],
"no-array-constructor": "error",
"no-mixed-spaces-and-tabs": "error",
"no-multi-spaces": "error",
"no-multi-str": "error",
"no-multiple-empty-lines": [
"error",
{
"max": 1,
"maxEOF": 0
}
],
"no-restricted-syntax": [
"error",
"WithStatement",
"BinaryExpression[operator='in']"
],
"no-trailing-spaces": "error",
"no-use-before-define": [
"error",
{
"functions": true,
"classes": true,
"variables": false
}
],
"no-var": "warn",
"object-curly-spacing": ["error", "always"],
"padded-blocks": [
"error",
{
"blocks": "never",
"switches": "never",
"classes": "never"
}
],
"quotes": ["error", "single"],
"space-before-blocks": ["error", "always"],
"space-before-function-paren": ["error", "always"],
"space-infix-ops": "error",
"space-unary-ops": ["error", { "words": true, "nonwords": false }],
"space-in-parens": ["error", "never"],
"semi": ["error", "never"]
}
}
2 changes: 1 addition & 1 deletion .github/workflows/ci-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:

strategy:
matrix:
node_version: [14.x, 15.x, 16.x, 17.x, 18.x]
node_version: [14.x, 16.x, 18.x, 19.x]

steps:
- uses: actions/checkout@v2
Expand Down
5 changes: 5 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
coverage
.github
pnpm-lock.yaml
examples
26 changes: 21 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,10 @@ Lightweight util for generating random sentences, paragraphs and articles in Eng
[![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)
[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)

[![Deploy](https://button.deta.dev/1/svg)](https://go.deta.dev/deploy?repo=https://github.com/ndaidong/txtgen-deta)

# Demo

- [Want to see how it works?](https://ndaidong.github.io/txtgen/)
- [Deta service to generate text](https://txtgen.deta.dev/)

## Setup

Expand Down Expand Up @@ -85,6 +81,7 @@ console.log(window.txtgen.sentence())
- `.getNouns()`
- `.getAdjectives()`
- `.getTemplates()`
- `.lorem([Number min [, Number max]])`


As their name suggests, we have 4 groups of methods:
Expand All @@ -97,13 +94,13 @@ As their name suggests, we have 4 groups of methods:

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:

```js
Expand All @@ -128,6 +125,25 @@ Here are the available placeholders:
- `an_adjective`


### Lorem ipsum

Syntax:

```js
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:

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

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

## Test

```bash
Expand Down
18 changes: 9 additions & 9 deletions build.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const buildTime = (new Date()).toISOString()
const shortComment = [
`// ${pkg.name}@${pkg.version}, by ${pkg.author}`,
`built with esbuild at ${buildTime}`,
`published under ${pkg.license} license`
`published under ${pkg.license} license`,
].join(' - ')

const baseOpt = {
Expand All @@ -24,7 +24,7 @@ const baseOpt = {
charset: 'utf8',
target: ['es2020', 'node14'],
minify: true,
write: true
write: true,
}

const esmVersion = {
Expand All @@ -34,8 +34,8 @@ const esmVersion = {
mainFields: ['module'],
outfile: `dist/${pkg.name}.esm.js`,
banner: {
js: shortComment
}
js: shortComment,
},
}
buildSync(esmVersion)

Expand All @@ -46,15 +46,15 @@ const cjsVersion = {
mainFields: ['main'],
outfile: `dist/cjs/${pkg.name}.js`,
banner: {
js: shortComment
}
js: shortComment,
},
}
buildSync(cjsVersion)

const cjspkg = {
name: pkg.name + '-cjs',
version: pkg.version,
main: `./${pkg.name}.js`
main: `./${pkg.name}.js`,
}
writeFileSync(
'dist/cjs/package.json',
Expand All @@ -71,7 +71,7 @@ const iifeVersion = {
globalName: pkg.name,
outfile: `dist/${pkg.name}.min.js`,
banner: {
js: shortComment
}
js: shortComment,
},
}
buildSync(iifeVersion)
2 changes: 1 addition & 1 deletion cjs-eval.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// remove type=`module` from package.json first

const {
sentence
sentence,
} = require('./dist/cjs/txtgen.js')

console.log('sentence() // => ', sentence())
2 changes: 1 addition & 1 deletion dist/cjs/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "txtgen-cjs",
"version": "3.0.4",
"version": "3.0.5",
"main": "./txtgen.js"
}
Loading

0 comments on commit 1db1503

Please sign in to comment.