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

v4.0.1 #81

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
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
Loading