extension method
Gets the file extension of path
: the portion of basename from the last
.
to the end (including the .
itself).
context.extension('path/to/foo.dart'); // -> '.dart'
context.extension('path/to/foo'); // -> ''
context.extension('path.to/foo'); // -> ''
context.extension('path/to/foo.dart.js'); // -> '.js'
If the file name starts with a .
, then it is not considered an
extension:
context.extension('~/.bashrc'); // -> ''
context.extension('~/.notes.txt'); // -> '.txt'
Takes an optional parameter level
which makes possible to return
multiple extensions having level
number of dots. If level
exceeds the
number of dots, the full extension is returned. The value of level
must
be greater than 0, else RangeError
is thrown.
context.extension('foo.bar.dart.js', 2); // -> '.dart.js
context.extension('foo.bar.dart.js', 3); // -> '.bar.dart.js'
context.extension('foo.bar.dart.js', 10); // -> '.bar.dart.js'
context.extension('path/to/foo.bar.dart.js', 2); // -> '.dart.js'
Implementation
String extension(String path, [int level = 1]) =>
_parse(path).extension(level);