* Throws an error if setting an invalid tag. Will return empty string for * null or undefined inputs. * @param {string|null|undefined} tag * @return {string} The validated tag. * @throws {!Error} If the tag does not match the valid format.
(tag)
| 2265 | * @throws {!Error} If the tag does not match the valid format. |
| 2266 | */ |
| 2267 | validate(tag) { |
| 2268 | if (tag == null || tag === '') { |
| 2269 | return ''; |
| 2270 | } |
| 2271 | |
| 2272 | tag = String(tag); |
| 2273 | if (!/^([a-z0-9]|[a-z0-9][-_a-z0-9]{0,61}[a-z0-9])$/g.test(tag)) { |
| 2274 | const validationMessage = 'Tags must be 1-63 characters, ' + |
| 2275 | 'beginning and ending with a lowercase alphanumeric character ' + |
| 2276 | '([a-z0-9]) with dashes (-), underscores (_), and ' + |
| 2277 | 'lowercase alphanumerics between.'; |
| 2278 | throw new Error(`Invalid tag, "${tag}". ${validationMessage}`); |
| 2279 | } |
| 2280 | return tag; |
| 2281 | } |
| 2282 | |
| 2283 | /** |
| 2284 | * @return {!ee.data.WorkloadTag} |
no test coverage detected