Skip to content

Commit acdea7c

Browse files
authored
docs(fmt): improve documentation (#5373)
* docs(fmt): improve documentation * work * work * work
1 parent 2308f82 commit acdea7c

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

fmt/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Provides utilities for formatting text of different types:
2+
3+
- [Human-readable bytes](https://jsr.io/@std/fmt/doc/bytes/~)
4+
- [Styles for the CLI](https://jsr.io/@std/fmt/doc/colors/~)
5+
- [Time duration](https://jsr.io/@std/fmt/doc/duration/~)
6+
- [Printing formatted strings to stdout](https://jsr.io/@std/fmt/doc/printf/~)
7+
8+
```ts
9+
import { format } from "@std/fmt/bytes";
10+
import { red } from "@std/fmt/colors";
11+
12+
console.log(red(format(1337))); // Prints "1.34 kB"
13+
```

fmt/bytes.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,22 @@
44
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
55
// This module is browser compatible.
66

7+
/**
8+
* Convert bytes to a human-readable string: 1337 → 1.34 kB
9+
*
10+
* Based on {@link https://github.com/sindresorhus/pretty-bytes | pretty-bytes}.
11+
* A utility for displaying file sizes for humans.
12+
*
13+
* ```ts
14+
* import { format } from "@std/fmt/bytes";
15+
* import { assertEquals } from "@std/assert";
16+
*
17+
* assertEquals(format(1337), "1.34 kB");
18+
* assertEquals(format(100), "100 B");
19+
* ```
20+
* @module
21+
*/
22+
723
type LocaleOptions = {
824
minimumFractionDigits?: number;
925
maximumFractionDigits?: number;

fmt/colors.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
/**
77
* String formatters and utilities for dealing with ANSI color codes.
88
*
9+
* > ![IMPORTANT]
10+
* > If printing directly to the console, it's recommended to style console
11+
* > output using CSS (guide
12+
* > {@linkcode https://developer.mozilla.org/en-US/docs/Web/API/console#styling_console_output | here}).
13+
*
914
* This module supports `NO_COLOR` environmental variable disabling any coloring
1015
* if `NO_COLOR` is set.
1116
*

0 commit comments

Comments
 (0)