Skip to content

Commit

Permalink
refactor(functions): improve naming and update JSDoc
Browse files Browse the repository at this point in the history
  • Loading branch information
gooddevil79 authored and ASafaeirad committed Nov 4, 2024
1 parent 46a6f6e commit ccefd28
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 162 deletions.
2 changes: 1 addition & 1 deletion docs/pages/function/_meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
"sleep": "sleep",
"throttle": "throttle",
"try-or": "tryOr",
"seconds-to-time": "seconds-to-time"
"format-seconds": "format-seconds"
}
70 changes: 70 additions & 0 deletions docs/pages/function/format-seconds.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@

# formatSeconds

The `formatSeconds` function is designed to convert a given number of seconds into a human-readable time string.
By accepting a specified format, this function allows for flexible output options, such as displaying time in hours, minutes, and seconds, or just in minutes and seconds. Whether you need to present durations in a detailed format like `hh:mm:ss` or a more concise `mm:ss`, this function caters to various use cases in applications that require time representation.


### Import

```typescript
import { formatSeconds } from '@fullstacksjs/toolbox';
```

### Signature

```typescript
function formatSeconds(
durationInSeconds: number,
options
): string;
```

## Parameters

- **`durationInSeconds`** (`number`): The total number of seconds to be converted.
- **`options`** (`{ format: 'hh:mm:ss' | 'hh:mm' | 'mm:ss' }`): The desired output format.

## Returns

- **`string`**: The formatted time string based on the specified format.

## Examples

### Formatting to `hh:mm:ss`

```typescript
const time1 = formatSeconds(3661, { format: 'hh:mm:ss' });
// Output: '01:01:01'
```

### Formatting to `hh:mm`

```typescript
const time2 = formatSeconds(3661, { format: 'hh:mm' });
// Output: '01:01'
```

### Formatting to `mm:ss`

```typescript
const time3 = formatSeconds(61, { format: 'mm:ss' });
// Output: '01:01'
```

### Formatting Zero Seconds

```typescript
const time4 = formatSeconds(0, { format: 'mm:ss' });
// Output: '00:00'
```

## Error Handling

If an invalid format is provided, the function will throw an error:

```typescript
formatSeconds(120, { format: 'ss:ss:ss' });
// 'Invalid format: 'ss:ss:ss'. Accepted formats are 'hh:mm:ss', 'hh:mm', or 'mm:ss'.'
```

85 changes: 0 additions & 85 deletions docs/pages/function/seconds-to-time.mdx

This file was deleted.

26 changes: 0 additions & 26 deletions src/function/secondsToTIme.spec.ts

This file was deleted.

50 changes: 0 additions & 50 deletions src/function/secondsToTime.ts

This file was deleted.

0 comments on commit ccefd28

Please sign in to comment.