Skip to content

Commit

Permalink
Merge pull request #10 from Benoit-Welsch/Feat/better-template
Browse files Browse the repository at this point in the history
Feat/better template
  • Loading branch information
Benoit-Welsch committed Dec 21, 2023
2 parents 1cc81b3 + d801819 commit 588961d
Show file tree
Hide file tree
Showing 10 changed files with 426 additions and 8 deletions.
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ src/

# Ignore bun files
build.mjs
genDoc.ts
bun.lockb
tsconfig.json

Expand Down
13 changes: 13 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

- [Check](#check)
- [Csv](#csv)
- [Gen](#gen)
- [Parser](#parser)
- [Queue](#queue)
- [Scanner](#scanner)
Expand Down Expand Up @@ -74,6 +75,18 @@ const csv2 = CSV.readString('name,age\r\nJohn,20\r\nJane,21\r\nJack,22', ',');
csv2.toString('|');
```

### Gen

Generate pseudo-random data

#### randomName

```typescript
import { Gen } from '@lv00/toolkit';

const newName = Gen.randomName(); // antonelli-xenodochial
```

### Parser

Parse data to object.
Expand Down
10 changes: 6 additions & 4 deletions build.mjs
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import dts from 'bun-plugin-dts';
import { Scanner } from './src';
import path from 'path';
import fs from 'fs/promises';

await Bun.build({
entrypoints: ['./src/index.ts'],
outDir: './dist',
outDir: './dist/',
target: 'bun',
minify: true,
plugins: [dts()],
}).catch((e) => {
console.error(e);
process.exit(1);
}).then(() => {
console.log('build done');
});

// Scanner.readFolder("./src").folders.map(async (f) => {
Expand Down
Binary file modified bun.lockb
Binary file not shown.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"version": "1.1.5",
"version": "1.1.6",
"name": "@lv00/toolkit",
"module": "./dist/index.js",
"type": "module",
"scripts": {
"build": "bun run build.mjs",
"doc": "bun run genDoc.ts",
"build": "bun build.mjs && bun build src/index.ts --outfile=dist/index.js --target=bun --minify",
"doc": "bun genDoc.ts",
"format": "prettier --write \"src/**/*.ts\" --single-quote --trailing-comma all --tab-width 2",
"format:md":"prettier --write \"**/*.md\" --single-quote --trailing-comma all --tab-width 2",
"format:md": "prettier --write \"**/*.md\" --single-quote --trailing-comma all --tab-width 2",
"prepublish": "bun doc && bun format:md"
},
"devDependencies": {
Expand Down
11 changes: 11 additions & 0 deletions src/Gen/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
### Gen

Generate pseudo-random data

#### randomName

```typescript
import { Gen } from '@lv00/toolkit';

const newName = Gen.randomName(); // antonelli-xenodochial
```
22 changes: 22 additions & 0 deletions src/Gen/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { describe, it, expect } from 'bun:test';
import { randomName } from './index';

describe('randomName', () => {
it('should generate a random name with default options', () => {
const name = randomName();
expect(typeof name).toBe('string');
expect(name).not.toBe('');
expect(name).toMatch(/^[a-z]+(-[a-z]+)*$/);
});

it('should generate a random name with custom separator', () => {
const name = randomName('_');
expect(name.includes('_')).toBe(true);
expect(name).toMatch(/^[a-z]+(_[a-z]+)*$/);
});

it('should generate a random name with capitalized words', () => {
const name = randomName('-', true);
expect(name).toMatch(/^[A-Z][a-z]+(-[A-Z][a-z]+)*$/);
});
});
16 changes: 16 additions & 0 deletions src/Gen/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { famousName, word } from './list';

export const randomName = (serperator = '-', capitalize = false) => {
let randomFamousName =
famousName[Math.floor(Math.random() * famousName.length)];
let randomWord = word[Math.floor(Math.random() * word.length)];

if (capitalize) {
const capitalizeString = (text: string) => {
return text.charAt(0).toUpperCase() + text.slice(1);
};
randomFamousName = capitalizeString(randomFamousName);
randomWord = capitalizeString(randomWord);
}
return `${randomFamousName}${serperator}${randomWord}`;
};
Loading

0 comments on commit 588961d

Please sign in to comment.