Skip to content

Commit

Permalink
Merge pull request #81 from ndaidong/4.0.1
Browse files Browse the repository at this point in the history
v4.0.1
  • Loading branch information
ndaidong authored Jun 23, 2024
2 parents 46636c5 + aceebe3 commit f848e10
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 14 deletions.
13 changes: 0 additions & 13 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,3 @@ jobs:
steps:
- uses: actions/checkout@v4
- run: npx jsr publish
- uses: denoland/setup-deno@v1
with:
deno-version: v1.x
- name: npm build
run: deno task build
- uses: actions/setup-node@v4
with:
node-version: '20.x'
registry-url: 'https://registry.npmjs.org'
- name: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: cd npm && npm publish --provenance --access public
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ndaidong/txtgen",
"version": "4.0.1-rc2",
"version": "4.0.1",
"description": "Util for generating random sentences, paragraphs and articles in English",
"homepage": "https://github.com/ndaidong/txtgen",
"repository": {
Expand Down
21 changes: 21 additions & 0 deletions mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ const makeSentenceFromTemplate = (): string => {
return make(rand(sentenceTemplates));
};

/**
* Generate a sentence with or without starting phrase
*
* @param ignoreStartingPhrase. Set to true to add a short phrase at the begining
* @returns A sentence
*/

export const sentence = (ignoreStartingPhrase: boolean = false): string => {
const phrase = ignoreStartingPhrase ? "" : randomStartingPhrase();
let s = phrase + makeSentenceFromTemplate();
Expand All @@ -75,6 +82,13 @@ export const sentence = (ignoreStartingPhrase: boolean = false): string => {
return s;
};

/**
* Generate a paragraph with given sentence count
*
* @param len Sentence count, 3 to 15
* @returns A paragraph
*/

export const paragraph = (len: number = 0): string => {
if (!len) {
len = randint(3, 10);
Expand All @@ -88,6 +102,13 @@ export const paragraph = (len: number = 0): string => {
return a.join(" ");
};

/**
* Generate an article with given paragraph count
*
* @param len Paragraph count, 3 to 15
* @returns An article
*/

export const article = (len: number = 0): string => {
if (!len) {
len = randint(3, 10);
Expand Down
2 changes: 2 additions & 0 deletions utils/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import { adjectives, nouns, vowels } from "./sample.ts";

const crypto = globalThis.crypto;

export const randint = (min: number = 0, max: number = 1e6): number => {
const byteArray = new Uint8Array(1);
crypto.getRandomValues(byteArray);
Expand Down
8 changes: 8 additions & 0 deletions utils/lorem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ const WordDict =

const WordDictSize = WordDict.length;

/**
* Generate a lorem ipsum
*
* @param min Minimal words count, default 2
* @param max Maximum words count, default 24
* @returns A sentence
*/

export const generate = (min: number = 2, max: number = 24): string => {
const size: number = randint(min, max);
const words: string[] = [];
Expand Down

0 comments on commit f848e10

Please sign in to comment.