Skip to content

fmt/bytes format() should use non-breaking space between the number and the unit #6724

Open
@lionel-rowe

Description

@lionel-rowe

Is your feature request related to a problem? Please describe.

fmt/bytes format() should use non-breaking space between the number and the unit.

https://en.wikipedia.org/wiki/Non-breaking_space#Non-breaking_behavior

For example, if the text "100 km" will not quite fit at the end of a line, the software may break the line between "100" and "km". Using a non-breaking space between "100" and "km" will prevent this behaviour. This guarantees that the text "100 km" will not be broken—if it does not fit at the end of a line, it is moved in its entirety to the next line. For this reason, many style guides recommend using a non-breaking space between numbers and their associated units.[4][5]

Describe the solution you'd like

Use \xa0 non-breaking space instead of \x20 space between number and units in fmt/bytes:

import { format } from '@std/fmt/bytes'
import { assertEquals } from '@std/assert'
assertEquals(format(1e6), '1\xa0MB')

Describe alternatives you've considered

N/A

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions