indicative
Advanced tools
Comparing version 2.2.1 to 3.0.0
@@ -0,1 +1,19 @@ | ||
<a name="3.0.0"></a> | ||
# [3.0.0](https://github.com/poppinss/indicative/compare/v2.2.1...v3.0.0) (2017-08-19) | ||
### Bug Fixes | ||
* **rules:** work with short urls ([e9fa432](https://github.com/poppinss/indicative/commit/e9fa432)) | ||
* **sanitization:** make 2nd arg optional ([4bb95ec](https://github.com/poppinss/indicative/commit/4bb95ec)), closes [#88](https://github.com/poppinss/indicative/issues/88) | ||
* **validateAll:** return all validation errors ([a76f146](https://github.com/poppinss/indicative/commit/a76f146)), closes [#100](https://github.com/poppinss/indicative/issues/100) | ||
### Features | ||
* **rule:** add a new way to define rules ([26468ac](https://github.com/poppinss/indicative/commit/26468ac)) | ||
* **typescript:** add tsd ([ccbb8fc](https://github.com/poppinss/indicative/commit/ccbb8fc)) | ||
<a name="2.2.1"></a> | ||
@@ -2,0 +20,0 @@ ## [2.2.1](https://github.com/poppinss/indicative/compare/v2.2.0...v2.2.1) (2016-10-11) |
@@ -25,2 +25,1 @@ 'use strict' | ||
console.log(indicative.sanitizor.uppercase('hello world')) | ||
@@ -13,2 +13,3 @@ 'use strict' | ||
const Sanitization = require('./src/Sanitization') | ||
const Rule = require('./src/Rule') | ||
@@ -23,3 +24,4 @@ module.exports = { | ||
sanitizor: Sanitization.sanitizor, | ||
rule: Rule, | ||
'sanitizor.extend': Sanitization.sanitizor.extend | ||
} |
{ | ||
"name": "indicative", | ||
"version": "2.2.1", | ||
"version": "3.0.0", | ||
"description": "Intentionally beautiful schema and raw validator for nodejs", | ||
"main": "index.js", | ||
"types": "index.d.ts", | ||
"scripts": { | ||
"test": "npm run lint && istanbul cover _mocha --report lcovonly -- -R spec test && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage", | ||
"coverage": "npm run lint && istanbul cover _mocha test --bail", | ||
"lint": "standard" | ||
"lint": "standard", | ||
"pretest": "npm run lint", | ||
"posttest": "npm run coverage", | ||
"test:local": "FORCE_COLOR=true node bin/index.js --local", | ||
"test": "nyc npm run test:local", | ||
"test:win": "set FORCE_COLOR=true && node bin/index.js --win", | ||
"coverage": "nyc report --reporter=text-lcov | coveralls" | ||
}, | ||
@@ -14,21 +19,29 @@ "author": "amanvirk", | ||
"devDependencies": { | ||
"benchmark": "^2.1.0", | ||
"chai": "^3.5.0", | ||
"co-mocha": "^1.1.2", | ||
"coveralls": "^2.11.9", | ||
"cz-conventional-changelog": "^1.1.6", | ||
"istanbul": "^0.4.3", | ||
"mocha": "^3.0.2", | ||
"mocha-lcov-reporter": "^1.2.0", | ||
"standard": "^8.4.0" | ||
"benchmark": "^2.1.4", | ||
"coveralls": "^2.13.1", | ||
"cz-conventional-changelog": "^2.0.0", | ||
"japa": "^1.0.4", | ||
"japa-cli": "^1.0.1", | ||
"nyc": "^11.1.0", | ||
"semver": "^5.4.1", | ||
"standard": "^10.0.3" | ||
}, | ||
"dependencies": { | ||
"inflect": "^0.3.0", | ||
"lodash": "^4.12.0", | ||
"moment": "^2.13.0", | ||
"pope": "^1.0.0", | ||
"q": "^2.0.3" | ||
"haye": "^1.0.1", | ||
"lodash": "^4.17.4", | ||
"moment": "^2.18.1", | ||
"p-settle": "^2.0.0", | ||
"pluralize": "^6.0.0", | ||
"pope": "^1.0.2" | ||
}, | ||
"standard": { | ||
"global": ["it", "describe", "context", "before", "after", "beforeEach", "afterEach"] | ||
"global": [ | ||
"it", | ||
"describe", | ||
"context", | ||
"before", | ||
"after", | ||
"beforeEach", | ||
"afterEach" | ||
] | ||
}, | ||
@@ -57,3 +70,9 @@ "directories": { | ||
} | ||
}, | ||
"nyc": { | ||
"exclude": [ | ||
"bin", | ||
"test" | ||
] | ||
} | ||
} |
@@ -18,2 +18,3 @@ 'use strict' | ||
Modes.set = function (mode) { | ||
/* istanbul ignore next */ | ||
if (availableModes.indexOf(mode) <= -1) { | ||
@@ -20,0 +21,0 @@ console.log(`indicative: ${mode} is not a valid mode, switching back to normal mode`) |
@@ -12,3 +12,4 @@ 'use strict' | ||
const arrayExpressionRegex = /(\w[^\.\*]+)(\.\*\.?)(.+)?/ | ||
const haye = require('haye') | ||
const arrayExpressionRegex = /(\w[^.*]+)(\.\*\.?)(.+)?/ | ||
const _ = require('lodash') | ||
@@ -19,36 +20,2 @@ | ||
/** | ||
* parse a validation validation string to fetch | ||
* args from it. | ||
* | ||
* @param {String} validation | ||
* | ||
* @return {Object} | ||
* | ||
* @private | ||
*/ | ||
const _parseValidation = function (validation) { | ||
return _(validation.split(':')) | ||
.thru((value) => { | ||
const args = value[1] ? value[1].split(',') : [] | ||
return {name: value[0], args} | ||
}) | ||
.value() | ||
} | ||
/** | ||
* parse all validation strings to object. | ||
* | ||
* @param {Array} validations | ||
* | ||
* @return {Array} | ||
* | ||
* @private | ||
*/ | ||
const _parseValidations = function (validations) { | ||
return _.map(validations, (validation) => { | ||
return _parseValidation(validation) | ||
}) | ||
} | ||
/** | ||
* parse a given set of validations to a consumable array. | ||
@@ -61,4 +28,19 @@ * | ||
Parser.parse = function (validations) { | ||
const validationsArray = validations instanceof Array ? validations : validations.split('|') | ||
return _parseValidations(validationsArray) | ||
if (validations instanceof Array) { | ||
return validations.map((rule) => rule) | ||
} | ||
/** | ||
* Add .map to be backward compatible, since we want | ||
* rules to always expected an array of string, | ||
* null or array. | ||
* | ||
* Can be changed later | ||
*/ | ||
return haye.fromPipe(validations).toArray().map((i) => { | ||
return { | ||
name: i.name, | ||
args: i.args === null ? [] : (i.args instanceof Array === true ? i.args : [i.args]) | ||
} | ||
}) | ||
} | ||
@@ -151,4 +133,5 @@ | ||
_.extend(result, Parser.transformRule(data, rule, field)) | ||
}) | ||
return result | ||
}, {}) | ||
.value() | ||
} |
@@ -17,4 +17,4 @@ 'use strict' | ||
*/ | ||
const urlRegex = /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,63}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/i | ||
const emailRegex = /^([\w-]+(?:\.[\w-]+)*)(\+[\w\.-]+)?@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,63}(?:\.[a-z]{2})?)$/i | ||
const urlRegex = /https?:\/\/(www\.)?([-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-z]{2,63}|localhost)\b([-a-zA-Z0-9@:%_+.~#?&//=]*)/i | ||
const emailRegex = /^([\w-]+(?:\.[\w-]+)*)(\+[\w.-]+)?@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,63}(?:\.[a-z]{2})?)$/i | ||
const phoneRegex = /\b\d{3}[-.]?\d{3}[-.]?\d{4}\b/ | ||
@@ -537,3 +537,2 @@ const creditCardRegex = /^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|6(?:011|5[0-9]{2})[0-9]{12}|(?:2131|1800|35\d{3})\d{11})$/ | ||
downScale++ | ||
return | ||
} | ||
@@ -767,3 +766,2 @@ }) | ||
matchesCount++ | ||
return | ||
} | ||
@@ -770,0 +768,0 @@ }) |
@@ -12,2 +12,5 @@ 'use strict' | ||
const _ = require('lodash') | ||
const pluralize = require('pluralize') | ||
const domains = /^hotmail\.com|gmail\.com|live\.com$/ | ||
@@ -17,4 +20,2 @@ const linksRegex = /<a\b[^>]*>(.*?)<\/a>/ig | ||
const inflect = require('inflect') | ||
let SanitizationFilters = exports = module.exports = {} | ||
@@ -189,3 +190,3 @@ | ||
SanitizationFilters.toInt = function (value, args) { | ||
const radix = typeof (args[0]) === 'number' ? args[0] : 10 | ||
const radix = _.isNumber(_.get(args, '0')) ? args[0] : 10 | ||
return parseInt(value, radix) | ||
@@ -230,3 +231,3 @@ } | ||
SanitizationFilters.stripTags = function (value, args) { | ||
const strict = (args[0] && args[0] === 'trim') | ||
const strict = _.get(args, '0') === 'trim' | ||
value = _replace(value, tagsRegex, '') | ||
@@ -240,39 +241,39 @@ if (strict) { | ||
SanitizationFilters.plural = function (value) { | ||
return inflect.pluralize(value) | ||
return pluralize(value) | ||
} | ||
SanitizationFilters.singular = function (value) { | ||
return inflect.singularize(value) | ||
return pluralize.singular(value) | ||
} | ||
SanitizationFilters.camelCase = function (value) { | ||
return inflect.camelize(value) | ||
return _.camelCase(value) | ||
} | ||
SanitizationFilters.capitalize = function (value) { | ||
return inflect.capitalize(value) | ||
return _.capitalize(value) | ||
} | ||
SanitizationFilters.decapitalize = function (value) { | ||
return inflect.decapitalize(value) | ||
return _.lowerFirst(value) | ||
} | ||
SanitizationFilters.title = function (value) { | ||
return inflect.titleize(value) | ||
return _.startCase(value) | ||
} | ||
SanitizationFilters.underscore = function (value) { | ||
return inflect.underscore(value) | ||
return _.snakeCase(value) | ||
} | ||
SanitizationFilters.toDash = function (value) { | ||
return inflect.dasherize(value) | ||
return _.kebabCase(value) | ||
} | ||
SanitizationFilters.slug = function (value) { | ||
return inflect.parameterize(value) | ||
return _.kebabCase(value) | ||
} | ||
SanitizationFilters.humanize = function (value) { | ||
return inflect.humanize(value) | ||
return _.upperFirst(_.lowerCase(value)) | ||
} |
@@ -31,3 +31,3 @@ 'use strict' | ||
const skippable = function (value) { | ||
return Modes.get() === 'strict' ? typeof (value) === undefined : !Raw.existy(value) | ||
return Modes.get() === 'strict' ? typeof (value) === 'undefined' : !Raw.existy(value) | ||
} | ||
@@ -752,3 +752,2 @@ | ||
withFieldCount++ | ||
return | ||
} | ||
@@ -836,3 +835,2 @@ }) | ||
withOutFieldCounts++ | ||
return | ||
} | ||
@@ -879,3 +877,2 @@ }) | ||
withOutFieldCounts++ | ||
return | ||
} | ||
@@ -1043,3 +1040,3 @@ }) | ||
if (!min || !max) { | ||
return reject('min and max values are required for range validation') | ||
return reject(new Error('min and max values are required for range validation')) | ||
} | ||
@@ -1286,3 +1283,10 @@ | ||
const expression = regexFlags ? new RegExp(regexExp, regexFlags) : new RegExp(regexExp) | ||
/** | ||
* If regex is already a regex expression, then | ||
* use it otherwise wrap it inside regex | ||
*/ | ||
const expression = regexExp instanceof RegExp === true | ||
? regexExp | ||
: (regexFlags ? new RegExp(regexExp, regexFlags) : new RegExp(regexExp)) | ||
if (Raw.regex(fieldValue, expression)) { | ||
@@ -1289,0 +1293,0 @@ resolve('validation passed') |
@@ -15,3 +15,3 @@ 'use strict' | ||
const _ = require('lodash') | ||
const Q = require('q') | ||
const pSettle = require('p-settle') | ||
@@ -33,8 +33,6 @@ const ValidationEngine = exports = module.exports = {} | ||
ValidationEngine.validateField = function (data, field, validations, messages, runAll) { | ||
const method = runAll ? 'allSettled' : 'all' | ||
return Q[method]( | ||
_.map(validations, (validation) => { | ||
return ValidationEngine.runValidationOnField(data, field, validation.name, messages, validation.args) | ||
}) | ||
) | ||
const validationsMap = _.map(validations, (validation) => { | ||
return ValidationEngine.runValidationOnField(data, field, validation.name, messages, validation.args) | ||
}) | ||
return runAll ? pSettle(validationsMap) : Promise.all(validationsMap) | ||
} | ||
@@ -57,7 +55,9 @@ | ||
return Q.Promise((resolve, reject) => { | ||
return new Promise((resolve, reject) => { | ||
validationMethod(data, field, message, args, _.get) | ||
.then(resolve) | ||
.catch((error) => { | ||
/* eslint-disable */ | ||
reject({field, validation, message: error}) | ||
/* eslint-enable */ | ||
}) | ||
@@ -64,0 +64,0 @@ }) |
@@ -18,3 +18,3 @@ 'use strict' | ||
const Modes = require('../Modes') | ||
const Q = require('q') | ||
const pSettle = require('p-settle') | ||
@@ -41,3 +41,3 @@ /** | ||
* | ||
* @param {Array} results | ||
* @param {Array} fieldsResults | ||
* | ||
@@ -49,12 +49,18 @@ * @return {void} | ||
*/ | ||
function _settleAllPromises (results) { | ||
const errors = _(results) | ||
function _settleAllPromises (fieldsResults) { | ||
const errorsList = _(fieldsResults) | ||
.transform((errors, field) => { | ||
const ruleErrors = _.filter(field.value, (item) => item.isRejected) | ||
if (ruleErrors) { | ||
errors.push(ruleErrors.map((item) => item.reason)) | ||
} | ||
}, []) | ||
.flatten() | ||
.map((result) => { | ||
return result.state === 'rejected' ? result.reason : null | ||
}) | ||
.compact() | ||
.value() | ||
if (_.size(errors)) { | ||
throw errors | ||
/** | ||
* Throw erros when there are errors | ||
*/ | ||
if (_.size(errorsList)) { | ||
throw errorsList | ||
} | ||
@@ -81,6 +87,10 @@ } | ||
return Q.Promise((resolve, reject) => { | ||
Q.all(validations) | ||
return new Promise((resolve, reject) => { | ||
Promise.all(validations) | ||
.then(() => resolve(data)) | ||
.catch((error) => reject([error])) | ||
.catch((error) => { | ||
/* eslint-disable */ | ||
reject([error]) | ||
/* eslint-enable */ | ||
}) | ||
}) | ||
@@ -104,4 +114,4 @@ } | ||
return Q.Promise((resolve, reject) => { | ||
Q.all(validations) | ||
return new Promise((resolve, reject) => { | ||
pSettle(validations) | ||
.then(_settleAllPromises) | ||
@@ -108,0 +118,0 @@ .then(() => resolve(data)) |
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
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
434926
8
25
3175
6
2
+ Addedhaye@^1.0.1
+ Addedp-settle@^2.0.0
+ Addedpluralize@^6.0.0
+ Addedhaye@1.0.1(transitive)
+ Addedp-limit@1.3.0(transitive)
+ Addedp-reflect@1.0.0(transitive)
+ Addedp-settle@2.1.0(transitive)
+ Addedp-try@1.0.0(transitive)
+ Addedpluralize@6.0.0(transitive)
- Removedinflect@^0.3.0
- Removedq@^2.0.3
- Removedasap@2.0.6(transitive)
- Removedinflect@0.3.0(transitive)
- Removedpop-iterate@1.0.1(transitive)
- Removedq@2.0.3(transitive)
- Removedweak-map@1.0.8(transitive)
Updatedlodash@^4.17.4
Updatedmoment@^2.18.1
Updatedpope@^1.0.2