@mikezimm/fps-core-v7
Version:
Library of reusable core interfaces, types and constants migrated from fps-library-v2
109 lines • 3.69 kB
JavaScript
/**
* 2024-09-07: Migrated from the same folder in fps-library-v2/banner/features/Tricky/...
*/
/**
* See full file in C:\Users\me\OneDrive...\SharePoint
*/
// Need to add: ?{}[],
// import { CurrentHostName } from "../../../logic/Strings/getSiteCollectionUrlFromLink";
import { CurrentHostName } from '../../../components/molecules/source-props/WindowLocationConstants';
import { allSP, TrickyTenantA, TrickyTenantC2, TrickyTenantFPS, TrickyTenantFPT, TrickyTenants } from './constants';
import { decrpt, encrpt } from './verify';
/**
* usage: testTricky(['test string1','test string2','test string3'])
* return: [ true, false, true ]
* @param tests
*/
export function testTenantA() {
let testLarge = ecrptMe(CurrentHostName);
let test = testLarge.indexOf(TrickyTenantA);
return test > -1 ? true : false;
}
// export function testTenantC() {
// let testLarge = ecrptMe( CurrentHostName);
// let test = testLarge.indexOf( TrickyTenantC );
// return test > -1 ? true : false;
// }
export function testTenantC2() {
let testLarge = ecrptMe(CurrentHostName);
let test = testLarge.indexOf(TrickyTenantC2);
return test > -1 ? true : false;
}
export function testTenantFPT() {
let testLarge = ecrptMe(CurrentHostName);
let test = testLarge.indexOf(TrickyTenantFPT);
return test > -1 ? true : false;
}
export function testTenantFPS() {
let testLarge = ecrptMe(CurrentHostName);
let test = testLarge.indexOf(TrickyTenantFPS);
return test > -1 ? true : false;
}
export function testTenants() {
return testTricky([CurrentHostName], TrickyTenants);
}
/**
*
* @param tests This should be array of longer strings
* @param testArray This should be array of shorter strings to be found in longer strings
*/
export function testTricky(tests, testArray = allSP) {
let encryptarr = [];
let found = [];
tests.map(original => {
let testing = ecrptMe(original);
let idx = testArray.indexOf(testing);
if (idx > -1) {
console.log('Found: ', idx, original);
found.push(true);
}
else {
console.log('NOT Found: ', idx, original);
found.push(false);
}
encryptarr.push(testing);
});
console.log('Finished!', tests, encryptarr);
console.log('results:', found);
return found;
}
function isOdd(num) { return (num % 2) == 1; }
// export function ecrptMe( str: string ) {
export function ecrptMe(str, key1 = decrpt, key2 = encrpt) {
let result = '';
for (var i = 0; i < str.length; i++) {
let testChar = str.charAt(i);
let idx = key2.indexOf(testChar);
//console.log( testChar, i, idx);
if (idx === -1) {
result += testChar;
}
else if (isOdd(i) === true) {
result += key1.charAt(key1.length - 1 - idx);
}
else {
result += key1.charAt(idx);
}
}
return result;
}
// export function ecrptMe( str: string ) {
export function dcrptMe(str) {
let result = '';
for (var i = 0; i < str.length; i++) {
let testChar = str.charAt(i);
let idx = encrpt.indexOf(testChar);
//let idx = isOdd(1) ? decript.indexOf(str.charAt(i)) : decript.lastIndexOf(str.charAt(i));
if (idx === -1) {
result += testChar;
}
else if (isOdd(i) === true) {
result += decrpt.charAt(decrpt.length - 1 - idx);
}
else {
result += decrpt.charAt(idx);
}
}
return result;
}
//# sourceMappingURL=logfun.js.map