helper.js 611 B

12345678910111213141516171819202122232425262728
  1. function trimNewLine(input) {
  2. return typeof(input) === 'string' ? input.replace(/\n/g, '') : input;
  3. }
  4. function get(object, path) {
  5. const pathArray = path.split('.');
  6. let result = object;
  7. while (result != null && pathArray.length) {
  8. const pathItem = pathArray.shift();
  9. if (pathItem in result) {
  10. result = result[pathItem];
  11. } else {
  12. return undefined;
  13. }
  14. }
  15. return result;
  16. }
  17. function last(array) {
  18. var length = array == null ? 0 : array.length;
  19. return length ? array[length - 1] : undefined;
  20. }
  21. module.exports = {
  22. get: get,
  23. last: last,
  24. trimNewLine: trimNewLine,
  25. };