format-param-output.js 440 B

12345678910111213141516171819202122
  1. const validator = require('validator');
  2. module.exports = function formatParamOutput(param) {
  3. if (Array.isArray(param)) {
  4. param = param.reduce((prev, curr) => {
  5. var part = '';
  6. if (validator.isInt(curr)) {
  7. part = '[' + curr + ']';
  8. } else if (prev) {
  9. part = '.' + curr;
  10. } else {
  11. part = curr;
  12. }
  13. return prev + part;
  14. }, '');
  15. }
  16. return param;
  17. };
  18. module.exports(['foo']);