Skip to content

Commit b13d826

Browse files
committed
fix: bump dependencies
1 parent 21a1afc commit b13d826

File tree

2 files changed

+77
-172
lines changed

2 files changed

+77
-172
lines changed

package.json

+3-9
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@
2020
"html5-framework",
2121
"javascript-framework"
2222
],
23-
"publishConfig": {
24-
"access": "public"
25-
},
23+
"publishConfig": { "access": "public" },
2624
"scripts": {
2725
"start": "npx webpack --config webpack.config.js",
2826
"build": "NODE_ENV=production npx webpack --config webpack.config.js",
@@ -36,9 +34,7 @@
3634
},
3735
"author": "CoCreate LLC",
3836
"license": "MIT",
39-
"bugs": {
40-
"url": "https://github.com/CoCreate-app/CoCreate-utils/issues"
41-
},
37+
"bugs": { "url": "https://github.com/CoCreate-app/CoCreate-utils/issues" },
4238
"homepage": "https://cocreate.app/docs/utils",
4339
"funding": {
4440
"type": "GitHub Sponsors ❤",
@@ -60,7 +56,5 @@
6056
"webpack-cli": "^4.5.0",
6157
"webpack-log": "^3.0.1"
6258
},
63-
"dependencies": {
64-
"@cocreate/docs": "^1.4.5"
65-
}
59+
"dependencies": { "@cocreate/docs": "^1.4.6" }
6660
}

src/utils.js

+74-163
Original file line numberDiff line numberDiff line change
@@ -247,168 +247,12 @@
247247
}
248248
}
249249

