node-red-contrib-prib-functions 0.21.0 → 0.23.2
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 +91 -35
- package/dataAnalysis/arrayAverage.js +13 -0
- package/dataAnalysis/arraySum.js +14 -0
- package/dataAnalysis/arrayTypesForEach.js +5 -0
- package/dataAnalysis/autocorrelation.js +29 -0
- package/dataAnalysis/dataAnalysis.html +3 -1
- package/dataAnalysis/dataAnalysis.js +3 -0
- package/documentation/matrix.jpg +0 -0
- package/lib/common.js +128 -0
- package/lib/objectExtensions.js +190 -80
- package/lib/typedInput.js +77 -0
- package/matrix/matrixNode.html +2 -1
- package/package.json +14 -11
- package/test/00-objectExtensions.js +192 -1
- 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 +3306 -427
- package/test/data/flow.json +3292 -411
- package/test/data/package-lock.json +4 -4
- package/test/dataAnalysisExtensions.js +20 -0
- package/testing/test.html +4 -0
- package/testing/test.js +59 -26
- package/transform/transform.html +163 -19
- package/transform/transform.js +106 -55
- 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
|
+
})
|
|
67
41
|
|
|
68
|
-
|
|
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/>")})
|
|
50
|
+
|
|
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,131 @@ 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;
|
|
361
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
|
+
|
|
444
|
+
//defineMethod(TypedArray,"deepClone",function(){ return new type(this)})
|
|
445
|
+
defineMethod(Array,"deepClone",function(){
|
|
446
|
+
const clone=[]
|
|
447
|
+
for (let i in this)
|
|
448
|
+
clone[i]=this[i].deepClone()
|
|
449
|
+
return clone
|
|
450
|
+
})
|
|
451
|
+
defineMethod(Object,"deepClone",function(){
|
|
452
|
+
const clone={}
|
|
453
|
+
for (let i in this)
|
|
454
|
+
clone[i]=this[i].deepClone()
|
|
455
|
+
return clone
|
|
456
|
+
})
|
|
457
|
+
defineMethod(Number, "rangeLimit",function(min,max) {return (min!=null && this<min) ? min : ((max!=null && this>max) ? max : this)})
|
|
458
|
+
defineMethod(BigInt, "rangeLimit",function(min,max) {return (min!=null && this<min) ? min : ((max!=null && this>max) ? max : this)})
|
|
459
|
+
defineMethod(Date, "rangeLimit",function(min,max) {return (min!=null && this<min) ? min : ((max!=null && this>max) ? max : this)})
|
|
460
|
+
defineMethod(String, "rangeLimit",function(min,max) {return (min!=null && this<min) ? min : ((max!=null && this>max) ? max : this)})
|
|
461
|
+
defineMethod(String,"deunderscore",function(){return this.replace(/_/g," ")})
|
|
462
|
+
defineMethod(String,"deunderscoreCapitilize",function(){return this.replace(/_/g," ").toTitle()})
|
|
463
|
+
defineMethod(String,"dropSquareBracketPrefix",function(bracket="[",endBracket="]"){return (this.substr(0,1)==bracket)? this.split(endBracket+" ")[1] : this})
|
|
464
|
+
module.exports={
|
|
465
|
+
coalesce:coalesce,
|
|
466
|
+
colours:colours,
|
|
467
|
+
colourSmallList:colourSmallList,
|
|
468
|
+
nullif:nullif,
|
|
469
|
+
toDateType,
|
|
470
|
+
toDateTypeZulu,
|
|
471
|
+
}
|
|
@@ -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,26 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-red-contrib-prib-functions",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.23.2",
|
|
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\"",
|
|
@@ -38,6 +38,8 @@
|
|
|
38
38
|
"adjoint",
|
|
39
39
|
"append",
|
|
40
40
|
"analysis",
|
|
41
|
+
"autocorrelation",
|
|
42
|
+
"autocovariance",
|
|
41
43
|
"average",
|
|
42
44
|
"avg",
|
|
43
45
|
"AVRO",
|
|
@@ -115,6 +117,7 @@
|
|
|
115
117
|
"system",
|
|
116
118
|
"testing",
|
|
117
119
|
"test",
|
|
120
|
+
"tensor",
|
|
118
121
|
"translate",
|
|
119
122
|
"transform",
|
|
120
123
|
"transpose",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const assert=require('assert');
|
|
2
2
|
const should=require("should");
|
|
3
|
-
require("../lib/objectExtensions");
|
|
3
|
+
const {coalesce,nullif}=require("../lib/objectExtensions");
|
|
4
4
|
|
|
5
5
|
describe('/lib/objectExtensions array ', function() {
|
|
6
6
|
it("array find sorted empty set", function(done) {
|
|
@@ -92,3 +92,194 @@ describe('/lib/objectExtensions csvLine', function() {
|
|
|
92
92
|
done()
|
|
93
93
|
})
|
|
94
94
|
})
|
|
95
|
+
describe('/lib/objectExtensions number', function() {
|
|
96
|
+
it("isBetween", function(done) {
|
|
97
|
+
assert.deepStrictEqual(Number(1).isBetween(0,1),true)
|
|
98
|
+
assert.deepStrictEqual(Number(0).isBetween(0,1),true)
|
|
99
|
+
assert.deepStrictEqual(Number(-1).isBetween(0,1),false)
|
|
100
|
+
assert.deepStrictEqual(Number(2).isBetween(0,1),false)
|
|
101
|
+
done()
|
|
102
|
+
})
|
|
103
|
+
it("toSimpleArray", function(done) {
|
|
104
|
+
assert.deepStrictEqual({}.toSimpleArray(),[])
|
|
105
|
+
assert.deepStrictEqual({a:1,b:"2"}.toSimpleArray(),[["a",1,"number"],["b","2","string"]])
|
|
106
|
+
done()
|
|
107
|
+
})
|
|
108
|
+
it("toSimpleArrayIgnoreNulls", function(done) {
|
|
109
|
+
assert.deepStrictEqual({}.toSimpleArrayIgnoreNulls(),[])
|
|
110
|
+
assert.deepStrictEqual({a:1,b:"2"}.toSimpleArrayIgnoreNulls(),[["a",1,"number"],["b","2","string"]])
|
|
111
|
+
assert.deepStrictEqual({a:1,b:"2",c:null}.toSimpleArrayIgnoreNulls(),[["a",1,"number"],["b","2","string"]])
|
|
112
|
+
done()
|
|
113
|
+
})
|
|
114
|
+
it("in", function(done) {
|
|
115
|
+
assert.deepStrictEqual("abc".in(),false)
|
|
116
|
+
assert.deepStrictEqual("abc".in("abc"),true)
|
|
117
|
+
assert.deepStrictEqual("abc".in("abc","c"),true)
|
|
118
|
+
assert.deepStrictEqual("abc".in("a","abc","c"),true)
|
|
119
|
+
assert.deepStrictEqual("abc".in("a","no","c"),false)
|
|
120
|
+
done()
|
|
121
|
+
})
|
|
122
|
+
it("startsWithList", function(done) {
|
|
123
|
+
assert.deepStrictEqual("abc".startsWithList("a"),true)
|
|
124
|
+
assert.deepStrictEqual("Abc".startsWithList("a"),false)
|
|
125
|
+
assert.deepStrictEqual("abc".startsWithList("b","ab"),true)
|
|
126
|
+
assert.deepStrictEqual("abc".startsWithList("c"),false)
|
|
127
|
+
done()
|
|
128
|
+
})
|
|
129
|
+
it("startsWithListAnyCase", function(done) {
|
|
130
|
+
assert.deepStrictEqual("abc".startsWithListAnyCase("a"),true)
|
|
131
|
+
assert.deepStrictEqual("Abc".startsWithListAnyCase("a"),true)
|
|
132
|
+
assert.deepStrictEqual("aBc".startsWithListAnyCase("b","ab"),true)
|
|
133
|
+
assert.deepStrictEqual("abc".startsWithListAnyCase("c"),false)
|
|
134
|
+
done()
|
|
135
|
+
})
|
|
136
|
+
it("toAbbreviated", function(done) {
|
|
137
|
+
const test=(n,a)=>{
|
|
138
|
+
const t=n.toAbbreviated()
|
|
139
|
+
console.log(n+" => "+t+" s/be "+a)
|
|
140
|
+
assert.deepStrictEqual(t,a)
|
|
141
|
+
}
|
|
142
|
+
test(0,"0.00")
|
|
143
|
+
test(1,"1.00")
|
|
144
|
+
test(-1,"-1.00")
|
|
145
|
+
test(0.1,"0.10")
|
|
146
|
+
test(1.1234567,"1.12")
|
|
147
|
+
test(1001.0,"1.00K")
|
|
148
|
+
test(-1001.0,"-1.00K")
|
|
149
|
+
test(1011.0,"1.01K")
|
|
150
|
+
test(-1011.0,"-1.01K")
|
|
151
|
+
test(2011000.1,"2.01M")
|
|
152
|
+
test(2011002003,"2.01G")
|
|
153
|
+
test(2011002003004,"2.01T")
|
|
154
|
+
test(2011002003004005,"2.01P")
|
|
155
|
+
done()
|
|
156
|
+
})
|
|
157
|
+
it("xmlStringEncode", function(done) {
|
|
158
|
+
assert.deepStrictEqual("a&c".xmlStringEncode("a"),"a&c")
|
|
159
|
+
assert.deepStrictEqual("a\"c".xmlStringEncode("a"),"a"c")
|
|
160
|
+
assert.deepStrictEqual("a<>c".xmlStringEncode("a"),"a<>c")
|
|
161
|
+
done()
|
|
162
|
+
})
|
|
163
|
+
it("getWord", function(done) {
|
|
164
|
+
assert.deepStrictEqual("".getWord(1),"")
|
|
165
|
+
assert.deepStrictEqual("one two three".getWord(1),"one")
|
|
166
|
+
assert.deepStrictEqual("one two three".getWord(2),"two")
|
|
167
|
+
assert.deepStrictEqual("one two three".getWord(3),"three")
|
|
168
|
+
assert.deepStrictEqual("one two three".getWord(4),"")
|
|
169
|
+
done()
|
|
170
|
+
})
|
|
171
|
+
it("coalesce", function(done) {
|
|
172
|
+
const anull=null,notanull="notnull"
|
|
173
|
+
assert.deepStrictEqual(coalesce(anull,"test"),"test")
|
|
174
|
+
assert.deepStrictEqual(coalesce(notanull,"test"),"notnull")
|
|
175
|
+
done()
|
|
176
|
+
})
|
|
177
|
+
it("nullif", function(done) {
|
|
178
|
+
const anull="test",notanull="notnull"
|
|
179
|
+
assert.deepStrictEqual(nullif(anull,"test"),null)
|
|
180
|
+
assert.deepStrictEqual(nullif(notanull,"test"),"notnull")
|
|
181
|
+
done()
|
|
182
|
+
})
|
|
183
|
+
it("deepClone", function(done) {
|
|
184
|
+
const n=new Number(1)
|
|
185
|
+
const s=new String("astring")
|
|
186
|
+
const a=[s,n,[,s,n]]
|
|
187
|
+
assert.deepStrictEqual({}.deepClone(),{})
|
|
188
|
+
assert.deepStrictEqual([].deepClone(),[])
|
|
189
|
+
assert.deepStrictEqual(n.deepClone(),n)
|
|
190
|
+
assert.deepStrictEqual(s.deepClone(),s)
|
|
191
|
+
assert.deepStrictEqual(a.deepClone(),a)
|
|
192
|
+
done()
|
|
193
|
+
})
|
|
194
|
+
it("rangeLimit", function(done) {
|
|
195
|
+
const test=(type,min,max,value,result)=>{
|
|
196
|
+
const typedValue=new type(value)
|
|
197
|
+
assert.deepStrictEqual(typedValue.rangeLimit(new type(min),new type(max)),new type(result))
|
|
198
|
+
}
|
|
199
|
+
test(Number,2,4,1,2)
|
|
200
|
+
test(Number,2,4,2,2)
|
|
201
|
+
test(Number,2,4,3,3)
|
|
202
|
+
test(Number,2,4,4,4)
|
|
203
|
+
test(Number,2,4,5,4)
|
|
204
|
+
|
|
205
|
+
const test2=(type,min,max,value,result)=>{
|
|
206
|
+
const typedValue=type(value)
|
|
207
|
+
const typedResult=type(result)
|
|
208
|
+
const typedMin=type(min)
|
|
209
|
+
const typeMax=type(max)
|
|
210
|
+
assert.equal(typedValue.rangeLimit(typedMin,typeMax),typedResult)
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
test2(BigInt,2,4,1,2)
|
|
214
|
+
test2(BigInt,2,4,2,2)
|
|
215
|
+
test2(BigInt,2,4,3,3)
|
|
216
|
+
test2(BigInt,2,4,4,4)
|
|
217
|
+
|
|
218
|
+
test2(Date,"2/2/2022","4/2/2022","1/2/2022","2/2/2022")
|
|
219
|
+
test2(Date,"2/2/2022","4/2/2022","2/2/2022","2/2/2022")
|
|
220
|
+
test2(Date,"2/2/2022","4/2/2022","3/2/2022","3/2/2022")
|
|
221
|
+
test2(Date,"2/2/2022","4/2/2022","4/2/2022","4/2/2022")
|
|
222
|
+
test2(Date,"2/2/2022","4/2/2022","5/2/2022","4/2/2022")
|
|
223
|
+
|
|
224
|
+
test2(String,"bb","bcd","aa","bb")
|
|
225
|
+
test2(String,"bb","bcd","bb","bb")
|
|
226
|
+
test2(String,"bb","bcd","bc","bc")
|
|
227
|
+
test2(String,"bb","bcd","bcd","bcd")
|
|
228
|
+
test2(String,"bb","bcd","bce","bcd")
|
|
229
|
+
done()
|
|
230
|
+
})
|
|
231
|
+
it("capitalize", function(done) {
|
|
232
|
+
assert.equal("".capitalize(),"")
|
|
233
|
+
assert.equal("abc".capitalize(),"Abc")
|
|
234
|
+
assert.equal("aBcd".capitalize(),"ABcd")
|
|
235
|
+
done()
|
|
236
|
+
})
|
|
237
|
+
it("toTitle", function(done) {
|
|
238
|
+
assert.equal("".toTitle(),"")
|
|
239
|
+
assert.equal("abc".toTitle(),"Abc")
|
|
240
|
+
assert.equal("aBcd".toTitle(),"ABcd")
|
|
241
|
+
assert.equal("aBcd def".toTitle(),"ABcd Def")
|
|
242
|
+
done()
|
|
243
|
+
})
|
|
244
|
+
it("toTitleGrammatical", function(done) {
|
|
245
|
+
assert.equal("to be or not to be".toTitleGrammatical(),"To Be or Not to Be")
|
|
246
|
+
assert.equal("a small dog".toTitleGrammatical(),"A Small Dog")
|
|
247
|
+
done()
|
|
248
|
+
})
|
|
249
|
+
it("deunderscore", function(done) {
|
|
250
|
+
assert.equal("abc_def_".deunderscore(),"abc def ")
|
|
251
|
+
done()
|
|
252
|
+
})
|
|
253
|
+
it("deunderscoreCapitilize", function(done) {
|
|
254
|
+
assert.equal(" abc_def_".deunderscoreCapitilize()," Abc Def ")
|
|
255
|
+
done()
|
|
256
|
+
})
|
|
257
|
+
it("dropSquareBracketPrefix", function(done) {
|
|
258
|
+
assert.equal("[abc] def".dropSquareBracketPrefix(),"def")
|
|
259
|
+
done()
|
|
260
|
+
})
|
|
261
|
+
})
|
|
262
|
+
describe('/lib/objectExtensions string', function() {
|
|
263
|
+
it("isBetween", function(done) {
|
|
264
|
+
assert.deepStrictEqual("a".isBetween("b","de"),false)
|
|
265
|
+
assert.deepStrictEqual("f".isBetween("b","de"),false)
|
|
266
|
+
assert.deepStrictEqual("b".isBetween("b","de"),true)
|
|
267
|
+
assert.deepStrictEqual("c".isBetween("b","de"),true)
|
|
268
|
+
assert.deepStrictEqual("d".isBetween("b","de"),true)
|
|
269
|
+
assert.deepStrictEqual("de".isBetween("b","de"),true)
|
|
270
|
+
assert.deepStrictEqual("df".isBetween("b","de"),false)
|
|
271
|
+
done()
|
|
272
|
+
})
|
|
273
|
+
})
|
|
274
|
+
describe('/lib/objectExtensions Date', function() {
|
|
275
|
+
it("isBetween", function(done) {
|
|
276
|
+
const aDate=new Date("2025/05/02")
|
|
277
|
+
assert.deepStrictEqual(aDate.isBetween("2025/05/01","2025/05/03"),true)
|
|
278
|
+
assert.deepStrictEqual(aDate.isBetween(new Date("2025/05/01"),new Date("2025/05/03")),true)
|
|
279
|
+
assert.deepStrictEqual(aDate.isBetween("2025/05/02","2025/05/03"),true)
|
|
280
|
+
assert.deepStrictEqual(aDate.isBetween("2025/05/01","2025/05/02"),true)
|
|
281
|
+
assert.deepStrictEqual(aDate.isBetween("2025/04/01","2025/05/01"),false)
|
|
282
|
+
assert.deepStrictEqual(aDate.isBetween("2025/05/03","2025/06/01"),false)
|
|
283
|
+
done()
|
|
284
|
+
})
|
|
285
|
+
})
|