hola-server 0.5.5 → 0.6.1
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/core/number.js +3 -3
- package/core/validate.js +1 -1
- package/db/entity.js +9 -0
- package/package.json +1 -1
- package/test/core/number.js +17 -0
package/core/number.js
CHANGED
|
@@ -167,12 +167,12 @@ const random_sample = (obj) => {
|
|
|
167
167
|
* @returns
|
|
168
168
|
*/
|
|
169
169
|
const extract_number = (value) => {
|
|
170
|
-
const
|
|
171
|
-
if (!
|
|
170
|
+
const numbers = value.match(/([+\-0-9\\.]+)/g);
|
|
171
|
+
if (!numbers) {
|
|
172
172
|
return 0;
|
|
173
173
|
}
|
|
174
174
|
|
|
175
|
-
const values =
|
|
175
|
+
const values = numbers.map(Number).filter(v => has_value(v));
|
|
176
176
|
return values.length == 1 ? values[0] : 0;
|
|
177
177
|
}
|
|
178
178
|
|
package/core/validate.js
CHANGED
package/db/entity.js
CHANGED
|
@@ -138,6 +138,15 @@ class Entity {
|
|
|
138
138
|
}
|
|
139
139
|
}
|
|
140
140
|
|
|
141
|
+
if (param_obj["_id"] && param_obj["_id"].trim().length > 0) {
|
|
142
|
+
const ids = param_obj["_id"].split(",");
|
|
143
|
+
if (ids.length == 1) {
|
|
144
|
+
and_array.push(oid_query(ids[0]));
|
|
145
|
+
} else if (ids.length > 1) {
|
|
146
|
+
and_array.push(oid_queries(ids));
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
141
150
|
if (and_array.length > 0) {
|
|
142
151
|
query["$and"] = and_array;
|
|
143
152
|
|
package/package.json
CHANGED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const { strictEqual } = require('assert');
|
|
2
|
+
const { extract_number } = require('../../core/number');
|
|
3
|
+
|
|
4
|
+
describe('number', function () {
|
|
5
|
+
describe('test number related method', function () {
|
|
6
|
+
it('should extract number successfully', function () {
|
|
7
|
+
strictEqual(extract_number("123"), 123);
|
|
8
|
+
strictEqual(extract_number("123 abc"), 123);
|
|
9
|
+
strictEqual(extract_number("123 abc . efg"), 123);
|
|
10
|
+
strictEqual(extract_number(" abc 134.56 efg"), 134.56);
|
|
11
|
+
strictEqual(extract_number(" abc 134.56 efg . rg"), 134.56);
|
|
12
|
+
strictEqual(extract_number(" abc 134.56 efg 123 rg"), 0);
|
|
13
|
+
strictEqual(extract_number("123.67"), 123.67);
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
);
|