@sap-ux/project-input-validator
Advanced tools
Comparing version 0.3.1 to 0.3.2
@@ -15,2 +15,31 @@ /** | ||
export declare function validateUrl(input: string): boolean | string; | ||
/** | ||
* Validate input is not empty string. | ||
* | ||
* @param input input string to be validated | ||
* @returns true or error message | ||
*/ | ||
export declare function validateEmptyString(input: string): boolean | string; | ||
/** | ||
* Validate input does not contain any whitespace characters. | ||
* | ||
* @param value The string to check for whitespace characters. | ||
* @returns true or error message | ||
*/ | ||
export declare function validateEmptySpaces(value: string): boolean | string; | ||
/** | ||
* Validate input is valid JSON. | ||
* | ||
* @param value The string to test. | ||
* @returns true or error message | ||
*/ | ||
export declare function validateJSON(value: string): boolean | string; | ||
/** | ||
* Validates a value for special characters. | ||
* | ||
* @param value The value to validate. | ||
* @param regexp The regex expression for allowed special characters. | ||
* @returns {boolean} True if validation passes, or an error message if validation fails. | ||
*/ | ||
export declare function validateSpecialChars(value: string, regexp?: string): boolean | string; | ||
//# sourceMappingURL=validators.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.validateUrl = exports.validateClient = void 0; | ||
exports.validateSpecialChars = exports.validateJSON = exports.validateEmptySpaces = exports.validateEmptyString = exports.validateUrl = exports.validateClient = void 0; | ||
const i18n_1 = require("../i18n"); | ||
@@ -38,2 +38,60 @@ /** | ||
exports.validateUrl = validateUrl; | ||
/** | ||
* Validate input is not empty string. | ||
* | ||
* @param input input string to be validated | ||
* @returns true or error message | ||
*/ | ||
function validateEmptyString(input) { | ||
const formattedInput = input?.trim() || ''; | ||
if (formattedInput.trim().length > 0) { | ||
return true; | ||
} | ||
return (0, i18n_1.t)('general.inputCannotBeEmpty'); | ||
} | ||
exports.validateEmptyString = validateEmptyString; | ||
/** | ||
* Validate input does not contain any whitespace characters. | ||
* | ||
* @param value The string to check for whitespace characters. | ||
* @returns true or error message | ||
*/ | ||
function validateEmptySpaces(value) { | ||
if (/\s/.test(value)) { | ||
return (0, i18n_1.t)('general.inputCannotHaveSpaces'); | ||
} | ||
return true; | ||
} | ||
exports.validateEmptySpaces = validateEmptySpaces; | ||
/** | ||
* Validate input is valid JSON. | ||
* | ||
* @param value The string to test. | ||
* @returns true or error message | ||
*/ | ||
function validateJSON(value) { | ||
try { | ||
JSON.parse(`{${value}}`); | ||
return true; | ||
} | ||
catch { | ||
return (0, i18n_1.t)('general.invalidJSON'); | ||
} | ||
} | ||
exports.validateJSON = validateJSON; | ||
/** | ||
* Validates a value for special characters. | ||
* | ||
* @param value The value to validate. | ||
* @param regexp The regex expression for allowed special characters. | ||
* @returns {boolean} True if validation passes, or an error message if validation fails. | ||
*/ | ||
function validateSpecialChars(value, regexp = '^[a-zA-Z0-9_$.\\-]+$') { | ||
const regex = new RegExp(regexp, 'g'); | ||
if (regex.test(value)) { | ||
return true; | ||
} | ||
return (0, i18n_1.t)('general.invalidValueForSpecialChars'); | ||
} | ||
exports.validateSpecialChars = validateSpecialChars; | ||
//# sourceMappingURL=validators.js.map |
export * from './deploy/validators'; | ||
export * from './ui5/validators'; | ||
export * from './general/validators'; | ||
export * from './adp/validators'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -20,2 +20,3 @@ "use strict"; | ||
__exportStar(require("./general/validators"), exports); | ||
__exportStar(require("./adp/validators"), exports); | ||
//# sourceMappingURL=index.js.map |
@@ -47,4 +47,8 @@ { | ||
"invalidUrl": "Invalid URL: [{{-input}}]", | ||
"invalidClient": "[{{client}}] is invalid. Leave empty or enter value between 000-999" | ||
"invalidClient": "[{{client}}] is invalid. Leave empty or enter value between 000-999", | ||
"inputCannotBeEmpty": "Input cannot be empty.", | ||
"inputCannotHaveSpaces": "Input cannot contain spaces.", | ||
"invalidJSON": "Invalid JSON", | ||
"invalidValueForSpecialChars": "Input must contain only Latin alphanumeric characters or the following symbols: '-','_','$' and '.'" | ||
} | ||
} |
{ | ||
"name": "@sap-ux/project-input-validator", | ||
"version": "0.3.1", | ||
"version": "0.3.2", | ||
"description": "Library to validate Fiori project input formats", | ||
@@ -5,0 +5,0 @@ "repository": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
41935
16
680