interpolator 0.0.1-alpha.3 copy "interpolator: ^0.0.1-alpha.3" to clipboard
interpolator: ^0.0.1-alpha.3 copied to clipboard

outdated

Yet another Dart package to handle dynamic String interpolation with lighter implementation 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!


	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
0
pub points
66%
popularity

Publisher

unverified uploader

Yet another Dart package to handle dynamic String interpolation with lighter implementation and error check.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

More

Packages that depend on interpolator