Skip to content

Commit

Permalink
Cleanup typedoc
Browse files Browse the repository at this point in the history
- Update typedoc configuration
  - Ignore private / internal members
  - Use dist folder as output
- Add examples
- Update turbo configuration
  - Run build before generating documentation
  • Loading branch information
kitsuyui committed Dec 28, 2024
1 parent 7e5bf41 commit d94540e
Show file tree
Hide file tree
Showing 17 changed files with 171 additions and 30 deletions.
8 changes: 7 additions & 1 deletion .config/typedoc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
/** @type {import('typedoc').TypeDocOptions} */
module.exports = {
entryPoints: ['../packages/**/src/*.ts'],
entryPoints: ['../packages/**/dist/index.d.ts'],
out: '../build/typedocs',
exclude: [
'**/node_modules/**',
'**/*.spec.ts',
'**/*.test.ts',
'**/examples/**',
],
}
4 changes: 1 addition & 3 deletions .github/workflows/typedoc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ jobs:

- run: pnpm install

- run: |
pnpm build
pnpm typedoc
- run: pnpm typedoc

- uses: peaceiris/actions-gh-pages@v4
with:
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"format": "biome check --write ./",
"lint": "biome check ./",
"test": "jest --coverage",
"typedoc": "typedoc"
"typedoc": "turbo run typedoc",
"typedoc:server": "python3 -m http.server --directory build/typedocs"
},
"devDependencies": {
"@biomejs/biome": "^1.9.4",
Expand Down
10 changes: 10 additions & 0 deletions packages/hello/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
/**
* Returns a greeting message.
* @example
* ```ts
* import { hello } from '@kitsuyui/hello'
* hello() // => 'Hello, world!'
* ```
* @returns {string} The greeting message.
*/
export function hello(): string {
Expand All @@ -8,6 +13,11 @@ export function hello(): string {

/**
* Prints a greeting message.
* @example
* ```ts
* import { printHello } from '@kitsuyui/hello'
* printHello() // => 'Hello, world!'
* ```
*/
export function printHello(): void {
console.log(hello())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import fs from 'node:fs'
import { type WaveParameter, uintToRGB } from './src/'
import { type WaveParameter, uintToRGB } from '../src/'

const main = () => {
const satuationParameter = {
Expand Down
2 changes: 1 addition & 1 deletion packages/incremental-color-palette/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"scripts": {
"build": "tsup src/index.ts --clean",
"dev": "pnpm build --watch",
"example": "tsx example.ts"
"example": "tsx examples/example.ts"
},
"exports": {
".": {
Expand Down
7 changes: 3 additions & 4 deletions packages/incremental-color-palette/src/colorPalette.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,9 @@ export const uintToBrightness = (
/**
* Return a value between min and max by using sin wave.
* @param rad
* @param min
* @param max
* @param frequency
* @param phase
* @param waveParameter.range [min, max] of the return value
* @param waveParameter.frequency
* @param waveParameter.phase
* @returns min <= return value <= max
*/
export const waveInRange = (
Expand Down
4 changes: 2 additions & 2 deletions packages/luxon-ext/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ export const toHumanDurationWithTemporal = (

/**
* Convert the duration between two DateTimes to a human readable format
* @param start
* @param end
* @param begin The beginning DateTime
* @param end The ending DateTime
* @param opts
* @returns
*/
Expand Down
18 changes: 15 additions & 3 deletions packages/mymath/src/array/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
/**
* Sum of all values in the array
* Example: sum([1, 2, 3, 4]) => 10
* If the array is empty, it returns 0 (0 is identity element for addition)
* @example
* ```ts
* import { sum } from '@kitsuyui/mymath'
* sum([1, 2, 3, 4]) // => 10
* ```
* @param values
* @returns sum of all values
*/
Expand All @@ -15,8 +19,12 @@ export const sum = (values: number[]): number => {

/**
* Product of all values in the array
* Example: product([1, 2, 3, 4]) => 24
* If the array is empty, it returns 1 (1 is identity element for multiplication)
* @example
* ```ts
* import { product } from '@kitsuyui/mymath'
* product([1, 2, 3, 4]) // => 24
* ```
* @param values
* @returns product of all values
*/
Expand All @@ -30,8 +38,12 @@ export const product = (values: number[]): number => {

/**
* Average of all values in the array
* Example: average([1, 2, 3, 4]) => 2.5
* If the array is empty, it returns 0 or the defaultValue
* @example
* ```ts
* import { average } from '@kitsuyui/mymath'
* average([1, 2, 3, 4]) // => 2.5
* ```
* @param values
* @param defaultValue
* @returns average of all values
Expand Down
22 changes: 16 additions & 6 deletions packages/mymath/src/clamp.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
/**
* Clamps a value between a minimum and maximum value
* Example: clamp(5, [10, 20]) returns 10
* Example: clamp(15, [10, 20]) returns 15
* Example: clamp(25, [10, 20]) returns 20
*
* @example
* ```ts
* clamp(5, [10, 20]) // => 10
* ```
* @example
* ```ts
* clamp(15, [10, 20]) // => 15
* ```
* @example
* ```ts
* clamp(25, [10, 20]) // => 20
* ```
* @param value
* @param min
* @param max
* @param range [min, max]
* @returns The clamped value
*/
export const clamp = (value: number, [min, max]: [number, number]): number => {
export const clamp = (value: number, range: [number, number]): number => {
const [min, max] = range
return Math.min(Math.max(value, min), max)
}
13 changes: 12 additions & 1 deletion packages/mymath/src/log/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
/**
* Returns the logarithm of a number with a specified base
* @example
* ```ts
* import { logOfBase } from '@kitsuyui/mymath'
* logOfBase(2, 8) // => 3
* ```
* @param base base of the logarithm
* @param input value to the function
* @param x value to the function
* @returns the logarithm of x with the specified base
*/
export const logOfBase = (base: number, x: number) => {
Expand All @@ -12,6 +17,12 @@ type NumberToNumberFunction = (x: number) => number

/**
* Returns a function that computes the logarithm of a number with a specified base
* @example
* ```ts
* import { logFnOfBase } from '@kitsuyui/mymath'
* const log2 = logFnOfBase(2)
* log2(8) // => 3
* ```
* @param base base of the logarithm
* @returns a function that computes the logarithm of a number with the specified base
*/
Expand Down
5 changes: 5 additions & 0 deletions packages/mymath/src/sigmoid/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
/**
* Sigmoid function
* @example
* ```ts
* import { sigmoid } from '@kitsuyui/mymath'
* sigmoid(0) // => 0.5
* ```
* @param x input value to the function
* @returns the output of the sigmoid function
*/
Expand Down
6 changes: 6 additions & 0 deletions packages/string/src/capitalization/cases/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ export type Case = (typeof ALL_CASES)[number]

/**
* Check if a string is a valid Case Name
* @example
* ```ts
* import { isValidCaseName } from 'string'
* isValidCaseName('kebab-case') // => true
* isValidCaseName('kebab_case') // => false
* ```
* @param caseText
* @returns
*/
Expand Down
17 changes: 17 additions & 0 deletions packages/string/src/capitalization/convert/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,23 @@ const isValidCase = (caseText: string): caseText is Case => {
return ALL_CASES.includes(caseText as Case)
}

/**
* Convert the text to the specified case
* @example
* ```ts
* import { convertCase } from '@kitsuyui/string'
* convertCase('hello world', 'kebab-case') // => 'hello-world'
* convertCase('hello world', 'snake_case') // => 'hello_world'
* convertCase('hello world', 'space separated') // => 'hello world'
* convertCase('hello world', 'camelCase') // => 'helloWorld'
* convertCase('hello world', 'UpperCamelCase') // => 'HelloWorld'
* convertCase('hello world', 'lowerCamelCase') // => 'helloWorld'
* convertCase('hello world', 'PascalCase') // => 'HelloWorld'
* ```
* @param text
* @param toCase
* @returns
*/
export const convertCase = (text: string, toCase: Case): string => {
if (!isValidCase(toCase)) {
throw new Error(`Invalid Case: ${toCase}`)
Expand Down
70 changes: 64 additions & 6 deletions packages/string/src/capitalization/join/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
import { type Case, isValidCaseName } from '../cases'

/**
* Join words into a single string with the specified case
* @example
* ```ts
* import { joinWords } from 'string'
* joinWords(['hello', 'world'], 'kebab-case') // => 'hello-world'
* joinWords(['hello', 'world'], 'snake_case') // => 'hello_world'
* ```
*/
export const joinWords = (words: string[], toCase: Case): string => {
if (!toCase) {
throw new Error('Case is required')
Expand Down Expand Up @@ -41,6 +50,11 @@ export const joinWords = (words: string[], toCase: Case): string => {

/**
* Join words into a single string with kebab case
* @example
* ```ts
* import { intoKebabCase } from 'string'
* intoKebabCase(['hello', 'world']) // => 'hello-world'
* ```
* @param words
* @returns
*/
Expand All @@ -51,6 +65,11 @@ export const intoKebabCase = (words: string[]): string => {

/**
* Join words into a single string with snake case
* @example
* ```ts
* import { intoSnakeCase } from 'string'
* intoSnakeCase(['hello', 'world']) // => 'hello_world'
* ```
* @param words
* @returns
*/
Expand All @@ -61,6 +80,11 @@ export const intoSnakeCase = (words: string[]): string => {

/**
* Join words into a single string with space separator
* @example
* ```ts
* import { intoSpaceSeparated } from 'string'
* intoSpaceSeparated(['hello', 'world']) // => 'hello world'
* ```
*/
export const intoSpaceSeparated = (words: string[]): string => {
const space = words.join(' ')
Expand All @@ -69,6 +93,11 @@ export const intoSpaceSeparated = (words: string[]): string => {

/**
* Join words into a single string with all caps
* @example
* ```ts
* import { intoAllCaps } from 'string'
* intoAllCaps(['hello', 'world']) // => 'HELLO WORLD'
* ```
*/
export const intoAllCaps = (words: string[]): string => {
const caps = words.map((word) => word.toUpperCase()).join(' ')
Expand All @@ -77,6 +106,11 @@ export const intoAllCaps = (words: string[]): string => {

/**
* Join words into a single string with screaming snake case (MACRO_CASE)
* @example
* ```ts
* import { intoScreamingSnakeCase } from 'string'
* intoScreamingSnakeCase(['hello', 'world']) // => 'HELLO_WORLD'
* ```
*/
export const intoScreamingSnakeCase = (words: string[]): string => {
const snake = words.map((word) => word.toUpperCase()).join('_')
Expand All @@ -85,6 +119,11 @@ export const intoScreamingSnakeCase = (words: string[]): string => {

/**
* Join words into a single string with train case
* @example
* ```ts
* import { intoTrainCase } from 'string'
* intoTrainCase(['hello', 'world']) // => 'Hello-World'
* ```
*/
export const intoTrainCase = (words: string[]): string => {
const train = words.map(capitalize).join('-')
Expand All @@ -93,6 +132,11 @@ export const intoTrainCase = (words: string[]): string => {

/**
* Join words into a single string with flat case
* @example
* ```ts
* import { intoFlatCase } from 'string'
* intoFlatCase(['hello', 'world']) // => 'helloworld'
* ```
*/
export const intoFlatCase = (words: string[]): string => {
const flat = words.join('')
Expand All @@ -101,6 +145,11 @@ export const intoFlatCase = (words: string[]): string => {

/**
* Join words into a single string with dot separator
* @example
* ```ts
* import { intoDotSeparated } from 'string'
* intoDotSeparated(['hello', 'world']) // => 'hello.world'
* ```
*/
export const intoDotSeparated = (words: string[]): string => {
const dot = words.join('.')
Expand All @@ -109,8 +158,11 @@ export const intoDotSeparated = (words: string[]): string => {

/**
* Join words into a single string with Upper Camel Case (Pascal Case)
* @param words
* @returns
* @example
* ```ts
* import { intoUpperCamelCase } from 'string'
* intoUpperCamelCase(['hello', 'world']) // => 'HelloWorld'
* ```
*/
export const intoUpperCamelCase = (words: string[]): string => {
const camel = words.map(capitalize).join('')
Expand All @@ -119,8 +171,11 @@ export const intoUpperCamelCase = (words: string[]): string => {

/**
* Join words into a single string with Lower Camel Case
* @param words
* @returns
* @example
* ```ts
* import { intoLowerCamelCase } from 'string'
* intoLowerCamelCase(['hello', 'world']) // => 'helloWorld'
* ```
*/
export const intoLowerCamelCase = (words: string[]): string => {
const camel = words
Expand All @@ -131,8 +186,11 @@ export const intoLowerCamelCase = (words: string[]): string => {

/**
* Capitalize a word
* @param word
* @returns
* @example
* ```ts
* import { capitalize } from 'string'
* capitalize('hello') // => 'Hello'
* ```
*/
const capitalize = (word: string): string => {
return word.charAt(0).toUpperCase() + word.slice(1)
Expand Down
Loading

0 comments on commit d94540e

Please sign in to comment.