(context, operator, key, modifier)
| 502 | } |
| 503 | |
| 504 | function getValues(context, operator, key, modifier) { |
| 505 | |
| 506 | var value = context[key], |
| 507 | result = []; |
| 508 | |
| 509 | if (isDefined(value) && value !== '') { |
| 510 | if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') { |
| 511 | value = value.toString(); |
| 512 | |
| 513 | if (modifier && modifier !== '*') { |
| 514 | value = value.substring(0, parseInt(modifier, 10)); |
| 515 | } |
| 516 | |
| 517 | result.push(encodeValue(operator, value, isKeyOperator(operator) ? key : null)); |
| 518 | } else { |
| 519 | if (modifier === '*') { |
| 520 | if (Array.isArray(value)) { |
| 521 | value.filter(isDefined).forEach(function (value) { |
| 522 | result.push(encodeValue(operator, value, isKeyOperator(operator) ? key : null)); |
| 523 | }); |
| 524 | } else { |
| 525 | Object.keys(value).forEach(function (k) { |
| 526 | if (isDefined(value[k])) { |
| 527 | result.push(encodeValue(operator, value[k], k)); |
| 528 | } |
| 529 | }); |
| 530 | } |
| 531 | } else { |
| 532 | var tmp = []; |
| 533 | |
| 534 | if (Array.isArray(value)) { |
| 535 | value.filter(isDefined).forEach(function (value) { |
| 536 | tmp.push(encodeValue(operator, value)); |
| 537 | }); |
| 538 | } else { |
| 539 | Object.keys(value).forEach(function (k) { |
| 540 | if (isDefined(value[k])) { |
| 541 | tmp.push(encodeURIComponent(k)); |
| 542 | tmp.push(encodeValue(operator, value[k].toString())); |
| 543 | } |
| 544 | }); |
| 545 | } |
| 546 | |
| 547 | if (isKeyOperator(operator)) { |
| 548 | result.push(encodeURIComponent(key) + '=' + tmp.join(',')); |
| 549 | } else if (tmp.length !== 0) { |
| 550 | result.push(tmp.join(',')); |
| 551 | } |
| 552 | } |
| 553 | } |
| 554 | } else { |
| 555 | if (operator === ';') { |
| 556 | result.push(encodeURIComponent(key)); |
| 557 | } else if (value === '' && (operator === '&' || operator === '?')) { |
| 558 | result.push(encodeURIComponent(key) + '='); |
| 559 | } else if (value === '') { |
| 560 | result.push(''); |
| 561 | } |
no test coverage detected