github.com/argoproj/argo-cd@v1.8.7/ui/src/app/applications/components/label-selector.ts (about) 1 type operatorFn = (labels: {[name: string]: string}, key: string, values: string[]) => boolean; 2 3 const operators: {[type: string]: operatorFn} = { 4 '!=': (labels, key, values) => labels[key] !== values[0], 5 '==': (labels, key, values) => labels[key] === values[0], 6 '=': (labels, key, values) => labels[key] === values[0], 7 '[\\W]notin[\\W]': (labels, key, values) => !values.includes(labels[key]), 8 '[\\W]in[\\W]': (labels, key, values) => values.includes(labels[key]), 9 '[\\W]gt[\\W]': (labels, key, values) => parseFloat(labels[key]) > parseFloat(values[0]), 10 '[\\W]lt[\\W]': (labels, key, values) => parseFloat(labels[key]) < parseFloat(values[0]) 11 }; 12 13 function split(input: string, delimiter: string | RegExp): string[] { 14 return input 15 .split(delimiter) 16 .map(part => part.trim()) 17 .filter(part => part !== ''); 18 } 19 20 export type LabelSelector = (labels: {[name: string]: string}) => boolean; 21 22 export function parse(selector: string): LabelSelector { 23 for (const type of Object.keys(operators)) { 24 const operator = operators[type]; 25 const parts = split(selector, new RegExp(type)); 26 if (parts.length > 1) { 27 const values = split(parts[1], ','); 28 return labels => operator(labels, parts[0], values); 29 } 30 } 31 if (selector.startsWith('!')) { 32 return labels => !labels.hasOwnProperty(selector.slice(1)); 33 } 34 return labels => labels.hasOwnProperty(selector); 35 } 36 37 export function match(selector: string, labels: {[name: string]: string}): boolean { 38 return parse(selector)(labels || {}); 39 }