MCPcopy Create free account
hub / github.com/keepfool/vue-tutorials / parse

Function parse

06.Router/basic/js/vue-resource.js:457–502  ·  view source on GitHub ↗
(template)

Source from the content-addressed store, hash-verified

455 }
456
457 function parse(template) {
458
459 var operators = ['+', '#', '.', '/', ';', '?', '&'],
460 variables = [];
461
462 return {
463 vars: variables,
464 expand: function (context) {
465 return template.replace(/\{([^\{\}]+)\}|([^\{\}]+)/g, function (_, expression, literal) {
466 if (expression) {
467
468 var operator = null,
469 values = [];
470
471 if (operators.indexOf(expression.charAt(0)) !== -1) {
472 operator = expression.charAt(0);
473 expression = expression.substr(1);
474 }
475
476 expression.split(/,/g).forEach(function (variable) {
477 var tmp = /([^:\*]*)(?::(\d+)|(\*))?/.exec(variable);
478 values.push.apply(values, getValues(context, operator, tmp[1], tmp[2] || tmp[3]));
479 variables.push(tmp[1]);
480 });
481
482 if (operator && operator !== '+') {
483
484 var separator = ',';
485
486 if (operator === '?') {
487 separator = '&';
488 } else if (operator !== '#') {
489 separator = operator;
490 }
491
492 return (values.length !== 0 ? operator : '') + values.join(separator);
493 } else {
494 return values.join(',');
495 }
496 } else {
497 return encodeReserved(literal);
498 }
499 });
500 }
501 };
502 }
503
504 function getValues(context, operator, key, modifier) {
505

Callers 1

expandFunction · 0.70

Calls 2

getValuesFunction · 0.70
encodeReservedFunction · 0.70

Tested by

no test coverage detected