diff options
Diffstat (limited to 'std/fmt')
-rw-r--r-- | std/fmt/README.md | 89 | ||||
-rw-r--r-- | std/fmt/sprintf_test.ts | 22 |
2 files changed, 56 insertions, 55 deletions
diff --git a/std/fmt/README.md b/std/fmt/README.md index 15d9e18fd..8229a585c 100644 --- a/std/fmt/README.md +++ b/std/fmt/README.md @@ -1,7 +1,7 @@ # Printf for Deno -This is very much a work-in-progress. I'm actively soliciting feedback. -What immediately follows are points for discussion. +This is very much a work-in-progress. I'm actively soliciting feedback. What +immediately follows are points for discussion. If you are looking for the documentation proper, skip to: @@ -13,14 +13,13 @@ below. This is very much a work-in-progress. I'm actively soliciting feedback. -- What useful features are available in other languages apart from - Golang and C? +- What useful features are available in other languages apart from Golang and C? - behaviour of `%v` verb. In Golang, this is a shortcut verb to "print the - default format" of the argument. It is currently implemented to format - using `toString` in the default case and `inpect` if the `%#v` - alternative format flag is used in the format directive. Alternativly, - `%V` could be used to distinguish the two. + default format" of the argument. It is currently implemented to format using + `toString` in the default case and `inpect` if the `%#v` alternative format + flag is used in the format directive. Alternativly, `%V` could be used to + distinguish the two. `inspect` output is not defined, however. This may be problematic if using this code on other plattforms (and expecting interoperability). To my @@ -33,28 +32,28 @@ This is very much a work-in-progress. I'm actively soliciting feedback. Consider possible modifier flags, etc. - `<` verb. This is an extension that assumes the argument is an array and will - format each element according to the format (surrounded by [] and seperated - by comma) (`<` Mnemonic: pull each element out of array) + format each element according to the format (surrounded by [] and seperated by + comma) (`<` Mnemonic: pull each element out of array) -- how to deal with more newfangled Javascript features ( generic Iterables, - Map and Set types, typed Arrays, ...) +- how to deal with more newfangled Javascript features ( generic Iterables, Map + and Set types, typed Arrays, ...) - the implementation is fairly rough around the edges: -- currently contains little in the way of checking for - correctness. Conceivably, there will be a 'strict' form, e.g. - that ensures only Number-ish arguments are passed to %f flags +- currently contains little in the way of checking for correctness. Conceivably, + there will be a 'strict' form, e.g. that ensures only Number-ish arguments are + passed to %f flags -- assembles output using string concatenation instead of - utilizing buffers or other optimizations. It would be nice to - have printf / sprintf / fprintf (etc) all in one. +- assembles output using string concatenation instead of utilizing buffers or + other optimizations. It would be nice to have printf / sprintf / fprintf (etc) + all in one. -- float formatting is handled by toString() and to `toExponential` - along with a mess of Regexp. Would be nice to use fancy match +- float formatting is handled by toString() and to `toExponential` along with a + mess of Regexp. Would be nice to use fancy match -- some flags that are potentially applicable ( POSIX long and unsigned - modifiers are not likely useful) are missing, namely %q (print quoted), %U - (unicode format) +- some flags that are potentially applicable ( POSIX long and unsigned modifiers + are not likely useful) are missing, namely %q (print quoted), %U (unicode + format) ## Author @@ -64,8 +63,8 @@ Tim Becker (tim@presseverykey.com) MIT -The implementation is inspired by POSIX and Golang (see above) but does -not port implementation code. A number of Golang test-cases based on: +The implementation is inspired by POSIX and Golang (see above) but does not port +implementation code. A number of Golang test-cases based on: https://golang.org/src/fmt/fmt_test.go ( BSD: Copyright (c) 2009 The Go Authors. All rights reserved. ) @@ -74,26 +73,26 @@ were used. # printf: prints formatted output -sprintf converts and formats a variable number of arguments as is -specified by a `format string`. In it's basic form, a format string -may just be a literal. In case arguments are meant to be formatted, -a `directive` is contained in the format string, preceded by a '%' character: +sprintf converts and formats a variable number of arguments as is specified by a +`format string`. In it's basic form, a format string may just be a literal. In +case arguments are meant to be formatted, a `directive` is contained in the +format string, preceded by a '%' character: %<verb> -E.g. the verb `s` indicates the directive should be replaced by the -string representation of the argument in the corresponding position of -the argument list. E.g.: +E.g. the verb `s` indicates the directive should be replaced by the string +representation of the argument in the corresponding position of the argument +list. E.g.: Hello %s! applied to the arguments "World" yields "Hello World!" -The meaning of the format string is modelled after [POSIX][1] format -strings as well as well as [Golang format strings][2]. Both contain -elements specific to the respective programming language that don't -apply to JavaScript, so they can not be fully supported. Furthermore we -implement some functionality that is specific to JS. +The meaning of the format string is modelled after [POSIX][1] format strings as +well as well as [Golang format strings][2]. Both contain elements specific to +the respective programming language that don't apply to JavaScript, so they can +not be fully supported. Furthermore we implement some functionality that is +specific to JS. ## Verbs @@ -117,16 +116,16 @@ The following verbs are supported: ## Width and Precision -Verbs may be modified by providing them with width and precision, either or -both may be omitted: +Verbs may be modified by providing them with width and precision, either or both +may be omitted: %9f width 9, default precision %.9f default width, precision 9 %8.9f width 8, precision 9 %8.f width 9, precision 0 -In general, 'width' describes the minimum length of the output, while 'precision' -limits the output. +In general, 'width' describes the minimum length of the output, while +'precision' limits the output. | verb | precision | | --------- | -------------------------------------------------------------- | @@ -177,13 +176,13 @@ the 'depth' config parameter ## Positional arguments -Arguments do not need to be consumed in the order they are provded and may -be consumed more than once. E.g.: +Arguments do not need to be consumed in the order they are provded and may be +consumed more than once. E.g.: sprintf("%[2]s %[1]s", "World", "Hello") -returns "Hello World". The precence of a positional indicator resets the arg counter -allowing args to be reused: +returns "Hello World". The precence of a positional indicator resets the arg +counter allowing args to be reused: sprintf("dec[%d]=%d hex[%[1]d]=%x oct[%[1]d]=%#o %s", 1, 255, "Third") diff --git a/std/fmt/sprintf_test.ts b/std/fmt/sprintf_test.ts index 26757c3cc..4d3a48c68 100644 --- a/std/fmt/sprintf_test.ts +++ b/std/fmt/sprintf_test.ts @@ -587,16 +587,18 @@ const tests: Array<[string, any, string]> = [ ]; test(function testThorough(): void { - tests.forEach((t, i): void => { - // p(t) - const is = S(t[0], t[1]); - const should = t[2]; - assertEquals( - is, - should, - `failed case[${i}] : is >${is}< should >${should}<` - ); - }); + tests.forEach( + (t, i): void => { + // p(t) + const is = S(t[0], t[1]); + const should = t[2]; + assertEquals( + is, + should, + `failed case[${i}] : is >${is}< should >${should}<` + ); + } + ); }); test(function testWeirdos(): void { |