From aceebe3bee54b210328e66674396ab6391846c60 Mon Sep 17 00:00:00 2001 From: Dong Nguyen Date: Sun, 23 Jun 2024 14:49:59 +0700 Subject: [PATCH] v4.0.1 - Auto publish to JSR - Add some docs --- .github/workflows/publish.yml | 13 ------------- deno.json | 2 +- mod.ts | 21 +++++++++++++++++++++ utils/helper.ts | 2 ++ utils/lorem.ts | 8 ++++++++ 5 files changed, 32 insertions(+), 14 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 9c77164..b1c0ff2 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -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 diff --git a/deno.json b/deno.json index a60eb99..ed44b00 100644 --- a/deno.json +++ b/deno.json @@ -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": { diff --git a/mod.ts b/mod.ts index 770162f..bba8948 100644 --- a/mod.ts +++ b/mod.ts @@ -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(); @@ -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); @@ -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); diff --git a/utils/helper.ts b/utils/helper.ts index 77cb36f..b598724 100644 --- a/utils/helper.ts +++ b/utils/helper.ts @@ -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); diff --git a/utils/lorem.ts b/utils/lorem.ts index a970b12..6e04782 100644 --- a/utils/lorem.ts +++ b/utils/lorem.ts @@ -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[] = [];