-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |