-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from Benoit-Welsch/Feat/better-template
Feat/better template
- Loading branch information
Showing
10 changed files
with
426 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ src/ | |
|
||
# Ignore bun files | ||
build.mjs | ||
genDoc.ts | ||
bun.lockb | ||
tsconfig.json | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]+)*$/); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`; | ||
}; |
Oops, something went wrong.