Skip to main content
Module

x/ddc_vim/deps.ts>fn.printf

Dark deno-powered completion framework for neovim/Vim8
Go to Latest
function fn.printf
import { fn } from "https://deno.land/x/ddc_vim@v2.3.0/deps.ts";
const { printf } = fn;

Return a String with {fmt}, where "%" items are replaced by the formatted form of their respective arguments. Example: printf("%4d: E%d %.30s", lnum, errno, msg) May result in: " 99: E42 asdfasdfasdfasdfasdfasdfasdfas" ~ When used as a |method| the base is passed as the second argument: Compute()->printf("result: %d") Often used items are: %s string %6S string right-aligned in 6 display cells %6s string right-aligned in 6 bytes %.9s string truncated to 9 bytes %c single byte %d decimal number %5d decimal number padded with spaces to 5 characters %x hex number %04x hex number padded with zeros to at least 4 characters %X hex number using upper case letters %o octal number %08b binary number padded with zeros to at least 8 chars %f floating point number as 12.23, inf, -inf or nan %F floating point number as 12.23, INF, -INF or NAN %e floating point number as 1.23e3, inf, -inf or nan %E floating point number as 1.23E3, INF, -INF or NAN %g floating point number, as %f or %e depending on value %G floating point number, as %F or %E depending on value %% the % character itself Conversion specifications start with '%' and end with the conversion type. All other characters are copied unchanged to the result. The "%" starts a conversion specification. The following arguments appear in sequence: % [flags] [field-width] [.precision] type flags Zero or more of the following flags: # The value should be converted to an "alternate form". For c, d, and s conversions, this option has no effect. For o conversions, the precision of the number is increased to force the first character of the output string to a zero (except if a zero value is printed with an explicit precision of zero). For b and B conversions, a non-zero result has the string "0b" (or "0B" for B conversions) prepended to it. For x and X conversions, a non-zero result has the string "0x" (or "0X" for X conversions) prepended to it. 0 (zero) Zero padding. For all conversions the converted value is padded on the left with zeros rather than blanks. If a precision is given with a numeric conversion (d, b, B, o, x, and X), the 0 flag is ignored. - A negative field width flag; the converted value is to be left adjusted on the field boundary. The converted value is padded on the right with blanks, rather than on the left with blanks or zeros. A - overrides a 0 if both are given. ' ' (space) A blank should be left before a positive number produced by a signed conversion (d). + A sign must always be placed before a number produced by a signed conversion. A + overrides a space if both are used. field-width An optional decimal digit string specifying a minimum field width. If the converted value has fewer bytes than the field width, it will be padded with spaces on the left (or right, if the left-adjustment flag has been given) to fill out the field width. .precision An optional precision, in the form of a period '.' followed by an optional digit string. If the digit string is omitted, the precision is taken as zero. This gives the minimum number of digits to appear for d, o, x, and X conversions, or the maximum number of bytes to be printed from a string for s conversions. For floating point it is the number of digits after the decimal point. type A character that specifies the type of conversion to be applied, see below. A field width or precision, or both, may be indicated by an asterisk '*' instead of a digit string. In this case, a Number argument supplies the field width or precision. A negative field width is treated as a left adjustment flag followed by a positive field width; a negative precision is treated as though it were missing. Example: :echo printf("%d: %.*s", nr, width, line) This limits the length of the text used from "line" to "width" bytes. The conversion specifiers and their meanings are: dbBoxX The Number argument is converted to signed decimal (d), unsigned binary (b and B), unsigned octal (o), or unsigned hexadecimal (x and X) notation. The letters "abcdef" are used for x conversions; the letters "ABCDEF" are used for X conversions. The precision, if any, gives the minimum number of digits that must appear; if the converted value requires fewer digits, it is padded on the left with zeros. In no case does a non-existent or small field width cause truncation of a numeric field; if the result of a conversion is wider than the field width, the field is expanded to contain the conversion result. The 'h' modifier indicates the argument is 16 bits. The 'l' modifier indicates the argument is 32 bits. The 'L' modifier indicates the argument is 64 bits. Generally, these modifiers are not useful. They are ignored when type is known from the argument. i alias for d D alias for ld U alias for lu O alias for lo c The Number argument is converted to a byte, and the resulting character is written. s The text of the String argument is used. If a precision is specified, no more bytes than the number specified are used. If the argument is not a String type, it is automatically converted to text with the same format as ":echo". S The text of the String argument is used. If a precision is specified, no more display cells than the number specified are used. f F The Float argument is converted into a string of the form 123.456. The precision specifies the number of digits after the decimal point. When the precision is zero the decimal point is omitted. When the precision is not specified 6 is used. A really big number (out of range or dividing by zero) results in "inf" or "-inf" with %f (INF or -INF with %F). "0.0 / 0.0" results in "nan" with %f (NAN with %F). Example: echo printf("%.2f", 12.115) 12.12 Note that roundoff depends on the system libraries. Use |round()| when in doubt. e E The Float argument is converted into a string of the form 1.234e+03 or 1.234E+03 when using 'E'. The precision specifies the number of digits after the decimal point, like with 'f'. g G The Float argument is converted like with 'f' if the value is between 0.001 (inclusive) and 10000000.0 (exclusive). Otherwise 'e' is used for 'g' and 'E' for 'G'. When no precision is specified superfluous zeroes and '+' signs are removed, except for the zero immediately after the decimal point. Thus 10000000.0 results in 1.0e7. % A '%' is written. No argument is converted. The complete conversion specification is "%%". When a Number argument is expected a String argument is also accepted and automatically converted. When a Float or String argument is expected a Number argument is also accepted and automatically converted. Any other argument type results in an error message. The number of {exprN} arguments must exactly match the number of "%" items. If there are not sufficient or too many arguments an error is given. Up to 18 arguments can be used.

Parameters

denops: Denops
fmt: unknown
expr1: unknown

Returns

Promise<unknown>