Comparing version 4.6.2 to 4.7.0
{ | ||
"name": "abolish", | ||
"version": "4.6.2", | ||
"version": "4.7.0", | ||
"description": "A javascript object validator.", | ||
@@ -18,12 +18,6 @@ "main": "index.js", | ||
"dependencies": { | ||
"lodash.clonedeep": "^4.5.0", | ||
"lodash.has": "^4.5.2", | ||
"lodash.startcase": "^4.4.0", | ||
"lodash.unset": "^4.5.2" | ||
"@types/lodash": "^4.14.177", | ||
"lodash": "^4.17.21" | ||
}, | ||
"devDependencies": { | ||
"@types/lodash.clonedeep": "^4.5.6", | ||
"@types/lodash.has": "^4.5.6", | ||
"@types/lodash.startcase": "^4.4.6", | ||
"@types/lodash.unset": "^4.5.6", | ||
"@types/node": "^16.11.9", | ||
@@ -30,0 +24,0 @@ "joi": "^17.4.2", |
@@ -10,3 +10,3 @@ "use strict"; | ||
const ObjectModifier_1 = __importDefault(require("./ObjectModifier")); | ||
const lodash_clonedeep_1 = __importDefault(require("lodash.clonedeep")); | ||
const lodash_1 = require("lodash"); | ||
/** | ||
@@ -140,3 +140,3 @@ * Abolish Class | ||
// clone rules | ||
rules = (0, lodash_clonedeep_1.default)(rules); | ||
rules = (0, lodash_1.cloneDeep)(rules); | ||
/** | ||
@@ -630,2 +630,5 @@ * Check for wildcard rules (*, $) | ||
validator: (value, rules, { error, modifier }) => { | ||
if (!value || typeof value !== "object") { | ||
return error(`:param must be an object.`); | ||
} | ||
const [err, valid] = Abolish.validate(value, rules); | ||
@@ -632,0 +635,0 @@ if (err) |
@@ -27,3 +27,3 @@ import Abolish from "./Abolish"; | ||
export declare function Rule(rules: string | any[]): any; | ||
export declare function abolish_Pick(object: any, keys: string[]): any; | ||
export declare function abolish_Pick(object: any, keys: string[]): Pick<any, string>; | ||
export declare function abolish_Set(object: any, path: any, value: any): any; | ||
@@ -30,0 +30,0 @@ export declare function abolish_Get(obj: any, path: string, defaultValue?: any): any; |
@@ -8,3 +8,3 @@ "use strict"; | ||
const StringToRules_1 = __importDefault(require("./StringToRules")); | ||
const lodash_startcase_1 = __importDefault(require("lodash.startcase")); | ||
const lodash_1 = require("lodash"); | ||
/** | ||
@@ -28,5 +28,5 @@ * Change to string to upperFirst | ||
? abolishInstance.config.useStartCaseInErrors | ||
? (0, lodash_startcase_1.default)(str) | ||
? (0, lodash_1.startCase)(str) | ||
: str | ||
: (0, lodash_startcase_1.default)(str); | ||
: (0, lodash_1.startCase)(str); | ||
} | ||
@@ -70,41 +70,11 @@ exports.abolish_StartCase = abolish_StartCase; | ||
function abolish_Pick(object, keys) { | ||
return keys.reduce((obj, key) => { | ||
if (object && object.hasOwnProperty(key)) { | ||
obj[key] = object[key]; | ||
} | ||
return obj; | ||
}, {}); | ||
return (0, lodash_1.pick)(object, keys); | ||
} | ||
exports.abolish_Pick = abolish_Pick; | ||
function abolish_Set(object, path, value) { | ||
if (Object(object) !== object) | ||
return object; // When object is not an object | ||
// If not yet an array, get the keys from the string-path | ||
if (!Array.isArray(path)) | ||
path = path.toString().match(/[^.[\]]+/g) || []; | ||
path.slice(0, -1).reduce((a, c, i // Iterate all of them except the last one | ||
) => Object(a[c]) === a[c] // Does the key exist and is its value an object? | ||
? // Yes: then follow that path | ||
a[c] | ||
: // No: create the key. Is the next key a potential array-index? | ||
(a[c] = | ||
Math.abs(path[i + 1]) >> 0 === +path[i + 1] | ||
? [] // Yes: assign a new array object | ||
: {}), // No: assign a new plain object | ||
object)[path[path.length - 1]] = value; // Finally assign the value to the last key | ||
return object; // Return the top-level object to allow chaining | ||
return (0, lodash_1.set)(object, path, value); | ||
} | ||
exports.abolish_Set = abolish_Set; | ||
function abolish_Get(obj, path, defaultValue) { | ||
if (path.indexOf(".") >= 0) { | ||
const travel = (regexp) => String.prototype.split | ||
.call(path, regexp) | ||
.filter(Boolean) | ||
.reduce((res, key) => (res !== null && res !== undefined ? res[key] : res), obj); | ||
const result = travel(/[,[\]]+?/) || travel(/[,[\].]+?/); | ||
return result === undefined || result === obj ? defaultValue : result; | ||
} | ||
else { | ||
return obj[path]; | ||
} | ||
return (0, lodash_1.get)(obj, path, defaultValue); | ||
} | ||
@@ -111,0 +81,0 @@ exports.abolish_Get = abolish_Get; |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
const Functions_1 = require("./Functions"); | ||
const lodash_has_1 = __importDefault(require("lodash.has")); | ||
const lodash_unset_1 = __importDefault(require("lodash.unset")); | ||
const lodash_1 = require("lodash"); | ||
/** | ||
@@ -43,3 +39,3 @@ * ObjectOnValidation | ||
has(path) { | ||
return (0, lodash_has_1.default)(this.data, path); | ||
return (0, lodash_1.has)(this.data, path); | ||
} | ||
@@ -72,3 +68,3 @@ /** | ||
unset(path) { | ||
return (0, lodash_unset_1.default)(this.data, path); | ||
return (0, lodash_1.unset)(this.data, path); | ||
} | ||
@@ -81,3 +77,3 @@ /** | ||
unsetThis() { | ||
return (0, lodash_unset_1.default)(this.data, this.path); | ||
return (0, lodash_1.unset)(this.data, this.path); | ||
} | ||
@@ -84,0 +80,0 @@ /** |
2
5
59793
1767
+ Added@types/lodash@^4.14.177
+ Addedlodash@^4.17.21
+ Added@types/lodash@4.17.15(transitive)
+ Addedlodash@4.17.21(transitive)
- Removedlodash.clonedeep@^4.5.0
- Removedlodash.has@^4.5.2
- Removedlodash.startcase@^4.4.0
- Removedlodash.unset@^4.5.2
- Removedlodash.clonedeep@4.5.0(transitive)
- Removedlodash.has@4.5.2(transitive)
- Removedlodash.startcase@4.4.0(transitive)
- Removedlodash.unset@4.5.2(transitive)