common.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /* Copyright 2020 Mozilla Foundation
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. const FieldType = {
  16. none: 0,
  17. number: 1,
  18. percent: 2,
  19. date: 3,
  20. time: 4,
  21. };
  22. function createActionsMap(actions) {
  23. const actionsMap = new Map();
  24. if (actions) {
  25. for (const [eventType, actionsForEvent] of Object.entries(actions)) {
  26. actionsMap.set(eventType, actionsForEvent);
  27. }
  28. }
  29. return actionsMap;
  30. }
  31. function getFieldType(actions) {
  32. let format = actions.get("Format");
  33. if (!format) {
  34. return FieldType.none;
  35. }
  36. format = format[0];
  37. format = format.trim();
  38. if (format.startsWith("AFNumber_")) {
  39. return FieldType.number;
  40. }
  41. if (format.startsWith("AFPercent_")) {
  42. return FieldType.percent;
  43. }
  44. if (format.startsWith("AFDate_")) {
  45. return FieldType.date;
  46. }
  47. if (format.startsWith("AFTime__")) {
  48. return FieldType.time;
  49. }
  50. return FieldType.none;
  51. }
  52. export { createActionsMap, FieldType, getFieldType };