format method

String format(
  1. dynamic args, [
  2. ParamDecoratorFormat? decorator
])

Implementation

String format(dynamic args, [ParamDecoratorFormat? decorator]) {
  if (args == null || this.args.isEmpty) {
    return path;
  }

  if (args is Iterable) {
    _PathSegment? _segment = _segments.first.firstMask();
    final map = <String, String>{};

    for (int i = 0; i < args.length; i++) {
      if (_segment == null) {
        break;
      }

      map[_segment.name] = args.elementAt(i);
      _segment = _segment.nextMask();
    }

    return Parse.format(path, map, ParamDecorator.none);
  }

  if (args is Map) {
    return Parse.format(
        path,
        Parse.toKeyMap(args, (key, value) => '$key',
            converter: (value) => '$value'),
        decorator);
  }

  return Parse.format(path, {this.args.first: '$args'}, ParamDecorator.none);
}