Skip to content

Commit

Permalink
PropertyAccess Patch
Browse files Browse the repository at this point in the history
Part of Client Merge Part 2
  • Loading branch information
Universal Web committed Mar 18, 2023
1 parent e4a6e9e commit 7a1283b
Showing 1 changed file with 30 additions and 36 deletions.
66 changes: 30 additions & 36 deletions utilities/propertyAccess.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,31 @@
module.exports = (state) => {
const {
utility: {
apply,
hasValue,
mapWhile,
import {
apply,
hasValue,
mapWhile,
} from 'Acid';
const regEx = /^([a-zA-Z0-9.]+)$/;
const sensitiveWords = /(constructor|prototype|window|self|top|alert|confirm|eval|function|Object|Array)/;
const errorNoneExistentProperty = 'None existent property';
const errorPropertyStringAccess = 'Property string access';
export function isPropertyValid(string) {
return regEx.test(string) && !sensitiveWords.test(string);
}
function goDownTree(currentPosition, item) {
if (apply(Object.prototype.hasOwnProperty, currentPosition, [item])) {
return true;
}
}
export function getPropertyFromString(string, objectMain, error) {
let object = objectMain;
const arraySplit = string.split('.');
mapWhile(arraySplit, (item) => {
if (goDownTree(object, item)) {
object = object[item];
} else {
error(errorPropertyStringAccess, errorNoneExistentProperty, string);
object = false;
return !hasValue(object);
}
} = state;
const regEx = /^([a-zA-Z0-9.]+)$/;
const sensitiveWords = /(constructor|prototype|window|self|top|alert|confirm|eval|function|Object|Array)/;
const isPropertyValid = (string) => {
return regEx.test(string) && !sensitiveWords.test(string);
};
const goDownTree = (currentPosition, item) => {
if (apply(Object.prototype.hasOwnProperty, currentPosition, [item])) {
return true;
}
};
const errorNoneExistentProperty = 'None existent property';
const errorPropertyStringAccess = 'Property string access';
const getPropertyFromString = (string, objectMain, error) => {
let object = objectMain;
const arraySplit = string.split('.');
mapWhile(arraySplit, (item) => {
if (goDownTree(object, item)) {
object = object[item];
} else {
error(errorPropertyStringAccess, errorNoneExistentProperty, string);
object = false;
return !hasValue(object);
}
});
return object;
};
state.utility.isPropertyValid = isPropertyValid;
state.utility.getProperty = getPropertyFromString;
};
});
return object;
}

0 comments on commit 7a1283b

Please sign in to comment.