aotrautils 0.0.600 → 0.0.602

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 (23/09/2023-23:53:51)»*/
3
+ /*utils COMMONS library associated with aotra version : «1_29072022-2359 (24/09/2023-23:01:17)»*/
4
4
  /*-----------------------------------------------------------------------------*/
5
5
 
6
6
 
@@ -507,7 +507,7 @@ window.aotestMethods.getScenariiInTest=function(test){
507
507
 
508
508
  // CAUTION : We ABSOLUTELY need to iterate over a deep copy, or else it will create weird incomprehensible bugs
509
509
  // if we do another recursive browsing on the initial object !!!
510
- const scenario=JSON.parse(JSON.stringify(scenarioParam));
510
+ const scenario=parseJSON(stringifyObject(scenarioParam));
511
511
 
512
512
 
513
513
  const basePath=valuePath;
@@ -3805,13 +3805,13 @@ window.instanciate=function(className=null){
3805
3805
  JSON.stringifyDecycle=function(obj){
3806
3806
  let decycled=JSON.decycle(obj,null,"$className");
3807
3807
  // CANNOT USE stringifyObject(...) function because we are in a common, lower-level library !
3808
- return JSON.stringify(decycled);
3808
+ return stringifyObject(decycled);
3809
3809
  }
3810
3810
 
3811
3811
 
3812
3812
  JSON.parseRecycle=function(str){
3813
3813
 
3814
- const parsedDecycled=JSON.parse(str);
3814
+ const parsedDecycled=parseJSON(str);
3815
3815
  let restoreClass=function(objParam){
3816
3816
 
3817
3817
  if(!objParam || isPrimitive(objParam)) return objParam;
@@ -4365,9 +4365,7 @@ window.getAsFlatStructureImpl=function(rawObject, stateOnly=false
4365
4365
  });
4366
4366
 
4367
4367
 
4368
- // // DBG
4369
4368
  // CANNOT USE stringifyObject(...) function because we are in a common, lower-level library !
4370
- // console.log("¬¬¬¬resultMap STRINGIFY",JSON.stringify(resultMap));
4371
4369
 
4372
4370
  return resultMap;
4373
4371
  };
@@ -4609,8 +4607,8 @@ window.getAsTreeStructureImpl=function(oldMap, stateOnly=false, removeTypeInfo=t
4609
4607
  // as : {<POINTER_TO_ATTR_NAME> : "a uuid"} )*}) }
4610
4608
 
4611
4609
  if(typeof(oldMap)==="string"){
4612
- oldMap=JSON.parse(oldMap);
4613
- // oldMap=JSON.parse(oldMap.replace(/"/gim,"'"));
4610
+ oldMap=parseJSON(oldMap);
4611
+ // oldMap=parseJSON(oldMap.replace(/"/gim,"'"));
4614
4612
  // oldMap=eval(oldMap);
4615
4613
  }
4616
4614
 
@@ -4836,7 +4834,7 @@ JSON.decycle=function decycle(object, replacer, classNameAttributeName){
4836
4834
 
4837
4835
  // var a=[];
4838
4836
  // a[0]=a;
4839
- // return JSON.stringify(JSON.decycle(a));
4837
+ // return stringifyObject(JSON.decycle(a));
4840
4838
 
4841
4839
  //produces the string '[{"$ref":"$"}]'.
4842
4840
 
@@ -4900,7 +4898,7 @@ JSON.decycle=function decycle(object, replacer, classNameAttributeName){
4900
4898
  nu={};
4901
4899
  Object.keys(value).forEach(function (name){
4902
4900
  // CANNOT USE stringifyObject(...) function because we are in a common, lower-level library !
4903
- nu[name]=derez( value[name], path + "[" + JSON.stringify(name) + "]"
4901
+ nu[name]=derez( value[name], path + "[" + stringifyObject(name) + "]"
4904
4902
  );
4905
4903
  });
4906
4904
 
@@ -4937,7 +4935,7 @@ JSON.recycle=function recycle($){
4937
4935
 
4938
4936
  //So,
4939
4937
  // var s='[{"$ref":"$"}]';
4940
- // return JSON.recycle(JSON.parse(s));
4938
+ // return JSON.recycle(parseJSON(s));
4941
4939
  //produces an array containing a single element which is the array itself.
4942
4940
 
4943
4941
  var px=/^\$(?:\[(?:\d+|"(?:[^\\"\u0000-\u001f]|\\(?:[\\"\/bfnrt]|u[0-9a-zA-Z]{4}))*")\])*$/;
@@ -4997,7 +4995,7 @@ AOTRAUTILS_LIB_IS_LOADED=true;
4997
4995
 
4998
4996
 
4999
4997
 
5000
- /*utils CLIENT library associated with aotra version : «1_29072022-2359 (23/09/2023-23:53:51)»*/
4998
+ /*utils CLIENT library associated with aotra version : «1_29072022-2359 (24/09/2023-23:01:17)»*/
5001
4999
  /*-----------------------------------------------------------------------------*/
5002
5000
  /* ## Utility global methods in a browser (htmljs) client environment.
5003
5001
  *
@@ -5745,6 +5743,9 @@ function parseXMLString(txt){
5745
5743
 
5746
5744
  // JSON parsing management :
5747
5745
  function parseJSON(strParam){
5746
+
5747
+ if(!isString(strParam)) return strParam;
5748
+
5748
5749
  if (nothing(strParam))
5749
5750
  return null;
5750
5751
  var str=toOneSimplifiedLine(strParam.trim())
@@ -5788,6 +5789,9 @@ function parseJSON(strParam){
5788
5789
  }
5789
5790
 
5790
5791
  function stringifyObject(objectToStringify){
5792
+
5793
+ if(nothing(objectToStringify)) return null;
5794
+
5791
5795
  if (JSON && JSON.stringify && typeof JSON.stringify !== "undefined" && typeof JSON.stringify === "function"){
5792
5796
  return JSON.stringify(objectToStringify);
5793
5797
  }
@@ -7993,8 +7997,6 @@ function filterPoints(allPoints ,ctx/*DBG*/){
7993
7997
  }
7994
7998
  }
7995
7999
 
7996
- // DBG
7997
- //alert(JSON.stringify(constraints));
7998
8000
 
7999
8001
  let mediaHandler=getMediaHandlerIMPL(constraints, size, tagConfig, audioBufferSize, numberOfAudioChannels, doOnStart, {cameras:cameras, microphones:microphones});
8000
8002
  if(doFinallyWhenMultipleDevices) doFinallyWhenMultipleDevices(mediaHandler);
@@ -8158,7 +8160,7 @@ function filterPoints(allPoints ,ctx/*DBG*/){
8158
8160
  }
8159
8161
 
8160
8162
  // TRACE
8161
- console.log("INFO : Trying to start mediaHandler stream with constraints :",JSON.stringify(constraints));
8163
+ console.log("INFO : Trying to start mediaHandler stream with constraints :",stringifyObject(constraints));
8162
8164
 
8163
8165
  navigator.mediaDevices.getUserMedia(constraints).then(
8164
8166
  /* use the stream */
@@ -8328,7 +8330,7 @@ function filterPoints(allPoints ,ctx/*DBG*/){
8328
8330
  /* handle the error */
8329
8331
  function(error){
8330
8332
  // TRACE
8331
- console.log("ERROR : (Earlier process) Media handler could not start :",JSON.stringify(error));
8333
+ console.log("ERROR : (Earlier process) Media handler could not start :",stringifyObject(error));
8332
8334
 
8333
8335
 
8334
8336
 
@@ -8349,7 +8351,7 @@ function filterPoints(allPoints ,ctx/*DBG*/){
8349
8351
  startStream(mediaConstraints);
8350
8352
  }catch(error){
8351
8353
  // TRACE
8352
- console.log("ERROR : Media handler could not start because of an unhandled error :",JSON.stringify(error));
8354
+ console.log("ERROR : Media handler could not start because of an unhandled error :",stringifyObject(error));
8353
8355
  return null;
8354
8356
  }
8355
8357
 
@@ -12542,7 +12544,7 @@ createOritaMicroClient=function(url, port, isNode=false, staticMicroClientIdPara
12542
12544
  oritaClient.client.socketToServer.receive("protocol", (message) => {
12543
12545
 
12544
12546
  // TRACE
12545
- lognow("INFO : MICRO CLIENT : Server sent a message on the protocol channel : message:", JSON.stringify(message));
12547
+ lognow("INFO : MICRO CLIENT : Server sent a message on the protocol channel : message:", stringifyObject(message));
12546
12548
 
12547
12549
 
12548
12550
  if (contains(message.type, "response.microClient.registered")) {
@@ -13281,7 +13283,7 @@ createOritaMicroClient=function(url, port, isNode=false, staticMicroClientIdPara
13281
13283
 
13282
13284
 
13283
13285
 
13284
- /*utils GEOMETRY library associated with aotra version : «1_29072022-2359 (23/09/2023-23:53:51)»*/
13286
+ /*utils GEOMETRY library associated with aotra version : «1_29072022-2359 (24/09/2023-23:01:17)»*/
13285
13287
  /*-----------------------------------------------------------------------------*/
13286
13288
 
13287
13289
 
@@ -14520,7 +14522,7 @@ function rayVsUnitSphereClosestPoint(p, r) {
14520
14522
  // MUST REMAIN AT THE END OF THIS LIBRARY FILE !
14521
14523
 
14522
14524
  AOTRAUTILS_GEOMETRY_LIB_IS_LOADED=true;
14523
- /*utils SERVER library associated with aotra version : «1_29072022-2359 (23/09/2023-23:53:51)»*/
14525
+ /*utils SERVER library associated with aotra version : «1_29072022-2359 (24/09/2023-23:01:17)»*/
14524
14526
  /*-----------------------------------------------------------------------------*/
14525
14527
 
14526
14528
 
@@ -14625,7 +14627,7 @@ if(typeof(fs)==="undefined"){
14625
14627
  let resultData={};
14626
14628
 
14627
14629
  // 1)
14628
- if(!empty(resultFlat)) resultData=JSON.parse(resultFlat);
14630
+ if(!empty(resultFlat)) resultData=parseJSON(resultFlat);
14629
14631
 
14630
14632
  // 2)
14631
14633
  if(!empty(resultData) && isFlatMap(resultData)){
@@ -14648,7 +14650,7 @@ if(typeof(fs)==="undefined"){
14648
14650
 
14649
14651
  // reserved characters : -/\^$*+?.()|[]{}
14650
14652
  // CANNOT USE stringifyObject(...) function because we are in a common, lower-level library !
14651
- let dataFlatStr=JSON.stringify(dataFlatForClient)
14653
+ let dataFlatStr=stringifyObject(dataFlatForClient)
14652
14654
  // We «aerate» the produced JSON :
14653
14655
  .replace(/":[\w]*\{/gim,"\":{\n").replace(/,"/gim,",\n\"")
14654
14656
  // ...except for inline, escaped JSON string representations :
@@ -14692,7 +14694,7 @@ function isConnected(clientSocket){
14692
14694
 
14693
14695
  // -Server :
14694
14696
 
14695
- getServerParams=function(portParam=null,certPathParam=null,keyPathParam=null){
14697
+ getServerParams=function(portParam=null, certPathParam=null, keyPathParam=null){
14696
14698
 
14697
14699
  // Node dependencies :
14698
14700
  // https=require("https");
@@ -14837,11 +14839,11 @@ WebsocketImplementation={
14837
14839
  let dataResult=eventOrMessage;
14838
14840
 
14839
14841
  try{
14840
- dataResult=(WebsocketImplementation.useFlatStrings || isString(eventOrMessage)?JSON.parse(eventOrMessage):eventOrMessage);
14842
+ dataResult=(WebsocketImplementation.useFlatStrings || isString(eventOrMessage)?parseJSOn(eventOrMessage):eventOrMessage);
14841
14843
  }catch(error1){
14842
14844
  // TRACE
14843
14845
  lognow(`ERROR : Failed to parse JSON for string «${dataResult}»`,error1);
14844
- dataResult=(isString(eventOrMessage)?eventOrMessage:JSON.stringify(eventOrMessage));
14846
+ dataResult=(isString(eventOrMessage)?eventOrMessage:stringifyObject(eventOrMessage));
14845
14847
  }
14846
14848
 
14847
14849
  return dataResult;
@@ -14915,7 +14917,7 @@ WebsocketImplementation={
14915
14917
  // // DBG
14916
14918
  // lognow("(SERVER) RECEIVED SOMETHING FROM CLIENT...", eventOrMessage.data);
14917
14919
 
14918
- // dataWrapped=JSON.parse(dataWrapped);
14920
+ // dataWrapped=parseJSON(dataWrapped);
14919
14921
  // dataWrapped=getAt(dataWrapped,0);// We get the root element
14920
14922
 
14921
14923
 
@@ -15000,7 +15002,7 @@ WebsocketImplementation={
15000
15002
  let dataWrapped={channelName:channelName, data:data};
15001
15003
 
15002
15004
 
15003
- dataWrapped=JSON.stringify(dataWrapped);
15005
+ dataWrapped=stringifyObject(dataWrapped);
15004
15006
 
15005
15007
  // TODO : FIXME : Use one single interface !
15006
15008
  if(!WebsocketImplementation.useSocketIOImplementation) clientSocket.send(dataWrapped);
@@ -15025,7 +15027,7 @@ WebsocketImplementation={
15025
15027
 
15026
15028
  // Channel information is stored in exchanged data :
15027
15029
  let dataWrapped={channelName:channelName, data:data};
15028
- dataWrapped=JSON.stringify(dataWrapped);
15030
+ dataWrapped=stringifyObject(dataWrapped);
15029
15031
 
15030
15032
 
15031
15033
  // DBG
@@ -15263,9 +15265,9 @@ WebsocketImplementation={
15263
15265
  clientsRoomsTag:clientsRoomsTag,
15264
15266
  execute:(eventOrMessage)=>{
15265
15267
 
15266
- // dataWrapped=JSON.parse(dataWrapped);
15268
+ // dataWrapped=parseJSON(dataWrapped);
15267
15269
  // dataWrapped=getAt(dataWrapped,0);// We get the root element
15268
- // const dataWrapped=(WebsocketImplementation.useFlatStrings?JSON.parse(eventOrMessage):eventOrMessage);
15270
+ // const dataWrapped=(WebsocketImplementation.useFlatStrings?parseJSON(eventOrMessage):eventOrMessage);
15269
15271
 
15270
15272
  const dataWrapped=WebsocketImplementation.getMessageDataBothImplementations(eventOrMessage);
15271
15273
 
@@ -15327,7 +15329,7 @@ WebsocketImplementation={
15327
15329
  // console.log("(NODE CLIENT) SENDING DATA ! dataWrapped:",dataWrapped);
15328
15330
 
15329
15331
 
15330
- dataWrapped=JSON.stringify(dataWrapped);
15332
+ dataWrapped=stringifyObject(dataWrapped);
15331
15333
 
15332
15334
 
15333
15335
  // // DBG
@@ -15579,7 +15581,7 @@ WebsocketImplementation={
15579
15581
  console.log("(BROWSER) SENDING... : clientSocket :",clientSocket);
15580
15582
 
15581
15583
 
15582
- dataWrapped=JSON.stringify(dataWrapped);
15584
+ dataWrapped=stringifyObject(dataWrapped);
15583
15585
 
15584
15586
 
15585
15587
  // TODO : FIXME : Use one single interface !
@@ -15836,7 +15838,7 @@ initNodeServerInfrastructureWrapper=function(doOnClientConnection=null, doOnFina
15836
15838
  }else if(i==3){
15837
15839
  if(!isHashAsked){
15838
15840
  try{
15839
- const jsonConf=JSON.parse(val);
15841
+ const jsonConf=parseJSON(val);
15840
15842
  argCLPort=jsonConf.port;
15841
15843
  argCLCertPath=jsonConf.sslCertPath;
15842
15844
  argCLKeyPath=jsonConf.sslKeyPath;
aotrautils/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aotrautils",
3
- "version": "0.0.600",
3
+ "version": "0.0.602",
4
4
  "main": "aotrautils.build.js",
5
5
  "description": "A library for vanilla javascript utils (client-side) used in aotra javascript CMS",
6
6
  "author": "Jeremie Ratomposon <info@alqemia.com> (https://alqemia.com)",