docs(fmt): improve documentation (#5373)

* docs(fmt): improve documentation

* work

* work

* work
This commit is contained in:
Asher Gomez 2024-07-10 15:26:41 +10:00 committed by GitHub
parent 2308f8263f
commit acdea7c9f5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 34 additions and 0 deletions

13
fmt/README.md Normal file
View File

@ -0,0 +1,13 @@
Provides utilities for formatting text of different types:
- [Human-readable bytes](https://jsr.io/@std/fmt/doc/bytes/~)
- [Styles for the CLI](https://jsr.io/@std/fmt/doc/colors/~)
- [Time duration](https://jsr.io/@std/fmt/doc/duration/~)
- [Printing formatted strings to stdout](https://jsr.io/@std/fmt/doc/printf/~)
```ts
import { format } from "@std/fmt/bytes";
import { red } from "@std/fmt/colors";
console.log(red(format(1337))); // Prints "1.34 kB"
```

View File

@ -4,6 +4,22 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
// This module is browser compatible.
/**
* Convert bytes to a human-readable string: 1337 1.34 kB
*
* Based on {@link https://github.com/sindresorhus/pretty-bytes | pretty-bytes}.
* A utility for displaying file sizes for humans.
*
* ```ts
* import { format } from "@std/fmt/bytes";
* import { assertEquals } from "@std/assert";
*
* assertEquals(format(1337), "1.34 kB");
* assertEquals(format(100), "100 B");
* ```
* @module
*/
type LocaleOptions = {
minimumFractionDigits?: number;
maximumFractionDigits?: number;

View File

@ -6,6 +6,11 @@
/**
* String formatters and utilities for dealing with ANSI color codes.
*
* > ![IMPORTANT]
* > If printing directly to the console, it's recommended to style console
* > output using CSS (guide
* > {@linkcode https://developer.mozilla.org/en-US/docs/Web/API/console#styling_console_output | here}).
*
* This module supports `NO_COLOR` environmental variable disabling any coloring
* if `NO_COLOR` is set.
*