Guest User

Untitled

a guest
Apr 4th, 2025
13
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. Handlebars.RegisterHelper("withExtractPostalAddress", (output, options, context, arguments) =>
  2. {
  3. foreach (object oneParameter in arguments)
  4. {
  5. if (oneParameter is UndefinedBindingResult)
  6. {
  7. options.Inverse(output, null);
  8. return ;
  9. }
  10. }
  11.  
  12. string addressBlock = arguments.At<string>(0);
  13. object countryCode = arguments.At<string>(1);
  14.  
  15. var addressArray = addressBlock.Split('\n');
  16.  
  17. if (addressArray.Length >= 4)
  18. {
  19. var address = new
  20. {
  21. name = addressArray[0],
  22. name2 = "",
  23. street = addressArray[1],
  24. district = "",
  25. firstLines = addressArray[0] + "\n" + addressArray[1],
  26. zipcode = addressArray[2].Split(' ')[0],
  27. city = addressArray[2].Split(' ')[1],
  28. region = "",
  29. country = countryCode,
  30. };
  31. options.Template(output, address);
  32. }
  33. else
  34. {
  35. Logger.AddError("factory 'withExtractPostalAddress' could not extract address using country code '" + countryCode + "' : " + addressBlock);
  36. options.Inverse(output, null);
  37. }
  38. });
Advertisement
Add Comment
Please, Sign In to add comment