sprintf 4.0.2

dart-sprintf #

Dart implementation of sprintf.

Build Status

ChangeLog #

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

Getting Started #

Add the following to your pubspec.yaml:

dependencies:
  sprintf: "^4.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.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  sprintf: ^4.0.2

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:sprintf/sprintf.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
97
Health:
Code health derived from static analysis. [more]
83
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
50
Overall:
Weighted score of the above. [more]
84
Learn more about scoring.

We analyzed this package on Jan 16, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.0
  • pana: 0.13.4

Health issues and suggestions

Document public APIs. (-1 points)

31 out of 31 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Fix lib/src/sprintf_impl.dart. (-12.22 points)

Analysis of lib/src/sprintf_impl.dart reported 26 hints, including:

line 6 col 35: Unnecessary new keyword.

line 7 col 38: Unnecessary new keyword.

line 10 col 29: Unnecessary new keyword.

line 11 col 29: Unnecessary new keyword.

line 12 col 29: Unnecessary new keyword.

Fix lib/src/formatters/float_formatter.dart. (-3.45 points)

Analysis of lib/src/formatters/float_formatter.dart reported 7 hints, including:

line 5 col 29: Unnecessary new keyword.

line 6 col 27: Unnecessary new keyword.

line 7 col 37: Unnecessary new keyword.

line 10 col 23: Unnecessary new keyword.

line 15 col 10: Don't explicitly initialize variables to null.

Fix lib/sprintf.dart. (-0.50 points)

Analysis of lib/sprintf.dart reported 1 hint:

line 13 col 15: Unnecessary new keyword.

Fix additional 3 files with analysis or formatting issues. (-0.50 points)

Additional issues in the following files:

  • lib/src/formatters/Formatter.dart (1 hint)
  • lib/src/formatters/int_formatter.dart (Run dartfmt to format lib/src/formatters/int_formatter.dart.)
  • lib/src/formatters/string_formatter.dart (Run dartfmt to format lib/src/formatters/string_formatter.dart.)

Maintenance issues and suggestions

Provide a file named CHANGELOG.md. (-20 points)

Changelog entries help developers follow the progress of your package. See the example generated by stagehand.

The package description is too short. (-20 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Maintain an example. (-10 points)

Create a short demo in the example/ directory to show how to use this package.

Common filename patterns include main.dart, example.dart, and sprintf.dart. Packages with multiple examples should provide example/README.md.

For more information see the pub package layout conventions.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK <3.0.0
Dev dependencies
test any