@kizmann/pico-js 0.5.1 → 0.5.3
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/pico-js.js +2 -370
- package/dist/pico-js.js.map +1 -1
- package/package.json +1 -1
- package/src/utility/any.js +43 -1
- package/webservy.json +4 -2
package/package.json
CHANGED
package/src/utility/any.js
CHANGED
@@ -101,14 +101,56 @@ export class Any
|
|
101
101
|
return this.isEmpty(val) ? empty : this.string(val);
|
102
102
|
}
|
103
103
|
|
104
|
+
static number(val, fallback = NaN)
|
105
|
+
{
|
106
|
+
let res = ! val || typeof val.toString === 'undefined' ?
|
107
|
+
String(val) : val.toString();
|
108
|
+
|
109
|
+
if ( ! Any.isString(res) ) {
|
110
|
+
return fallback;
|
111
|
+
}
|
112
|
+
|
113
|
+
if ( res.match(/^[0-9]+$/) ) {
|
114
|
+
return this.integer(val);
|
115
|
+
}
|
116
|
+
|
117
|
+
if ( res.match(/^[0-9.,]+$/) ) {
|
118
|
+
return this.float(val);
|
119
|
+
}
|
120
|
+
|
121
|
+
if ( ! this.isNumber(res) || Number.isNaN(res) ) {
|
122
|
+
return fallback;
|
123
|
+
}
|
124
|
+
|
125
|
+
return res;
|
126
|
+
}
|
127
|
+
|
104
128
|
static integer(val)
|
105
129
|
{
|
130
|
+
let res = ! val || typeof val.toString === 'undefined' ?
|
131
|
+
String(val) : val.toString();
|
132
|
+
|
133
|
+
if ( ! Any.isString(res) ) {
|
134
|
+
return NaN;
|
135
|
+
}
|
136
|
+
|
106
137
|
return parseInt(val);
|
107
138
|
}
|
108
139
|
|
109
140
|
static float(val)
|
110
141
|
{
|
111
|
-
|
142
|
+
let res = typeof val.toString === 'undefined' ?
|
143
|
+
String(val) : val.toString();
|
144
|
+
|
145
|
+
if ( ! Any.isString(res) ) {
|
146
|
+
return NaN;
|
147
|
+
}
|
148
|
+
|
149
|
+
if ( res.match(/^[0-9,]+$/) ) {
|
150
|
+
res = res.replace(/,/g, '.');
|
151
|
+
}
|
152
|
+
|
153
|
+
return parseFloat(res);
|
112
154
|
}
|
113
155
|
|
114
156
|
static bool(val)
|