interpolator 0.1.0 icon indicating copy to clipboard operation
interpolator: ^0.1.0 copied to clipboard

Yet another Dart package to handle dynamic String interpolation with better performance and error check.

example/example.dart

import 'package:interpolator/interpolator.dart';

void main() {
	const format = "{Name} is a chemical element with the symbol {Symbol} and atomic number {No.}.";
	final element = Interpolator(format);
	const map = {
    "Name":     "Chromium",
    "Symbol":   "Cr",
    "No.":      24
	};
	print(element(map));

	//Chromium is a chemical element with the symbol Cr and atomic number 24.


	const formatWithBraces = "Need format string includes '{pre}' and '{suf}'? No problem!";
	final escaped = Interpolator(formatWithBraces);
	print(escaped(const {}));

	//Need format string includes '{' and '}'? No problem!

	const defaultFormat = "Default value: {default}, placeholder: {unspecified}";
	const defaultVal = {"default": 0, null: '_'};
	final fillDefault = Interpolator(defaultFormat, defaultVal);
	print(fillDefault(const {}));

	//Default value: 0, placeholder: _

	try{
		Interpolator("Unmatched '{pre}' at 2:2\n { ");
	}on FormatException catch(e){
		print(e);
	}
		
	//FormatException: Expected '}' to match '{' at 2:2


	final nullMatch = Interpolator("{nullMatch}");
	try{
		nullMatch(const{});
	}on FormatException catch(e){
		print(e);
	}
	
	//FormatException: No match with key "nullMatch" at 1:2 and no placeholder specified
}
0
likes
130
pub points
57%
popularity

Publisher

unverified uploader

Yet another Dart package to handle dynamic String interpolation with better performance and error check.

Repository (GitHub)

Documentation

API reference

License

Icon for licenses.BSD-3-Clause (LICENSE)

More

Packages that depend on interpolator