aotrautils-srv 0.0.950 → 0.0.952

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
 
2
2
 
3
- /*utils COMMONS library associated with aotra version : «1_29072022-2359 (15/04/2024-03:13:05)»*/
3
+ /*utils COMMONS library associated with aotra version : «1_29072022-2359 (20/04/2024-05:43:52)»*/
4
4
  /*-----------------------------------------------------------------------------*/
5
5
 
6
6
 
@@ -1678,7 +1678,7 @@ function encodeXORNoPattern(strToEncode,key){
1678
1678
  return result;
1679
1679
  }
1680
1680
 
1681
- function generateRandomString(length,/*NULLABLE*/mode){
1681
+ function generateRandomString(length,/*NULLABLE*/mode=null){
1682
1682
 
1683
1683
  // This list must be very conservative, because we want to be able to pass it through GET URLs !
1684
1684
  // OLD (not enough conservative ?) : const ALLOWED_CHARS="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0912346789_-£¢¤¬²³¼½¾";
@@ -1825,6 +1825,26 @@ function generateRandomString(length,/*NULLABLE*/mode){
1825
1825
  return result;
1826
1826
  }
1827
1827
 
1828
+ function generateRandomStringFromOriginalString(str, randomFactor=1, mode=null){
1829
+ const strLength=str.length;
1830
+ const maxStrLength=strLength*randomFactor;
1831
+ const numberOfCharactersToChange=Math.getRandomInt(maxStrLength);
1832
+ const randomString=generateRandomString(numberOfCharactersToChange, mode);
1833
+ if(strLength<=maxStrLength) return randomString;
1834
+ let strIndexes=[];
1835
+ for(let i=0;i<strLength;i++){
1836
+ strIndexes.push(i);
1837
+ }
1838
+ let chosenIndexes=getRandomsInArray(strIndexes, numberOfCharactersToChange);
1839
+ let newStrAsArray=Array.from(str);
1840
+ // chosenIndexes array size is the same as the number of characters in string randomString :
1841
+ forEach(chosenIndexes,(randomIndex,i)=>{
1842
+ newStrAsArray[randomIndex]=randomString[i];
1843
+ });
1844
+ const newStr=newStrAsArray.join("");
1845
+ return newStr;
1846
+ }
1847
+
1828
1848
 
1829
1849
 
1830
1850
  // NOT AOTESTABLE !
@@ -1976,6 +1996,8 @@ window.foreach=function(arrayOfValues,doOnEachFunction,
1976
1996
  // for instance this is a valid javascript compare function : function(a, b){return a-b} so (100,20) returns positive result and (20,100) returns negative result !
1977
1997
  /*OPTIONAL*/compareFunction=null){
1978
1998
 
1999
+ // TODO : FIXME : Add the possibility to iterate over a string characters ?
2000
+
1979
2001
  if(!arrayOfValues){
1980
2002
  // SILENT ERROR :
1981
2003
  // // TRACE
@@ -5275,7 +5297,7 @@ AOTRAUTILS_LIB_IS_LOADED=true;
5275
5297
 
5276
5298
 
5277
5299
 
5278
- /*utils SERVER library associated with aotra version : «1_29072022-2359 (15/04/2024-03:13:05)»*/
5300
+ /*utils SERVER library associated with aotra version : «1_29072022-2359 (20/04/2024-05:43:52)»*/
5279
5301
  /*-----------------------------------------------------------------------------*/
5280
5302
 
5281
5303
 
@@ -7023,7 +7045,7 @@ performHTTPRequest=function(completeURL,httpMethod="GET",headers={},requestBodyO
7023
7045
  // CASE BROWSER CONTEXT :
7024
7046
  if(!isNodeContext || typeof(require)=="undefined"){
7025
7047
  // TRACE
7026
- lognow("INFO : We are not running in a nodejs context (isNodeContext:"+isNodeContext+";typeof(require):"+(typeof(require))+"). Using browser library.");
7048
+ lognow("INFO : We are not running in a browser context (isNodeContext:"+isNodeContext+";typeof(require):"+(typeof(require))+"). Using browser library.");
7027
7049
 
7028
7050
  const body=((contains(["POST","PUT"],httpMethod) && requestBodyOrNamedArgs)?JSON.stringify(requestBodyOrNamedArgs):null);
7029
7051
  return new Promise((resolve,reject)=>{
@@ -7065,6 +7087,10 @@ performHTTPRequest=function(completeURL,httpMethod="GET",headers={},requestBodyO
7065
7087
 
7066
7088
  // CASE NODEJS CONTEXT :
7067
7089
 
7090
+ // TRACE
7091
+ lognow("INFO : We are running in a nodejs context (isNodeContext:"+isNodeContext+";typeof(require):"+(typeof(require))+"). Using nodejs library.");
7092
+
7093
+
7068
7094
  const isSecure=(!empty(completeURL) && contains(completeURL.toLowerCase(),"https://"));
7069
7095
  const httpHandler=isSecure?require("https"):require("http");
7070
7096
 
@@ -7074,7 +7100,6 @@ performHTTPRequest=function(completeURL,httpMethod="GET",headers={},requestBodyO
7074
7100
  method: httpMethod,
7075
7101
  };
7076
7102
 
7077
-
7078
7103
  if(contains(["POST","PUT"],httpMethod)){
7079
7104
  options.json=true;
7080
7105
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aotrautils-srv",
3
- "version": "0.0.950",
3
+ "version": "0.0.952",
4
4
  "main": "aotrautils-srv.build.js",
5
5
  "description": "A library for vanilla javascript utils (server-side) used in aotra javascript CMS",
6
6
  "author": "Jeremie Ratomposon <info@alqemia.com> (https://alqemia.com)",