PageSourceSearch

https://www.doodly.com/assets/projects/user_pages/chunk-4AIF3XZW.js

js doodly.com collected 2026-09-24 10:09:09 UTC 5,326 bytes, 191 lines download raw bytes

1import {
2  init_define_process
3} from "./chunk-RFSPGZ3L.js";
4
5// projects/lib/packages/yggdrasil-blueprints/src/Elements/Checkout/V2/Utils/checkout-input-validator.ts
6init_define_process();
7var VALIDATION_BY_FIELD_TYPE = {
8  email: {
9    inputType: "input",
10    validations: {
11      required: true,
12      // eslint-disable-next-line max-len
13      pattern: /^(([^<>()[\]\.,;:#%\s@"]+(\.[^<>()[\]\.,;:#%\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
14    }
15  },
16  phone_number: {
17    inputType: "input",
18    validations: {
19      callback: (value) => {
20        if (!globalThis.intlTelInput.utils) return { valid: true };
21        const PHONE_ERROR_MAP = [
22          "Phone Number is invalid",
23          "Phone Number has an invalid country code",
24          "Phone Number is too short",
25          "Phone Number too long",
26          "Phone Number is invalid"
27        ];
28        if (value) {
29          const isValid = globalThis.intlTelInput.utils.isValidNumber(value);
30          if (isValid) {
31            return { valid: true };
32          } else {
33            const errorCode = globalThis.intlTelInput.utils.getValidationError(value);
34            return { valid: false, message: PHONE_ERROR_MAP[errorCode] ?? "Phone Number has an unexpected format" };
35          }
36        } else {
37          return { valid: false, message: "Phone number is required" };
38        }
39      }
40    }
41  },
42  first_name: {
43    inputType: "input",
44    validations: {
45      required: true,
46      pattern: /^[\w\s\-\p{L},.']+$/u,
47      maxlength: 45
48    }
49  },
50  last_name: {
51    inputType: "input",
52    validations: {
53      required: true,
54      pattern: /^[\w\s\-\p{L},.']+$/u,
55      maxlength: 45
56    }
57  },
58  address: {
59    inputType: "input",
60    validations: {
61      required: true,
62      pattern: /^[\w\s\-\/\p{L},.#;:()'&]+$/u,
63      maxlength: 60
64    }
65  },
66  address_one: {
67    inputType: "input",
68    validations: {
69      required: true,
70      pattern: /^[\w\s\-\/\p{L},.#;:()'&]+$/u,
71      maxlength: 60
72    }
73  },
74  address_2: {
75    inputType: "input",
76    validations: {
77      pattern: /^[\w\s\-\/\p{L},.#;:()'&]+$/u,
78      maxlength: 60
79    }
80  },
81  country: {
82    inputType: "select",
83    validations: {
84      required: true,
85      pattern: /^[A-Z]{2}$/u,
86      maxlength: 2
87    }
88  },
89  city: {
90    inputType: "input",
91    validations: {
92      required: true,
93      pattern: /^[\w\s\-\p{L},.']+$/u,
94      maxlength: 45
95    }
96  },
97  state: {
98    inputType: "select"
99    // Some countries don't have states
100  },
101  zip: {
102    inputType: "input",
103    validations: {
104      required: true,
105      pattern: /^[\w\s\-]+$/,
106      maxlength: 10
107    }
108  },
109  postal_code: {
110    inputType: "input",
111    validations: {
112      required: true,
113      pattern: /^[\w\s\-]+$/,
114      maxlength: 10
115    }
116  },
117  card: {
118    validations: {
119      callback: (event) => {
120        if (event && event.valid && event.completed) {
121          return { valid: true };
122        } else if (event && event.error) {
123          return { valid: false, message: event.error.message };
124        } else {
125          const nameMapper = {
126            number: "Card number",
127            cvv: "Card cvv",
128            date: "Card expiration"
129          };
130          const sourceName = nameMapper[event.source];
131          return { valid: false, message: `${sourceName} required` };
132        }
133      }
134    }
135  }
136};
137var defaultValidateValue = (value, validations, fieldName) => {
138  const name = fieldName.split("_").map((name2) => {
139    return name2.charAt(0).toUpperCase() + name2.slice(1);
140  }).join(" ");
141  const { maxlength, required, pattern } = validations;
142  if (required && !value?.length) {
143    return { valid: false, message: `${name} is required` };
144  }
145  if (maxlength && (value?.length ?? 0) > maxlength) {
146    return { valid: false, message: `${name} exceeded max length of ${maxlength} characters` };
147  }
148  if (value?.length && pattern && !pattern.test(value)) {
149    return { valid: false, message: `${name} has an unexpected format` };
150  }
151  return { valid: true };
152};
153var validateValue = (fieldName, value) => {
154  const field = VALIDATION_BY_FIELD_TYPE[fieldName];
155  if (!field) {
156    console.warn(`No field found for ${fieldName}`);
157    return { valid: true };
158  }
159  const validations = field.validations;
160  if (!validations) {
161    return { valid: true };
162  }
163  if (validations.callback) {
164    return validations.callback(value);
165  }
166  return defaultValidateValue(value, validations, fieldName);
167};
168var resetInputErrors = (input) => {
169  const wrapper = $(input).closest(".elFormItemWrapper")[0];
170  const errorContainer = wrapper.querySelector("[data-error-container]");
171  errorContainer.setAttribute("data-error-container", "");
172  wrapper.classList.remove("elInputError");
173  errorContainer.innerHTML = "";
174};
175var addError = (input, errorMessage) => {
176  const wrapper = $(input).closest(".elFormItemWrapper")[0];
177  wrapper.classList.remove("elInputValid");
178  wrapper.classList.add("elInputError");
179  if (errorMessage) {
180    const errorContainer = wrapper.querySelector("[data-error-container]");
181    errorContainer.setAttribute("data-error-container", "active");
182    errorContainer.innerHTML += errorMessage;
183  }
184};
185
186export {
187  validateValue,
188  resetInputErrors,
189  addError
190};
191//# sourceMappingURL=chunk-4AIF3XZW.js.map

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.