New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

joi-nochange

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

joi-nochange - npm Package Compare versions

Comparing version 0.2.0 to 1.0.0-0

README.md

58

index.js
'use strict';
var Any = require('joi/lib/any');
var language = require('joi/lib/language');
var Hoek = require('hoek');
const Joi = require('joi');
const Hoek = require('hoek');
// monkey patch noChange() into Any's prototype
Any.prototype.noChange = function (sourceObj) {
// creates a rule for the provided base type
function createRule(joiType) {
const joiBaseType = Joi[joiType];
return this._test('noChange', null, (value, state, options) => {
return {
base: joiBaseType(),
name: joiType,
language: {
noChange: 'is not allowed to change' // maybe use 'may not change from {{q}}' instead?
},
rules: [{
name: 'noChange',
params: {
q: Joi.any()
},
validate(params, value, state, options) {
const path = state.path === '' ? null : state.path;
const origValue = Hoek.reach(sourceObj, path);
if (Hoek.deepEqual(origValue, value)) {
return null;
}
return this.createError('any.noChange', null, state, options);
});
};
const path = state.path === '' ? null : state.path;
const origValue = Hoek.reach(params.q, path);
// Add any.noChang error message to the language map
language.errors.any.noChange = 'is not allowed to change';
if (Hoek.deepEqual(origValue, value)) {
return null; // Everything is OK
}
return this.createError(joiType + '.noChange', {
v: value//,
// q: origValue
}, state, options);
}
}]
};
}
// extend Joi and export
// due to extending any() not extending other types, number(), string(), etc. we need to extend all of these manually
// see https://github.com/hapijs/joi/issues/577
module.exports = Joi
.extend(createRule('any'))
.extend(createRule('object'))
.extend(createRule('number'))
.extend(createRule('string'))
.extend(createRule('date'))
.extend(createRule('boolean'));
{
"name": "joi-nochange",
"version": "0.2.0",
"version": "1.0.0-0",
"description": "Adds noChange() to Joi",

@@ -30,6 +30,7 @@ "main": "index.js",

"dependencies": {
"hoek": "^3.0.4"
"hoek": "^3.0.4",
"joi": "9.0.0-6"
},
"peerDependencies": {
"joi": ">=6.0.0"
"joi": ">=9.0.0"
},

@@ -36,0 +37,0 @@ "devDependencies": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc