detect type for strings
Infer Nushell datatype from a string.
Signature
> detect type {flags}
Flags
-
--prefer-filesize, -f: For ints display them as human-readable file sizes. -
--prefer-dmy: Prefer day-month-year format for ambiguous dates.
Input/output types:
| input | output |
|---|---|
| string | any |
| any | any |
Examples
Bool from string
> 'true' | detect type true
Bool is case insensitive
> 'FALSE' | detect type false
Int from plain digits
> '42' | detect type 42
Int with underscores
> '1_000_000' | detect type 1000000
Int with commas
> '1,234,567' | detect type 1234567
Float from decimal
> '3.14' | detect type 3.14
Float in scientific notation
> '6.02e23' | detect type 601999999999999995805696.0
Prefer filesize for ints
> '1024' | detect type -f 1.0 kB
Date Y-M-D
> '2022-01-01' | detect type Sat, 1 Jan 2022 00:00:00 +0800 (4 years ago)
Date with time and offset
> '2022-01-01T00:00:00Z' | detect type Sat, 1 Jan 2022 00:00:00 +0000 (4 years ago)
Date D-M-Y
> '31-12-2021' | detect type Fri, 31 Dec 2021 00:00:00 +0800 (4 years ago)
Date M-D-Y (default for ambiguous)
> '01/02/2025' | detect type Thu, 2 Jan 2025 00:00:00 +0800 (a year ago)
Prefer DMY for ambiguous dates
> '01/02/2025' | detect type --prefer-dmy Sat, 1 Feb 2025 00:00:00 +0800 (a year ago)
Unknown stays a string
> 'not-a-number' | detect type not-a-number
Copyright © 2019–2026 The Nushell Project DevelopersLicensed under the MIT License.
https://www.nushell.sh/commands/docs/detect_type.html