MCPcopy Create free account
hub / github.com/SuperMap/iClient-JavaScript / isSimpleComparison

Function isSimpleComparison

src/common/util/FilterCondition.js:60–87  ·  view source on GitHub ↗
(filter)

Source from the content-addressed store, hash-verified

58
59// 要判断一下是否是二维数组的filter
60function isSimpleComparison(filter) {
61 if (!filter || !Array.isArray(filter)) {
62 return false;
63 }
64 const [operator, ...operands] = filter;
65
66 const simpleOps = ['==', '!=', '>', '>=', '<', '<=', 'in', '!in', 'has', '!has'];
67 const logicalOps = ['all', 'any', 'none'];
68 if (simpleOps.includes(operator)) {
69 // has / !has:只要求一个字段名
70 if (operator === 'has' || operator === '!has') {
71 // 排除这种: ['has', ['get', 'name']]
72 return typeof operands[0] === 'string';
73 }
74 // in / !in:field + 至少一个值
75 if (operator === 'in' || operator === '!in') {
76 if (typeof operands[0] !== 'string') { return false; }
77 return operands.length > 1;
78 }
79 // 普通比较:field + value
80 return operands.length === 2 && typeof operands[0] === 'string';
81 }
82 if (logicalOps.includes(operator)) {
83 if (operands.length === 0) { return false; }
84 return operands.every((item) => isSimpleComparison(item));
85 }
86 return false;
87}
88
89// 处理类似"O'Reilly"这种字符串,在SQL语句中需要转,单引号需要处理
90function formatValue(value) {

Callers 2

mapboxFilterToCqlFilterFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected