mirror of
https://github.com/denoland/std.git
synced 2024-11-21 20:50:22 +00:00
docs(fmt): improve documentation (#5373)
* docs(fmt): improve documentation * work * work * work
This commit is contained in:
parent
2308f8263f
commit
acdea7c9f5
13
fmt/README.md
Normal file
13
fmt/README.md
Normal 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"
|
||||
```
|
16
fmt/bytes.ts
16
fmt/bytes.ts
@ -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;
|
||||
|
@ -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.
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user