@run-crank/utilities
Advanced tools
Comparing version 0.4.2 to 0.4.3
@@ -6,3 +6,4 @@ "use strict"; | ||
const errors_1 = require("../constants/errors"); | ||
const VALID_OPERATORS = ['be', 'not be', 'contain', 'not contain', 'be greater than', 'be less than', 'be set', 'not be set', 'be one of', 'not be one of']; | ||
const valid_operators_1 = require("../constants/valid-operators"); | ||
const VALID_OPERATORS = valid_operators_1.validOperators; | ||
const DATE_TIME_FORMAT = /\d{4}-\d{2}-\d{2}(?:.?\d{2}:\d{2}:\d{2})?/; | ||
@@ -63,2 +64,10 @@ const EMAIL_FORMAT = /^(([^<>()[\]\\.,;:\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,}))$/; | ||
.includes(actual.trim()), | ||
'matches': (actual, expected) => { | ||
const regex = new RegExp(expected); | ||
return regex.test(actual); | ||
}, | ||
'does not match': (actual, expected) => { | ||
const regex = new RegExp(expected); | ||
return !regex.test(actual); | ||
}, | ||
}; | ||
@@ -76,2 +85,4 @@ const FAIL_MESSAGES = { | ||
'not be one of': (actual, expected, field) => `Expected ${field} field to not be one of these values (${expected}), but it was actually ${actual}`, | ||
'matches': (actual, expected, field) => `Expected ${field} field to match the pattern ${expected}, but it does not`, | ||
'does not match': (actual, expected, field) => `Expected ${field} field not to match the pattern ${expected}, but it does`, | ||
}; | ||
@@ -89,2 +100,4 @@ const SUCCESS_MESSAGES = { | ||
'not be one of': (expected, field) => `${field} field was not set to one of these values (${expected}), as expected`, | ||
'matches': (expected, field) => `The ${field} field matches the pattern ${expected}, as expected`, | ||
'does not match': (expected, field) => `The ${field} field does not match the pattern ${expected}, as expected`, | ||
}; | ||
@@ -91,0 +104,0 @@ function assert(operator, actualValue, expectedValue, field) { |
@@ -6,2 +6,3 @@ "use strict"; | ||
const csv_string_1 = require("csv-string"); | ||
const valid_operators_1 = require("../constants/valid-operators"); | ||
exports.operatorFailMessages = { | ||
@@ -18,2 +19,4 @@ 'be': 'Expected %s field to be %s, but it was actually %s', | ||
'not be one of': 'Expected %s field to not be one of these values (%s), but it was actually %s', | ||
'matches': 'Expected %s field to match the pattern %s, but it does not', | ||
'does not match': 'Expected %s field not to match the pattern %s, but it does', | ||
}; | ||
@@ -31,5 +34,6 @@ exports.operatorSuccessMessages = { | ||
'not be one of': '%s field was not set to one of these values (%s), as expected', | ||
'matches': 'The %s field matches the pattern %s, as expected', | ||
'does not match': 'The %s field does not match the pattern %s, as expected', | ||
}; | ||
function compare(operator, actualValue, value = null) { | ||
const validOperators = ['be', 'not be', 'contain', 'not contain', 'be greater than', 'be less than', 'be set', 'not be set', 'be one of', 'not be one of']; | ||
const dateTimeFormat = /\d{4}-\d{2}-\d{2}(?:.?\d{2}:\d{2}:\d{2})?/; | ||
@@ -39,3 +43,3 @@ operator = operator || ''; | ||
value = this.stringifyValue(value); | ||
if (validOperators.includes(operator.toLowerCase())) { | ||
if (valid_operators_1.validOperators.includes(operator.toLowerCase())) { | ||
if (operator.toLowerCase() == 'be') { | ||
@@ -91,2 +95,10 @@ return actualValue == value; | ||
} | ||
else if (operator.toLowerCase() == 'matches') { | ||
const regex = new RegExp(value); | ||
return regex.test(actualValue); | ||
} | ||
else if (operator.toLowerCase() == 'does not match') { | ||
const regex = new RegExp(value); | ||
return !regex.test(actualValue); | ||
} | ||
} | ||
@@ -93,0 +105,0 @@ else { |
{ | ||
"name": "@run-crank/utilities", | ||
"version": "0.4.2", | ||
"version": "0.4.3", | ||
"description": "Utility methods and functionality to be shared across all Cogs written in Typescript.", | ||
@@ -66,7 +66,3 @@ "homepage": "https://github.com/run-crank/typescript-cog-utilities#readme", | ||
"typescript": "^3.0.0" | ||
}, | ||
"directories": { | ||
"test": "tests" | ||
}, | ||
"author": "Angelito Salud" | ||
} | ||
} |
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
19153
19
319
0
1