Viewing version 6.0.0. Open the latest package page.

sprintf

6.0.0

Dart implementation of sprintf. Provides simple printf like formatting such as sprintf("hello %s", ["world"]);

Download archive

Readme

dart-sprintf

Dart implementation of sprintf.

Build Status

ChangeLog

ChangeLog.md

Getting Started

Add the following to your pubspec.yaml:

dependencies:
  sprintf: "^5.0.0"

then run pub install.

Next, import dart-sprintf:

import 'package:sprintf/sprintf.dart';

Example

import 'package:sprintf/sprintf.dart';

void main() {
	print(sprintf("%04i", [-42]));
	print(sprintf("%s %s", ["Hello", "World"]));
	print(sprintf("%#04x", [10]));
}
-042
Hello World
0x0a

Limitations

  • Negative numbers are wrapped as 64bit ints when formatted as hex or octal.

Differences to C's printf

  • When using fixed point printing of numbers with large exponents, C introduces errors after 20 decimal places. Dart-printf will just print 0s.
Changelog

v6.0.0 (2021-03-04)

* Promote null-safety to stable

v6.0.0-nullsafety (2020-12-10)

* Add null-safety support

v5.0.0 (2020-09-25)

* Fix #22: position arguments didn't work. Major version bump because it's
  a different API. The following now works:
  ```
  sprintf('|%2\$d %2\$d %1\$d|', [5, 10]); // '|10 10 5|'
  ```

v4.1.0 (2020-07-26)

* Used dart padentic to fix up some code
* changed SDK requirements to be >=2, <3

v4.0.3 (2020-07-26)

* Fixed formatting of "1.0" (#18); it was being truncated to "1" and then
  failing the regex.

v4.0.2 (2019-02-19)

* Fixed v4.0.1
* Fixed rounding bug if 0 or 1 digits of rounding are requested (#15)

v4.0.1 (2019-02-19)

* **BROKEN** Fixed rounding bug if 0 or 1 digits of rounding are requested (#15)

v4.0.0 (2018-07-02)

* **Breaking change** (#13)
  As of dart 2, int types are going to be fixed width, and the width depends on
  implementation (dart2js vs dartvm). Dart started warning about constants that
  are greater than the max int of javascript. To fix that, this patch will limit
  int (when formatted as hex or octal) to the max limit of javascript (2**53 - 1).
  Any int outside of the +-(2**53 -1) range is not guaranteed to format correctly!

v3.0.2 (2017-08-17)

* Fixed bad publish

v3.0.1 (2017-08-17)

* Fixed weak typing which stopped dartdevc from working (#11 thanks @bergwerf)

v3.0.0 (2017-04-20)

* Fixed rounding of floats, again. Bumping major version because it's different from previous behaviour

v2.0.0 (2017-03-23)

* Fixed rounding of floats. Bumping major version, because previous behaviour was to always round down.

v1.1.1 (2016-11-16)

* Updated to use `test` library since `unittest` has been deprecated.

v1.1.0 (2014-08-21)

* **API change**: Any object with a valid `toString` method can be formatted with `'%s'` (#7)

v1.0.9 (2013-12-15)

* Round numbers when they're truncated. (#6)

v1.0.8 (2013-10-08)

* Remove trailing decimal point if there are no following digits (#6)

v1.0.7 (2013-05-07)

* Update for new dart version

v1.0.6 (2013-04-16)

* Update for new dart version

v1.0.5 (2013-03-25)

* Fixed dependencies example in README (#5)

v1.0.4 (2013-03-21)

* Update for new dart version

* Update for new pubspec format

v1.0.3 (2013-02-12)

* Update for dart M2

v1.0.2 (2013-01-21)

* Pubspec and whitespace fixes

v1.0.1 (2012-11-12)

* Update for new dart version

v1.0.0 (2012-10-08)

First release with semver

Installing

export PUB_HOSTED_URL=https://pub.mirror.p-hatan.ir
flutter pub add 'sprintf:6.0.0'
pubspec.yaml
name: sprintf
version: 6.0.0
author: Richard Eames <dartsprintf@naddiseo.ca>
description: Dart implementation of sprintf. Provides simple printf like
  formatting such as sprintf("hello %s", ["world"]);
homepage: https://github.com/Naddiseo/dart-sprintf

environment:
  sdk: ">=2.12.0-0 <3.0.0"

dev_dependencies:
  test: ^1.16.0-nullsafety.13
  pedantic: ^1.10.0-nullsafety.3

Version history

VersionPublishedArchiveSHA-256
1.0.0-alpha1Cached · Upstream SHA-256 matchedDownloada6728ba2…7ae081
1.0.1Cached · Upstream SHA-256 matchedDownload61082cd0…906598
1.0.2Cached · Upstream SHA-256 matchedDownload7f7da7ae…b36e80
1.0.3Cached · Upstream SHA-256 matchedDownload91c5252f…b1c10b
1.0.4Cached · Upstream SHA-256 matchedDownload23567a5a…4ce230
1.0.5Cached · Upstream SHA-256 matchedDownloada7f26d36…8373e5
1.0.6Cached · Upstream SHA-256 matchedDownload378e7458…7f9b2b
1.0.7Cached · Upstream SHA-256 matchedDownload1ba6bbb7…e76fc6
1.0.8Cached · Upstream SHA-256 matchedDownloaddd5354ba…7df63b
3.0.0Cached · Upstream SHA-256 matchedDownload192621df…fa6196
3.0.1Cached · Upstream SHA-256 matchedDownloadfbce46f6…6b4aa3
3.0.2Cached · Upstream SHA-256 matchedDownloadc1488c52…5c66c4
4.0.0Cached · Upstream SHA-256 matchedDownload99f2e397…5379f2
4.0.1Cached · Upstream SHA-256 matchedDownload4f4023cc…b6f7d5
4.0.2Cached · Upstream SHA-256 matchedDownloadfc340e40…02a991
4.0.3Cached · Upstream SHA-256 matchedDownload55e2bb72…b6bfdd
4.1.0Cached · Upstream SHA-256 matchedDownloade5b1c200…bb1625
5.0.0Cached · Upstream SHA-256 matchedDownloadb6041625…71c27a
6.0.0-nullsafetyCached · Upstream SHA-256 matchedDownloadf21cf219…c5c03c
6.0.0Cached · Upstream SHA-256 matchedDownload936056f5…9fc526
6.0.2Cached · Upstream SHA-256 matchedDownloadec76d389…0776d1
7.0.0Cached · Upstream SHA-256 matchedDownload1fc9ffe6…120f23

Dependencies

No direct dependencies declared.