@sap-ux/project-input-validator 0.3.1 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Validates a value for duplication in existing change files.
3
+ *
4
+ * @param value The value to check for duplication.
5
+ * @param propertyName The property name in the change file objects to check.
6
+ * @param changeFiles The list of existing change files to check against.
7
+ * @returns {boolean} Returns true if a content duplication is found and false if there is no content duplication.
8
+ */
9
+ export declare function hasContentDuplication(value: string, propertyName: string, changeFiles: {
10
+ content: object;
11
+ }[]): boolean;
12
+ /**
13
+ * Validates a value for starting with a customer prefix.
14
+ *
15
+ * @param value The value to validate.
16
+ * @returns {boolean} True if the value starts with 'customer.' and false if it does not.
17
+ */
18
+ export declare function hasCustomerPrefix(value: string): boolean;
19
+ /**
20
+ * Validates if a value is a valid data source URI.
21
+ *
22
+ * @param uri The URI to validate.
23
+ * @returns {boolean} True if the URI is valid, false if it is not.
24
+ */
25
+ export declare function isDataSourceURI(uri: string): boolean;
26
+ //# sourceMappingURL=validators.d.ts.map
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isDataSourceURI = exports.hasCustomerPrefix = exports.hasContentDuplication = void 0;
4
+ /**
5
+ * Validates a value for duplication in existing change files.
6
+ *
7
+ * @param value The value to check for duplication.
8
+ * @param propertyName The property name in the change file objects to check.
9
+ * @param changeFiles The list of existing change files to check against.
10
+ * @returns {boolean} Returns true if a content duplication is found and false if there is no content duplication.
11
+ */
12
+ function hasContentDuplication(value, propertyName, changeFiles) {
13
+ return changeFiles.some(({ content }) => {
14
+ const contentProperty = content[propertyName];
15
+ return contentProperty && Object.keys(contentProperty).includes(value);
16
+ });
17
+ }
18
+ exports.hasContentDuplication = hasContentDuplication;
19
+ /**
20
+ * Validates a value for starting with a customer prefix.
21
+ *
22
+ * @param value The value to validate.
23
+ * @returns {boolean} True if the value starts with 'customer.' and false if it does not.
24
+ */
25
+ function hasCustomerPrefix(value) {
26
+ return value.toLowerCase().startsWith('customer.');
27
+ }
28
+ exports.hasCustomerPrefix = hasCustomerPrefix;
29
+ /**
30
+ * Validates if a value is a valid data source URI.
31
+ *
32
+ * @param uri The URI to validate.
33
+ * @returns {boolean} True if the URI is valid, false if it is not.
34
+ */
35
+ function isDataSourceURI(uri) {
36
+ return /^(?!.*\/\/)\/([^\s]*)\/$/.test(uri);
37
+ }
38
+ exports.isDataSourceURI = isDataSourceURI;
39
+ //# sourceMappingURL=validators.js.map
@@ -12,4 +12,33 @@ export declare function validateClient(client: string): boolean | string;
12
12
  * @returns true or error message
13
13
  */
14
14
  export declare function validateUrl(input: string): boolean | string;
15
+ /**
16
+ * Validate input is not empty string.
17
+ *
18
+ * @param input input string to be validated
19
+ * @returns true or error message
20
+ */
21
+ export declare function validateEmptyString(input: string): boolean | string;
22
+ /**
23
+ * Validate input does not contain any whitespace characters.
24
+ *
25
+ * @param value The string to check for whitespace characters.
26
+ * @returns true or error message
27
+ */
28
+ export declare function validateEmptySpaces(value: string): boolean | string;
29
+ /**
30
+ * Validate input is valid JSON.
31
+ *
32
+ * @param value The string to test.
33
+ * @returns true or error message
34
+ */
35
+ export declare function validateJSON(value: string): boolean | string;
36
+ /**
37
+ * Validates a value for special characters.
38
+ *
39
+ * @param value The value to validate.
40
+ * @param regexp The regex expression for allowed special characters.
41
+ * @returns {boolean} True if validation passes, or an error message if validation fails.
42
+ */
43
+ export declare function validateSpecialChars(value: string, regexp?: string): boolean | string;
15
44
  //# sourceMappingURL=validators.d.ts.map
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validateUrl = exports.validateClient = void 0;
3
+ exports.validateSpecialChars = exports.validateJSON = exports.validateEmptySpaces = exports.validateEmptyString = exports.validateUrl = exports.validateClient = void 0;
4
4
  const i18n_1 = require("../i18n");
