lemon-tls 0.1.0 → 0.2.0

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,88 +1,101 @@
1
-
2
- function concatUint8Arrays(arrays) {
3
- var totalLength = 0;
4
- for (var i = 0; i < arrays.length; i++) {
5
- totalLength += arrays[i].length;
6
- }
7
-
8
- var result = new Uint8Array(totalLength);
9
- var offset = 0;
10
-
11
- for (var i = 0; i < arrays.length; i++) {
12
- result.set(arrays[i], offset);
13
- offset += arrays[i].length;
14
- }
15
-
16
- return result;
17
- }
18
-
19
- function arraybufferEqual(buf1, buf2) {
20
- //if (buf1 === buf2) {
21
- //return true;
22
- //}
23
-
24
- if (buf1.byteLength !== buf2.byteLength) {
25
- return false;
26
- }
27
-
28
- var view1 = new DataView(buf1);
29
- var view2 = new DataView(buf2);
30
-
31
- for (let i = 0; i < buf1.byteLength; i++) {
32
- if (view1.getUint8(i) !== view2.getUint8(i)) {
33
- return false;
34
- }
35
- }
36
-
37
- return true;
38
- }
39
-
40
- function arraysEqual(a, b) {
41
- //if (a === b) return true;
42
- if (a == null || b == null) return false;
43
- if (a.length !== b.length) return false;
44
-
45
- // If you don't care about the order of the elements inside
46
- // the array, you should sort both arrays here.
47
- // Please note that calling sort on an array will modify that array.
48
- // you might want to clone your array first.
49
-
50
- for (var i = 0; i < a.length; ++i) {
51
- if(typeof a[i] !== 'undefined' && typeof b[i] !== 'undefined' && a[i]!==null && b[i]!==null && typeof a[i].byteLength == 'number' && typeof b[i].byteLength == 'number'){
52
- if(arraybufferEqual(a[i],b[i])==false){
53
- return false;
54
- }
55
- }else{
56
- if(typeof a[i]=='string' && typeof b[i]=='string'){
57
- if (a[i] !== b[i]){
58
- return false;
59
- }
60
- }else if(a[i].constructor==RegExp && typeof b[i]=='string'){
61
- if(a[i].test(b[i])==false){
62
- return false;
63
- }
64
- }else if(typeof a[i]=='string' && b[i].constructor==RegExp){
65
- if(b[i].test(a[i])==false){
66
- return false;
67
- }
68
- //}else if(a[i] instanceof Object && b[i] instanceof Object && Object.keys(a[i]).length>0 && Object.keys(b[i]).length>0){
69
- //if(_this.objectEquals(a[i],b[i])==false){
70
- // return false;
71
- //}
72
- }else{
73
- if (a[i] !== b[i]){
74
- return false;
75
- }
76
- }
77
-
78
- }
79
- }
80
- return true;
81
- };
82
-
83
-
84
- module.exports = {
85
- concatUint8Arrays,
86
- arraybufferEqual,
87
- arraysEqual
1
+
2
+ function concatUint8Arrays(arrays) {
3
+ let totalLength = 0;
4
+ for (let i = 0; i < arrays.length; i++) {
5
+ totalLength += arrays[i].length;
6
+ }
7
+
8
+ const result = new Uint8Array(totalLength);
9
+ let offset = 0;
10
+
11
+ for (let i = 0; i < arrays.length; i++) {
12
+ result.set(arrays[i], offset);
13
+ offset += arrays[i].length;
14
+ }
15
+
16
+ return result;
17
+ }
18
+
19
+ function arraybufferEqual(buf1, buf2) {
20
+ //if (buf1 === buf2) {
21
+ //return true;
22
+ //}
23
+
24
+ if (buf1.byteLength !== buf2.byteLength) {
25
+ return false;
26
+ }
27
+
28
+ const view1 = new DataView(buf1);
29
+ const view2 = new DataView(buf2);
30
+
31
+ for (let i = 0; i < buf1.byteLength; i++) {
32
+ if (view1.getUint8(i) !== view2.getUint8(i)) {
33
+ return false;
34
+ }
35
+ }
36
+
37
+ return true;
38
+ }
39
+
40
+ function arraysEqual(a, b) {
41
+ //if (a === b) return true;
42
+ if (a == null || b == null) return false;
43
+ if (a.length !== b.length) return false;
44
+
45
+ // If you don't care about the order of the elements inside
46
+ // the array, you should sort both arrays here.
47
+ // Please note that calling sort on an array will modify that array.
48
+ // you might want to clone your array first.
49
+
50
+ for (let i = 0; i < a.length; ++i) {
51
+ if(typeof a[i] !== 'undefined' && typeof b[i] !== 'undefined' && a[i]!==null && b[i]!==null && typeof a[i].byteLength == 'number' && typeof b[i].byteLength == 'number'){
52
+ if(arraybufferEqual(a[i],b[i])==false){
53
+ return false;
54
+ }
55
+ }else{
56
+ if(typeof a[i]=='string' && typeof b[i]=='string'){
57
+ if (a[i] !== b[i]){
58
+ return false;
59
+ }
60
+ }else if(a[i].constructor==RegExp && typeof b[i]=='string'){
61
+ if(a[i].test(b[i])==false){
62
+ return false;
63
+ }
64
+ }else if(typeof a[i]=='string' && b[i].constructor==RegExp){
65
+ if(b[i].test(a[i])==false){
66
+ return false;
67
+ }
68
+ //}else if(a[i] instanceof Object && b[i] instanceof Object && Object.keys(a[i]).length>0 && Object.keys(b[i]).length>0){
69
+ //if(_this.objectEquals(a[i],b[i])==false){
70
+ // return false;
71
+ //}
72
+ }else{
73
+ if (a[i] !== b[i]){
74
+ return false;
75
+ }
76
+ }
77
+
78
+ }
79
+ }
80
+ return true;
81
+ };
82
+
83
+
84
+
85
+ function uint8Equal(a, b) {
86
+ if (a === b) return true;
87
+ if (a == null || b == null) return false;
88
+ if (a.length !== b.length) return false;
89
+ for (let i = 0; i < a.length; i++) {
90
+ if (a[i] !== b[i]) return false;
91
+ }
92
+ return true;
93
+ }
94
+
95
+
96
+ export {
97
+ concatUint8Arrays,
98
+ arraybufferEqual,
99
+ arraysEqual,
100
+ uint8Equal
88
101
  };