250-
function searchData(data, filter) {
251-
if (filter && filter.search) {
252-
if (filter['search']['type'] == 'and') {
253-
data = andSearch(data, filter['search']['value']);
254-
} else {
255-
data = orSearch(data, filter['search']['value']);
256-
}
257-
258-
const total = data.length;
259-
const startIndex = filter.startIndex;
260-
const count = filter.count;
261-
let result_data = [];
262-
263-
if (startIndex)
264-
data = data.slice(startIndex, total);
265-
if (count)
266-
data = data.slice(0, count)
267-
268-
result_data = data;
269-
filter['startIndex'] = startIndex
270-
if (count)
271-
filter['count'] = count
272-
filter['total'] = total
273-
return result_data
274-
} else {
275-
return data
276-
}
277-
}
278-
279-
//. or operator
280-
function orSearch(results, search) {
281-
var tmp
282-
if (search && search.length > 0) {
283-
284-
tmp = results.filter(function(item) {
285-
286-
for (var key in item) {
287-
var value = item[key];
288-
var __status = false;
289-
290-
var str_value = value;
291-
292-
if (Array.isArray(str_value) || typeof str_value == 'number') {
293-
str_value = str_value.toString();
294-
}
295-
296-
if (typeof str_value == 'string') {
297-
str_value = str_value.toUpperCase();
298-
}
299-
300-
for (let i = 0; i < search.length; i++) {
301-
if (typeof search[i] == 'string' && typeof str_value == 'string') {
302-
if (str_value.indexOf(search[i].toUpperCase()) > -1) {
303-
__status = true;
304-
break;
305-
}
306-
} else {
307-
if (value == search[i]) {
308-
__status = true;
309-
break;
310-
}
311-
}
312-
}
313-
314-
if (__status) {
315-
return true;
316-
}
317-
}
318-
319-
return false;
320-
})
321-
} else {
322-
tmp = results;
323-
}
324-
325-
return tmp;
326-
}
327-
328-
329-
//. and operator
330-
function andSearch(results, search) {
331-
var tmp
332-
if (search && search.length > 0) {
333-
334-
tmp = results.filter(function(item) {
335-
336-
for (let i = 0; i < search.length; i++) {
337-
var __status = false;
338-
339-
for (var key in item) {
340-
var value = item[key];
341-
342-
if (typeof search[i] == 'string') {
343-
344-
if (Array.isArray(value) || typeof value == 'number' ) {
345-
value = value.toString();
346-
}
347-
348-
if (typeof value == 'string') {
349-
value = value.toUpperCase();
350-
if (value.indexOf(search[i].toUpperCase()) > -1) {
351-
__status = true;
352-
break;
353-
}
354-
}
355-
356-
} else {
357-
if (value == search[i]) {
358-
__status = true;
359-
break;
360-
}
361-
}
362-
}
363-
364-
if (!__status) {
365-
return false;
366-
}
367-
}
368-
369-
return true;
370-
})
371-
} else {
372-
tmp = results;
373-
}
374-
375-
return tmp;
376-
}
377-
378-
function sortData(data, sorts) {
379-
if (!Array.isArray(sorts))
380-
sorts = [sorts]
381-
for (let sort of sorts) {
382-
let name = sort.name
383-
if (name) {
384-
data.sort((a, b) => {
385-
if (!a[name])
386-
a[name] = ''
387-
if (!b[name])
388-
b[name] = ''
389-
if (sort.type == '-1') {
390-
if (sort.valueType == 'number')
391-
return b[name] - a[name]
392-
else
393-
return b[name].localeCompare(a[name])
394-
} else {
395-
if (sort.valueType == 'number')
396-
return a[name] - b[name]
397-
else
398-
return a[name].localeCompare(b[name])
399-
}
400-
});
401-
}
402-
}
403-
return data;
404-
}
405-
406-
function queryData(item, query) {
250+
function queryData(item, query) {
407251
//. $contain, $range, $eq, $ne, $lt, $lte, $gt, $gte, $in, $nin, $geoWithin
408252
let flag = true;
409-
if (!item || !query) {
253+
if (!item)
410254
return false;
411-
}
255+
412256
if (Array.isArray(item)) return false;
413257
for (let i = 0; i < query.length; i++) {
414258
let fieldValue = item[query[i].name];
@@ -468,6 +312,75 @@
468312
return flag;
469313
}
470314

315+
function searchData(data, searches) {
316+
const search = searches['value']
317+
const operator = searches['type']
318+
319+
for (var key in data) {
320+
let value = data[key];
321+
let status = false;
322+
323+
if (Array.isArray(value) || typeof value == 'number') {
324+
value = value.toString();
325+
}
326+
327+
if (typeof value == 'object') {
328+
// run keys of object or JSON.stringify
329+
}
330+
331+
if (typeof value == 'string') {
332+
value = value.toUpperCase();
333+
}
334+
335+
for (let i = 0; i < search.length; i++) {
336+
if (typeof search[i] == 'string' && typeof value == 'string') {
337+
if (value.indexOf(search[i].toUpperCase()) > -1) {
338+
status = true;
339+
}
340+
} else {
341+
if (value == search[i]) {
342+
status = true;
343+
}
344+
}
345+
if (operator == 'or' && status) {
346+
return true;
347+
}
348+
if (operator == 'and' && !status) {
349+
return false;
350+
}
351+
}
352+
353+
}
354+
355+
}
356+
357+
function sortData(data, sorts) {
358+
if (!Array.isArray(sorts))
359+
sorts = [sorts]
360+
for (let sort of sorts) {
361+
let name = sort.name
362+
if (name) {
363+
data.sort((a, b) => {
364+
if (!a[name])
365+
a[name] = ''
366+
if (!b[name])
367+
b[name] = ''
368+
if (sort.type == '-1') {
369+
if (sort.valueType == 'number')
370+
return b[name] - a[name]
371+
else
372+
return b[name].localeCompare(a[name])
373+
} else {
374+
if (sort.valueType == 'number')
375+
return a[name] - b[name]
376+
else
377+
return a[name].localeCompare(b[name])
378+
}
379+
});
380+
}
381+
}
382+
return data;
383+
}
471384

472385
// function computeStyles(el, properties) {
473386
// let computed = window.getComputedStyle(el);
@@ -500,11 +413,9 @@
500413
domParser,
501414
queryDocumentSelector,
502415
queryDocumentSelectorAll,
416+
queryData,
503417
searchData,
504-
andSearch,
505-
orSearch,
506-
sortData,
507-
queryData
418+
sortData
508419
}
509420

510421
}));

0 commit comments

Comments
 (0)