5
5
  /**
6
6
  * SAP client number is either empty or 3 digit string.
@@ -35,4 +35,62 @@ function validateUrl(input) {
35
35
  }
36
36
  }
37
37
  exports.validateUrl = validateUrl;
38
+ /**
39
+ * Validate input is not empty string.
40
+ *
41
+ * @param input input string to be validated
42
+ * @returns true or error message
43
+ */
44
+ function validateEmptyString(input) {
45
+ const formattedInput = input?.trim() || '';
46
+ if (formattedInput.trim().length > 0) {
47
+ return true;
48
+ }
49
+ return (0, i18n_1.t)('general.inputCannotBeEmpty');
50
+ }
51
+ exports.validateEmptyString = validateEmptyString;
52
+ /**
53
+ * Validate input does not contain any whitespace characters.
54
+ *
55
+ * @param value The string to check for whitespace characters.
56
+ * @returns true or error message
57
+ */
58
+ function validateEmptySpaces(value) {
59
+ if (/\s/.test(value)) {
60
+ return (0, i18n_1.t)('general.inputCannotHaveSpaces');
61
+ }
62
+ return true;
63
+ }
64
+ exports.validateEmptySpaces = validateEmptySpaces;
65
+ /**
66
+ * Validate input is valid JSON.
67
+ *
68
+ * @param value The string to test.
69
+ * @returns true or error message
70
+ */
71
+ function validateJSON(value) {
72
+ try {
73
+ JSON.parse(`{${value}}`);
74
+ return true;
75
+ }
76
+ catch {
77
+ return (0, i18n_1.t)('general.invalidJSON');
78
+ }
79
+ }
80
+ exports.validateJSON = validateJSON;
81
+ /**
82
+ * Validates a value for special characters.
83
+ *
84
+ * @param value The value to validate.
85
+ * @param regexp The regex expression for allowed special characters.
86
+ * @returns {boolean} True if validation passes, or an error message if validation fails.
87
+ */
88
+ function validateSpecialChars(value, regexp = '^[a-zA-Z0-9_$.\\-]+$') {
89
+ const regex = new RegExp(regexp, 'g');
90
+ if (regex.test(value)) {
91
+ return true;
92
+ }
93
+ return (0, i18n_1.t)('general.invalidValueForSpecialChars');
94
+ }
95
+ exports.validateSpecialChars = validateSpecialChars;
38
96
  //# sourceMappingURL=validators.js.map
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from './deploy/validators';
2
2
  export * from './ui5/validators';
3
3
  export * from './general/validators';
4
+ export * from './adp/validators';
4
5
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -17,4 +17,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./deploy/validators"), exports);
18
18
  __exportStar(require("./ui5/validators"), exports);
19
19
  __exportStar(require("./general/validators"), exports);
20
+ __exportStar(require("./adp/validators"), exports);
20
21
  //# sourceMappingURL=index.js.map
@@ -44,6 +44,10 @@
44
44
  },
45
45
  "general": {
46
46
  "invalidUrl": "Invalid URL: [{{-input}}]",
47
- "invalidClient": "[{{client}}] is invalid. Leave empty or enter value between 000-999"
47
+ "invalidClient": "[{{client}}] is invalid. Leave empty or enter value between 000-999",
48
+ "inputCannotBeEmpty": "Input cannot be empty.",
49
+ "inputCannotHaveSpaces": "Input cannot contain spaces.",
50
+ "invalidJSON": "Invalid JSON",
51
+ "invalidValueForSpecialChars": "Input must contain only Latin alphanumeric characters or the following symbols: '-','_','$' and '.'"
48
52
  }
49
53
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sap-ux/project-input-validator",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
4
4
  "description": "Library to validate Fiori project input formats",
5
5
  "repository": {
6
6
  "type": "git",