FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
cloudstack/ui/src/utils/sort.js at main · calvix/cloudstack · GitHub
calvix
/
cloudstack
Public
forked from
apache/cloudstack
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
4
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
cloudstack
/
ui
/
src
/
utils
/
sort.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
115 lines (100 loc) · 4.41 KB
Breadcrumbs
cloudstack
/
ui
/
src
/
utils
/
sort.js
Copy path
File metadata and controls
115 lines (100 loc) · 4.41 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
function
filterNumber
(
value
)
{
if
(
/
^
[
-
+
]
?
\d
*
\.
?
\d
*
$
/
.
test
(
value
)
)
{
return
Number
(
value
)
}
return
NaN
}
function
stringComparator
(
a
,
b
)
{
return
a
.
toString
(
)
.
localeCompare
(
b
.
toString
(
)
,
undefined
,
{
numeric
:
true
}
)
}
function
numericComparator
(
a
,
b
)
{
return
filterNumber
(
a
)
<
filterNumber
(
b
)
?
1
:
-
1
}
function
metricComparator
(
ma
,
mb
)
{
var
a
=
(
''
+
ma
)
.
replace
(
/
(
(
%
)
|
(
G
h
z
)
|
(
M
h
z
)
|
(
M
i
B
)
|
(
G
i
B
)
|
(
G
B
)
)
.
*
$
/
g
,
''
)
var
b
=
(
''
+
mb
)
.
replace
(
/
(
(
%
)
|
(
G
h
z
)
|
(
M
h
z
)
|
(
M
i
B
)
|
(
G
i
B
)
|
(
G
B
)
)
.
*
$
/
g
,
''
)
return
parseFloat
(
a
)
<
parseFloat
(
b
)
?
1
:
-
1
}
function
ipV4AddressCIDRComparator
(
a
,
b
)
{
a
=
a
.
split
(
/
[
.
/
]
/
gm
)
b
=
b
.
split
(
/
[
.
/
]
/
gm
)
for
(
var
i
=
0
;
i
<
a
.
length
;
i
++
)
{
if
(
(
a
[
i
]
=
parseInt
(
a
[
i
]
)
)
<
(
b
[
i
]
=
parseInt
(
b
[
i
]
)
)
)
{
return
-
1
}
else
if
(
a
[
i
]
>
b
[
i
]
)
{
return
1
}
}
return
0
}
function
ipV6AddressCIDRComparator
(
a
,
b
)
{
a
=
a
.
split
(
/
[:
/
]
/
gm
)
b
=
b
.
split
(
/
[:
/
]
/
gm
)
for
(
var
i
=
0
;
i
<
a
.
length
;
i
++
)
{
if
(
(
a
[
i
]
=
parseInt
(
'0x'
+
a
[
i
]
,
16
)
)
<
(
b
[
i
]
=
parseInt
(
'0x'
+
b
[
i
]
,
16
)
)
)
{
return
-
1
}
else
if
(
a
[
i
]
>
b
[
i
]
)
{
return
1
}
}
return
0
}
function
isIpV4Address
(
obj
)
{
return
!
Array
.
isArray
(
obj
)
&&
(
/
^
(
(
[
0
-
9
]
|
[
1
-
9
]
[
0
-
9
]
|
1
[
0
-
9
]
{
2
}
|
2
[
0
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
}
)
|
(
(
:
[
0
-
9
A
-
F
a
-
f
]
{
1
,
4
}
)
{
0
,
4
}
:
(
(
2
5
[
0
-
5
]
|
2
[
0
-
4
]
d
|
1
d
d
|
[
1
-
9
]
?
d
)
(
.
(
2
5
[
0
-
5
]
|
2
[
0
-
4
]
d
|
1
d
d
|
[
1
-
9
]
?
d
)
)
{
3
}
)
)
|
:
)
)
|
(
:
(
(
(
:
[
0
-
9
A
-
F
a
-
f
]
{
1
,
4
}
)
{
1
,
7
}
)
|
(
(
:
[
0
-
9
A
-
F
a
-
f
]
{
1
,
4
}
)
{
0
,
5
}
:
(
(
2
5
[
0
-
5
]
|
2
[
0
-
4
]
d
|
1
d
d
|
[
1
-
9
]
?
d
)
(
.
(
2
5
[
0
-
5
]
|
2
[
0
-
4
]
d
|
1
d
d
|
[
1
-
9
]
?
d
)
)
{3}))|:)))(%.+)?s*(\/([0-9]|[1-9][0-9]|1[0-1][0-9]|12[0-8]))?$/gm
).test(obj)
}
function
isNumeric
(
obj
)
{
return
!
Array
.
isArray
(
obj
)
&&
!
isNaN
(
filterNumber
(
obj
)
)
}
function
isMetric
(
value
)
{
return
/
^
[
0
-
9
\\
.
]
*
(
(
%
)
|
(
G
h
z
)
|
(
M
h
z
)
|
(
M
i
B
)
|
(
G
i
B
)
|
(
G
B
)
)
/
.
test
(
value
)
}
/**
* Compare elements, attempting to determine type of element to get the best comparison
*
*/
export
function
genericCompare
(
a
,
b
)
{
// strict function for filtering numbers (e.g. "2.3", "-2" but not "8 CPUs")
var
comparator
=
stringComparator
if
(
a
===
b
)
{
// Short circuit out to avoid unnecessary effort
return
0
}
if
(
(
isIpV4CIDRAddress
(
a
)
||
isIpV4Address
(
a
)
)
&&
(
isIpV4CIDRAddress
(
b
)
||
isIpV4Address
(
b
)
)
)
{
comparator
=
ipV4AddressCIDRComparator
}
if
(
(
isIpV6CIDRAddress
(
a
)
||
isIpV6Address
(
a
)
)
&&
(
isIpV6CIDRAddress
(
b
)
||
isIpV6Address
(
b
)
)
)
{
comparator
=
ipV6AddressCIDRComparator
}
if
(
isNumeric
(
a
)
&&
isNumeric
(
b
)
)
{
comparator
=
numericComparator
}
if
(
isMetric
(
a
)
&&
isMetric
(
b
)
)
{
comparator
=
metricComparator
}
return
comparator
(
a
,
b
)
}
Back
|
FazBrowse Home
|
New Git URL