node-red-contrib-prib-functions 0.22.0 → 0.23.3
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.
- package/README.md +142 -92
- package/lib/AlphaBeta.js +32 -0
- package/lib/GraphDB.js +40 -9
- package/lib/MinMax.js +17 -0
- package/lib/Tree.js +64 -0
- package/lib/common.js +128 -0
- package/lib/objectExtensions.js +213 -80
- package/lib/timeDimension.js +36 -0
- package/lib/typedInput.js +77 -0
- package/matrix/matrixNode.html +2 -1
- package/package.json +15 -13
- package/test/00-objectExtensions.js +192 -1
- package/test/02-graphdb.js +46 -0
- package/test/data/.config.nodes.json +3 -3
- package/test/data/.config.nodes.json.backup +3 -3
- package/test/data/.config.users.json +3 -2
- package/test/data/.config.users.json.backup +3 -2
- package/test/data/.flow.json.backup +3875 -472
- package/test/data/flow.json +3874 -471
- package/test/data/package-lock.json +11 -11
- package/test/data/shares/.config.nodes.json +589 -0
- package/test/data/shares/.config.runtime.json +4 -0
- package/test/data/shares/.config.runtime.json.backup +3 -0
- package/test/data/shares/.config.users.json +32 -0
- package/test/data/shares/.config.users.json.backup +29 -0
- package/test/data/shares/.flow.json.backup +230 -0
- package/test/data/shares/.flow_cred.json.backup +3 -0
- package/test/data/shares/flow.json +267 -0
- package/test/data/shares/flow_cred.json +3 -0
- package/test/data/shares/package.json +6 -0
- package/test/data/shares/settings.js +544 -0
- package/testing/test.js +63 -29
- package/transform/transform.html +185 -20
- package/transform/transform.js +272 -265
- package/transform/xlsx2.js +74 -0
- package/visual/shapes/base..js +1 -0
- package/visual/visual.js +0 -0
- package/visual/visualNode.js +45 -0
package/lib/objectExtensions.js
CHANGED
|
@@ -1,71 +1,54 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
if(!String.prototype.in)
|
|
11
|
-
String.prototype.in = function (str) {
|
|
12
|
-
for (var i = 0; i < arguments.length; i++)
|
|
13
|
-
if(this==arguments[i]) return true;
|
|
14
|
-
return false;
|
|
15
|
-
};
|
|
16
|
-
if(!String.prototype.startsWith)
|
|
17
|
-
String.prototype.startsWith = function (str) {
|
|
18
|
-
return this.slice(0, str.length) == str;
|
|
19
|
-
};
|
|
20
|
-
if(!String.prototype.toTitle)
|
|
21
|
-
String.prototype.toTitle = function () {
|
|
22
|
-
var title=this.substr(0,1).toUpperCase()
|
|
23
|
-
,lastLowerCase=false;
|
|
24
|
-
for(var i=1 ; i<this.length; i++ ) {
|
|
25
|
-
char=this.substr(i,1);
|
|
26
|
-
if(char==char.toUpperCase()) {
|
|
27
|
-
if(lastLowerCase) title+=' ';
|
|
28
|
-
lastLowerCase=false;
|
|
29
|
-
if(char=='_') continue;
|
|
30
|
-
if(char==' ') continue;
|
|
31
|
-
} else lastLowerCase=true;
|
|
32
|
-
title+=char;
|
|
33
|
-
}
|
|
34
|
-
return title;
|
|
35
|
-
};
|
|
36
|
-
if(!String.prototype.to)
|
|
37
|
-
String.prototype.to = function (type) {
|
|
38
|
-
if (this==null) return null;
|
|
39
|
-
if (type==null) return value;
|
|
40
|
-
return this['to'+type.capitalize()];
|
|
1
|
+
const defineMethod=(object,name,call)=>{
|
|
2
|
+
if(name in object.prototype) return
|
|
3
|
+
try{
|
|
4
|
+
Object.defineProperty(object.prototype, name, {
|
|
5
|
+
enumerable: false,
|
|
6
|
+
value: call
|
|
7
|
+
})
|
|
8
|
+
} catch(ex){
|
|
9
|
+
console.error("defining "+name,ex.message)
|
|
41
10
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
if(
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
11
|
+
}
|
|
12
|
+
const toDateType=aDate=>aDate instanceof Date? aDate : new Date(Date.parse(aDate))
|
|
13
|
+
const toDateTypeZulu=aDate=>aDate instanceof Date? aDate : new Date(aDate)
|
|
14
|
+
defineMethod(Array,'move',function(from, to) {
|
|
15
|
+
if(from<to) to--
|
|
16
|
+
this.splice(to, 0, this.splice(from, 1)[0])
|
|
17
|
+
})
|
|
18
|
+
defineMethod(String,"in",function (...str) {
|
|
19
|
+
for (var i = 0; i < arguments.length; i++)
|
|
20
|
+
if(this==arguments[i]) return true
|
|
21
|
+
return false
|
|
22
|
+
})
|
|
23
|
+
defineMethod(String,"capitalize",function() {return this.charAt(0).toUpperCase() + this.slice(1)})
|
|
24
|
+
defineMethod(String,"toCapitalized",function() {return this.charAt(0).toUpperCase() + this.slice(1)})
|
|
25
|
+
defineMethod(String,"to",function (type) {
|
|
26
|
+
if(type==null) return value
|
|
27
|
+
return this['to'+type.capitalize()]
|
|
28
|
+
})
|
|
29
|
+
defineMethod(String,"toReal",function (){return parseFloat(this)})
|
|
30
|
+
defineMethod(String,"toTitle", function (){return this.replace(/\w\S*/g, text => text.capitalize())})
|
|
31
|
+
|
|
32
|
+
defineMethod(String,"toTitleGrammatical", function (){
|
|
33
|
+
const lowerCaseList = ['a', 'an', 'the', 'and', 'but', 'or', 'for', 'nor', 'as', 'at',
|
|
34
|
+
'by', 'from', 'in', 'into', 'of', 'on', 'onto', 'to', 'with', 'yet', 'so','upon', 'like', 'over', 'plus', 'up', 'down', 'off', 'near'];
|
|
35
|
+
const title=this.replace(/\p{L}+/gu, (word)=>{
|
|
36
|
+
const wordLowerCase=word.toLowerCase()
|
|
37
|
+
return lowerCaseList.includes(wordLowerCase) ? wordLowerCase : word.capitalize()
|
|
38
|
+
})
|
|
39
|
+
return title.capitalize()
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
defineMethod(String,"toInt",function() {return parseInt(this)})
|
|
43
|
+
if(!String.prototype.toInt) String.prototype.toInteger=String.prototype.toInt
|
|
44
|
+
defineMethod(String,"toTimestamp",function () {
|
|
45
|
+
return Date.parse(this.substring(0,4)+'/'+this.substring(5,2)+'/'+this.substring(8,11))
|
|
46
|
+
+ parseInt(this.substring(21,3));
|
|
47
|
+
})
|
|
48
|
+
defineMethod(String,"toTime",function () {return Date.parse(this)})
|
|
49
|
+
defineMethod(String,"CRLF2BR", function(){return this.replace("\n\r","<br/>").replace("\n","<br/>")})
|
|
67
50
|
|
|
68
|
-
Array
|
|
51
|
+
defineMethod(Array,"findSorted",function(searchElement,minIndex = 0,maxIndex = this.length - 1) {
|
|
69
52
|
let currentIndex, currentElement
|
|
70
53
|
while(minIndex <= maxIndex) {
|
|
71
54
|
currentIndex = (minIndex + maxIndex) / 2 | 0
|
|
@@ -77,8 +60,8 @@ Array.prototype.findSorted = function(searchElement,minIndex = 0,maxIndex = this
|
|
|
77
60
|
} else return currentIndex
|
|
78
61
|
}
|
|
79
62
|
return -minIndex
|
|
80
|
-
}
|
|
81
|
-
Array
|
|
63
|
+
})
|
|
64
|
+
defineMethod(Array,"addSorted",function(element) {
|
|
82
65
|
if(this.length){
|
|
83
66
|
const position = -this.findSorted(element)
|
|
84
67
|
if(position<0 ) return -position
|
|
@@ -87,15 +70,16 @@ Array.prototype.findSorted = function(searchElement,minIndex = 0,maxIndex = this
|
|
|
87
70
|
}
|
|
88
71
|
this.push(element)
|
|
89
72
|
return 0
|
|
90
|
-
}
|
|
91
|
-
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
defineMethod(Object,"addList",function(property,object) {
|
|
92
76
|
try{
|
|
93
77
|
this[property].push(object)
|
|
94
78
|
} catch(ex) {
|
|
95
79
|
this[property]=[object]
|
|
96
80
|
}
|
|
97
|
-
}
|
|
98
|
-
Object
|
|
81
|
+
})
|
|
82
|
+
defineMethod(Object,"addErrorFunctions",function(){
|
|
99
83
|
this.onError=function(call){
|
|
100
84
|
if(this.errorStack) this.errorStack.push(call)
|
|
101
85
|
else this.errorStack=[this.call]
|
|
@@ -113,8 +97,9 @@ Object.prototype.addErrorFunctions = function(){
|
|
|
113
97
|
if(typeof ex == "string") throw Error(ex)
|
|
114
98
|
throw ex
|
|
115
99
|
}
|
|
116
|
-
}
|
|
117
|
-
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
const colourSmallList={
|
|
118
103
|
"Red":'#FF0000',
|
|
119
104
|
"Turquoise":'#00FFFF',
|
|
120
105
|
"Grass Green":'#408080',
|
|
@@ -132,7 +117,7 @@ if(!colourSmallList) var colourSmallList={
|
|
|
132
117
|
"Light Purple":'#FF0080',
|
|
133
118
|
"Dark Grey":'#808080'
|
|
134
119
|
}
|
|
135
|
-
|
|
120
|
+
const colours ={
|
|
136
121
|
AliceBlue: '#F0F8FF',
|
|
137
122
|
AntiqueWhite: '#FAEBD7',
|
|
138
123
|
Aqua: '#00FFFF',
|
|
@@ -282,8 +267,7 @@ if(!colours) var colours ={
|
|
|
282
267
|
Yellow: '#FFFF00',
|
|
283
268
|
YellowGreen: '#9ACD32'
|
|
284
269
|
}
|
|
285
|
-
|
|
286
|
-
String.prototype.csvLine=function(delimiter=",",quote='"'){
|
|
270
|
+
defineMethod(String,"csvLine",function(delimiter=",",quote='"'){
|
|
287
271
|
let i=this.length,j=i,charInQuote,result=[]
|
|
288
272
|
if(i==0) return result
|
|
289
273
|
delimiter:while(i--){
|
|
@@ -317,9 +301,8 @@ String.prototype.csvLine=function(delimiter=",",quote='"'){
|
|
|
317
301
|
const v=this.substring(i+1,j)
|
|
318
302
|
result.unshift(v.length?isNaN(v)? v : Number(v):null)
|
|
319
303
|
return result
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
String.prototype.csvFile=function(delimiter=",",quote='"'){
|
|
304
|
+
})
|
|
305
|
+
defineMethod(String,"csvFile",function(delimiter=",",quote='"'){
|
|
323
306
|
let i=this.length,j=i,charInQuote,result=[],line=[]
|
|
324
307
|
if(i==0) return result
|
|
325
308
|
line:while(i--){
|
|
@@ -358,4 +341,154 @@ String.prototype.csvFile=function(delimiter=",",quote='"'){
|
|
|
358
341
|
result.unshift(line)
|
|
359
342
|
}
|
|
360
343
|
return result
|
|
344
|
+
})
|
|
345
|
+
|
|
346
|
+
defineMethod(Date,"isBetween",function(min, max) {return !(this < toDateType(min) || this > toDateType(max))})
|
|
347
|
+
defineMethod(Number,"isBetween",function(min, max) {return !(this < min || this > max)})
|
|
348
|
+
defineMethod(String,"isBetween",function(min, max) {return !(this < min || this > max)})
|
|
349
|
+
defineMethod(Object,"toSimpleArray",function(prefix) {
|
|
350
|
+
const returnValue=[]
|
|
351
|
+
for (let property in this) {
|
|
352
|
+
if(this[property]==null || this[property].enumerable==null || this[property].enumerable)
|
|
353
|
+
returnValue.push([(prefix?prefix:"")+property,this[property],typeof this[property]])
|
|
354
|
+
}
|
|
355
|
+
return returnValue
|
|
356
|
+
})
|
|
357
|
+
defineMethod(Object,"toSimpleArrayIgnoreNulls",function(prefix) {
|
|
358
|
+
const returnValue=[]
|
|
359
|
+
for (let property in this) {
|
|
360
|
+
if(this[property]==null ) continue
|
|
361
|
+
if(this[property].enumerable==null || this[property].enumerable)
|
|
362
|
+
returnValue.push([(prefix?prefix:"")+property,this[property],typeof this[property]])
|
|
363
|
+
}
|
|
364
|
+
return returnValue
|
|
365
|
+
})
|
|
366
|
+
|
|
367
|
+
defineMethod(String,"in",function () {
|
|
368
|
+
for (let i = 0; i < arguments.length; i++)
|
|
369
|
+
if(this.toString()===arguments[i]) return true;
|
|
370
|
+
return false
|
|
371
|
+
})
|
|
372
|
+
defineMethod(String,"startsWithList",function () {
|
|
373
|
+
for (var i = 0; i < arguments.length; i++)
|
|
374
|
+
if(this.slice(0, arguments[i].length)===arguments[i]) return true
|
|
375
|
+
return false
|
|
376
|
+
})
|
|
377
|
+
defineMethod(String,"startsWithListAnyCase",function (...list) {
|
|
378
|
+
for (var i = 0; i < list.length; i++){
|
|
379
|
+
const testString=list[i].toLowerCase()
|
|
380
|
+
if(this.slice(0, testString.length).toLowerCase()==testString) return true
|
|
381
|
+
}
|
|
382
|
+
return false
|
|
383
|
+
})
|
|
384
|
+
defineMethod(String,"xmlStringEncode",function() {
|
|
385
|
+
return this.toString().replace(/([\&"<>])/g, function(str, item) {
|
|
386
|
+
return {
|
|
387
|
+
'&': '&',
|
|
388
|
+
'"': '"',
|
|
389
|
+
'<': '<',
|
|
390
|
+
'>': '>'
|
|
391
|
+
}[item]
|
|
392
|
+
});
|
|
393
|
+
})
|
|
394
|
+
|
|
395
|
+
defineMethod(Number,"toAbbreviated",function() {
|
|
396
|
+
const digits=(v,e)=>{
|
|
397
|
+
const nv=v/Math.pow(10,e)
|
|
398
|
+
const anv=Math.abs(nv)
|
|
399
|
+
if(anv<10) return nv.toFixed(2).toString()
|
|
400
|
+
if(anv<100) return nv.toFixed(1).toString()
|
|
401
|
+
return nv.toFixed(0).toString()
|
|
402
|
+
}
|
|
403
|
+
const a=Math.abs(this)
|
|
404
|
+
if(a>Math.pow(10,15)) return digits(this,15)+'P'
|
|
405
|
+
if(a>Math.pow(10,12)) return digits(this,12)+'T'
|
|
406
|
+
if(a>Math.pow(10,9)) return digits(this,9)+'G'
|
|
407
|
+
if(a>Math.pow(10,6)) return digits(this,6)+'M'
|
|
408
|
+
if(a>Math.pow(10,3)) return digits(this,3)+'K'
|
|
409
|
+
return digits(this,0)
|
|
410
|
+
})
|
|
411
|
+
|
|
412
|
+
defineMethod(BigInt,"toAbbreviated",function() {
|
|
413
|
+
const digits=(v,e)=>{
|
|
414
|
+
const nv=v/Math.pow(10,e)
|
|
415
|
+
const anv=Math.abs(nv)
|
|
416
|
+
if(anv<10) return nv.toFixed(2).toString()
|
|
417
|
+
if(anv<100) return nv.toFixed(1).toString()
|
|
418
|
+
return nv.toFixed(0).toString()
|
|
419
|
+
}
|
|
420
|
+
const a=Math.abs(this)
|
|
421
|
+
if(a>Math.pow(10,15)) return digits(this,15)+'P'
|
|
422
|
+
if(a>Math.pow(10,12)) return digits(this,12)+'T'
|
|
423
|
+
if(a>Math.pow(10,9)) return digits(this,9)+'G'
|
|
424
|
+
if(a>Math.pow(10,6)) return digits(this,6)+'M'
|
|
425
|
+
if(a>Math.pow(10,3)) return digits(this,3)+'K'
|
|
426
|
+
return digits(this,0)
|
|
427
|
+
})
|
|
428
|
+
|
|
429
|
+
|
|
430
|
+
defineMethod(String,"getWord",function(wordPosition) {return this.split(/\s+/g,wordPosition+1)[wordPosition-1]??""})
|
|
431
|
+
|
|
432
|
+
const coalesce=(...args)=>{
|
|
433
|
+
for (var i=0; i<args.length; ++i)
|
|
434
|
+
if (args[i] != null) return args[i]
|
|
435
|
+
return null;
|
|
436
|
+
}
|
|
437
|
+
const nullif=(a,b)=>{return a==b?null:a}
|
|
438
|
+
//missing Float16Array,
|
|
439
|
+
[ArrayBuffer,Number,Boolean,BigInt,Date,String,Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,BigInt64Array,BigUint64Array,Float32Array,Float64Array].forEach(type=>{
|
|
440
|
+
defineMethod(type,"deepClone",function(){ return new type(this)})
|
|
441
|
+
})
|
|
442
|
+
|
|
443
|
+
const getWord=(value,wordPosition)=>value.split(/\s+/g,wordPosition+1)[wordPosition-1]
|
|
444
|
+
|
|
445
|
+
const deepClone=(deepObject) =>{
|
|
446
|
+
if(deepObject==null) return null;
|
|
447
|
+
if(deepObject instanceof Array)
|
|
448
|
+
var newObj=[];
|
|
449
|
+
else if(deepObject instanceof String)
|
|
450
|
+
return new String(deepObject);
|
|
451
|
+
else if(deepObject instanceof Number)
|
|
452
|
+
return new Number(deepObject);
|
|
453
|
+
else if(deepObject instanceof Date)
|
|
454
|
+
return new Date(deepObject);
|
|
455
|
+
else if(typeof deepObject == "object")
|
|
456
|
+
var newObj={};
|
|
457
|
+
else return deepObject;
|
|
458
|
+
for (const i in deepObject)
|
|
459
|
+
newObj[i]=deepClone(deepObject[i]);
|
|
460
|
+
return newObj;
|
|
361
461
|
}
|
|
462
|
+
|
|
463
|
+
defineMethod(Array,"deepClone",function(){
|
|
464
|
+
const clone=[]
|
|
465
|
+
for (let i in this)
|
|
466
|
+
clone[i]=this[i].deepClone()
|
|
467
|
+
return clone
|
|
468
|
+
})
|
|
469
|
+
defineMethod(Object,"deepClone",function(){
|
|
470
|
+
// const clone={}
|
|
471
|
+
// for (let i in this)
|
|
472
|
+
// clone[i]=this[i].deepClone()
|
|
473
|
+
// return clone
|
|
474
|
+
return deepClone(this)
|
|
475
|
+
})
|
|
476
|
+
const rangeLimit=(value,min=value,max=value)=>value<min?min:value>max?max:value
|
|
477
|
+
defineMethod(Number, "rangeLimit",function(min,max) {return (min!=null && this<min) ? min : ((max!=null && this>max) ? max : this)})
|
|
478
|
+
defineMethod(BigInt, "rangeLimit",function(min,max) {return (min!=null && this<min) ? min : ((max!=null && this>max) ? max : this)})
|
|
479
|
+
defineMethod(Date, "rangeLimit",function(min,max) {return (min!=null && this<min) ? min : ((max!=null && this>max) ? max : this)})
|
|
480
|
+
defineMethod(String, "rangeLimit",function(min,max) {return (min!=null && this<min) ? min : ((max!=null && this>max) ? max : this)})
|
|
481
|
+
defineMethod(String,"deunderscore",function(){return this.replace(/_/g," ")})
|
|
482
|
+
defineMethod(String,"deunderscoreCapitilize",function(){return this.replace(/_/g," ").toTitle()})
|
|
483
|
+
defineMethod(String,"dropSquareBracketPrefix",function(bracket="[",endBracket="]"){return (this.substr(0,1)==bracket)? this.split(endBracket+" ")[1] : this})
|
|
484
|
+
module.exports={
|
|
485
|
+
coalesce:coalesce,
|
|
486
|
+
colours:colours,
|
|
487
|
+
colourSmallList:colourSmallList,
|
|
488
|
+
deepClone,deepClone,
|
|
489
|
+
getWord,getWord,
|
|
490
|
+
nullif:nullif,
|
|
491
|
+
rangeLimit,rangeLimit,
|
|
492
|
+
toDateType,
|
|
493
|
+
toDateTypeZulu,
|
|
494
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
const timePeriod={second:1000}
|
|
2
|
+
timePeriod.minute=timePeriod.second*60
|
|
3
|
+
timePeriod.hour=timePeriod.minute*60
|
|
4
|
+
timePeriod.day=timePeriod.hour*24
|
|
5
|
+
timePeriod.week=timePeriod.day*7
|
|
6
|
+
timePeriod.fortnight=timePeriod.week*2
|
|
7
|
+
|
|
8
|
+
const isPeriod={
|
|
9
|
+
second:t=>t%timePeriod.second,
|
|
10
|
+
minute:t=>t%timePeriod.minute
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
const timeDimension=(period=timePeriod.second,from=0,to=60,call)=>{
|
|
16
|
+
const fromDate=new Date(from).getMilliseconds%period
|
|
17
|
+
const toDate=new Date(to).getMilliseconds%increment
|
|
18
|
+
const periods=Object.keys(callFunctions)
|
|
19
|
+
for(let i=fromDate;i<toDate;i+increment){
|
|
20
|
+
call(i)
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const repeat=(r,call)=>{for(let i=0;i<r; i++) call(i)}
|
|
25
|
+
const secondsInMinute=call=>repeat(60,call)
|
|
26
|
+
const minutesInHour=repeat(60,call)
|
|
27
|
+
const hoursInDay=repeat(24,call)
|
|
28
|
+
const daysInWeek=repeat(7,call)
|
|
29
|
+
|
|
30
|
+
module.exports={
|
|
31
|
+
repeat:repeat,
|
|
32
|
+
secondsInMinute:secondsInMinute,
|
|
33
|
+
minutesInHour:minutesInHour,
|
|
34
|
+
hoursInDay:hoursInDay,
|
|
35
|
+
daysInWeek:daysInWeek
|
|
36
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
|
|
2
|
+
const setGetFunction=(RED,node,propertyName)=>node["get"+propertyName[0].toUpperCase() + propertyName.slice(1)]=getFunction(RED,node,propertyName)
|
|
3
|
+
|
|
4
|
+
const getFunction=(RED,node,propertyName)=>{
|
|
5
|
+
try{
|
|
6
|
+
const property=node[propertyName];
|
|
7
|
+
if(property==null) throw Error("no value for "+propertyName);
|
|
8
|
+
const propertyType=propertyName+"Type";
|
|
9
|
+
if(! (propertyType in node)) return eval("()=>node."+property)
|
|
10
|
+
const type=node[propertyType]
|
|
11
|
+
switch (type){
|
|
12
|
+
case "bin": // a Node.js Buffer
|
|
13
|
+
case "re": // a Regular Expression
|
|
14
|
+
case "jsonata": // a Jsonata Expression
|
|
15
|
+
case "cred": // a secure credential
|
|
16
|
+
case "bool":
|
|
17
|
+
case "json":
|
|
18
|
+
case "num":
|
|
19
|
+
case "str":
|
|
20
|
+
case "date": // the current timestamp
|
|
21
|
+
case "env":
|
|
22
|
+
case "global":
|
|
23
|
+
const value=RED.util.evaluateNodeProperty(property, type, node)
|
|
24
|
+
return eval("()=>value")
|
|
25
|
+
case "flow":
|
|
26
|
+
const flow = node.context().flow;
|
|
27
|
+
if(flow) throw Error("context store may be memoryonly so flow doesn't work")
|
|
28
|
+
return eval("()=>flow.get("+property+")");
|
|
29
|
+
case "msg":
|
|
30
|
+
return eval("(msg)=>msg."+property);
|
|
31
|
+
case "node":
|
|
32
|
+
const nodeContext = node.context();
|
|
33
|
+
return eval("()=>nodeContext.get("+property+")");
|
|
34
|
+
default:
|
|
35
|
+
throw Error("unknown type "+node[propertyType])
|
|
36
|
+
}
|
|
37
|
+
} catch(ex) {
|
|
38
|
+
throw Error(propertyName+" "+ex.message);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
}
|
|
42
|
+
const setFunction=(RED,node,name)=>{
|
|
43
|
+
if(!name)
|
|
44
|
+
if(!node.hasOwnProperty(name)) throw Error("name is null")
|
|
45
|
+
if(!node.hasOwnProperty(name+"-type")) {
|
|
46
|
+
node.set[name]=eval("data=>msg.payload['"+name+"']=data)")
|
|
47
|
+
return
|
|
48
|
+
}
|
|
49
|
+
const type=node[name+"t-type"]
|
|
50
|
+
switch(type){
|
|
51
|
+
case "node":
|
|
52
|
+
node.set[name]=eval("data=>node.context().set("+node[name]+",data)")
|
|
53
|
+
break
|
|
54
|
+
case "flow":
|
|
55
|
+
const flow=node.context().flow
|
|
56
|
+
if(flow) throw Error("context store may be memory only so flow doesn't work")
|
|
57
|
+
node.set[name]=eval("data=>flow.set("+node[name]+",data)")
|
|
58
|
+
break
|
|
59
|
+
case "global":
|
|
60
|
+
node.set[name]=eval("data=>nodeContext.global.set("+node[name]+",data)")
|
|
61
|
+
break
|
|
62
|
+
case "msg":
|
|
63
|
+
node.set[name]=eval("(data,msg)=>{msg."+node[name]+"=data;}")
|
|
64
|
+
break
|
|
65
|
+
default:
|
|
66
|
+
throw Error("setData unknown type "+type)
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const getValue=(RED,node,propertyName,defaultValue)=>propertyName in node?getFunction(RED,node,propertyName)():defaultValue
|
|
71
|
+
|
|
72
|
+
module.exports={
|
|
73
|
+
getFunction:getFunction,
|
|
74
|
+
setFunction:setFunction,
|
|
75
|
+
setGetFunction:setGetFunction,
|
|
76
|
+
getValue:getValue
|
|
77
|
+
}
|
package/matrix/matrixNode.html
CHANGED
|
@@ -146,7 +146,8 @@
|
|
|
146
146
|
|
|
147
147
|
defineProperty({name:"dataType",label:"number Type" ,icon:"tag"},[
|
|
148
148
|
{ value: "Float32Array", label: "float32 -3.4e38 to 3.4e38" },
|
|
149
|
-
{ value: "Float64Array", label: "double/float64 -1.8e308 to 1.8e308" },
|
|
149
|
+
{ value: "Float64Array", label: "double/float64 -1.8e308 to 1.8e308" },
|
|
150
|
+
{ value: "Int8Array", label: "byte -128 to 122" },
|
|
150
151
|
{ value: "Uint8Array", label: "octet 0 to 255" },
|
|
151
152
|
{ value: "Uint8ClampedArray", label: "octet clamped 0 to 255" },
|
|
152
153
|
{ value: "Int16Array", label: "short -32768 to 32767" },
|
package/package.json
CHANGED
|
@@ -1,33 +1,34 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-red-contrib-prib-functions",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.23.3",
|
|
4
4
|
"description": "Node-RED added node functions.",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"avsc": ">=5.7.7",
|
|
7
7
|
"compressiontool": "*",
|
|
8
|
-
"fast-xml-parser": "^
|
|
9
|
-
"node": ">=
|
|
8
|
+
"fast-xml-parser": "^5.2.1",
|
|
9
|
+
"node": ">=22.15.0",
|
|
10
10
|
"node-red-contrib-logger": "latest",
|
|
11
11
|
"node-red-contrib-noderedbase": ">=0.0.16",
|
|
12
12
|
"node-red-contrib-prib-functions": "file:",
|
|
13
|
-
"npm": "^
|
|
13
|
+
"npm": "^11.3.0",
|
|
14
14
|
"xlsx": "*"
|
|
15
15
|
},
|
|
16
16
|
"devDependencies": {
|
|
17
|
-
"@node-red/runtime": ">=
|
|
18
|
-
"axios": ">=
|
|
19
|
-
"bcrypt": "^5.
|
|
20
|
-
"bl": "^
|
|
21
|
-
"mocha": "^
|
|
22
|
-
"node-red": "
|
|
23
|
-
"node-red-node-test-helper": "
|
|
17
|
+
"@node-red/runtime": ">=4.0.9",
|
|
18
|
+
"axios": ">=1.9.0",
|
|
19
|
+
"bcrypt": "^5.1.1",
|
|
20
|
+
"bl": "^6.1.0",
|
|
21
|
+
"mocha": "^11.2.2",
|
|
22
|
+
"node-red": ">=4.0.9",
|
|
23
|
+
"node-red-node-test-helper": ">=0.3.4"
|
|
24
24
|
},
|
|
25
25
|
"scripts": {
|
|
26
26
|
"test": "mocha \"test/dataAnalysisE*.js\"",
|
|
27
27
|
"test2": "mocha \"test/transformNum*.js\"",
|
|
28
28
|
"test00": "mocha \"test/00*.js\"",
|
|
29
|
-
"
|
|
30
|
-
"startNodeRed": "node-red --userDir ./test/data --setting ./test/data/settings.js ./test/data/flow.json --title '***test nodered***'"
|
|
29
|
+
"test02": "mocha \"test/02*.js\"",
|
|
30
|
+
"startNodeRed": "node-red --userDir ./test/data --setting ./test/data/settings.js ./test/data/flow.json --title '***test nodered***'",
|
|
31
|
+
"sharesNodeRed": "node-red --userDir ./test/data/shares --setting ./test/data/shares/settings.js ./test/data/shares/flow.json --title '***shares nodered***'"
|
|
31
32
|
},
|
|
32
33
|
"repository": {
|
|
33
34
|
"type": "git",
|
|
@@ -117,6 +118,7 @@
|
|
|
117
118
|
"system",
|
|
118
119
|
"testing",
|
|
119
120
|
"test",
|
|
121
|
+
"tensor",
|
|
120
122
|
"translate",
|
|
121
123
|
"transform",
|
|
122
124
|
"transpose",
|