-
Notifications
You must be signed in to change notification settings - Fork 68
Expand file tree
/
Copy pathhelper_validation_utils.ts
More file actions
62 lines (55 loc) · 2.34 KB
/
Copy pathhelper_validation_utils.ts
File metadata and controls
62 lines (55 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright (c) 2026 Apple Inc. Licensed under MIT License.
export class HelperValidationUtils {
public static readonly MAXIMUM_DESCRIPTION_LENGTH = 45
public static readonly MAXIMUM_DISPLAY_NAME_LENGTH = 30
private static readonly MAXIMUM_SKU_LENGTH = 128
private static readonly MIN_PERIOD = 1
private static readonly MAX_PERIOD = 12
/**
* Validates description is a string and does not exceed maximum length.
*
* @param description The description to validate
* @return Whether the description is valid
*/
public static validateDescription(description: any): boolean {
return (typeof description === 'string' || description instanceof String) && description.length <= HelperValidationUtils.MAXIMUM_DESCRIPTION_LENGTH
}
/**
* Validates display name is a string and does not exceed maximum length.
*
* @param displayName The display name to validate
* @return Whether the display name is valid
*/
public static validateDisplayName(displayName: any): boolean {
return (typeof displayName === 'string' || displayName instanceof String) && displayName.length <= HelperValidationUtils.MAXIMUM_DISPLAY_NAME_LENGTH
}
/**
* Validates SKU is a string and does not exceed maximum length.
*
* @param sku The SKU to validate
* @return Whether the SKU is valid
*/
public static validateSku(sku: any): boolean {
return (typeof sku === 'string' || sku instanceof String) && sku.length <= HelperValidationUtils.MAXIMUM_SKU_LENGTH
}
/**
* Validates periodCount is a number between MIN_PERIOD and MAX_PERIOD inclusive.
*
* @param periodCount The period count to validate
* @return Whether the period count is valid
*/
public static validatePeriodCount(periodCount: any): boolean {
return typeof periodCount === 'number' &&
periodCount >= HelperValidationUtils.MIN_PERIOD &&
periodCount <= HelperValidationUtils.MAX_PERIOD
}
/**
* Validates a list of items is a non-empty array with no null elements.
*
* @param list The list of items to validate
* @return Whether the items list is valid
*/
public static validateItems(list: any): boolean {
return Array.isArray(list) && list.length > 0 && list.every((item: any) => item != null)
}
}