MCPcopy Create free account
hub / github.com/JPeer264/node-rcs-core / replaceAnAttributeSelector

Method replaceAnAttributeSelector

lib/attributeLibrary.ts:60–122  ·  view source on GitHub ↗
(
    result: string | false,
    attributeSelector: string,
    value: AttributeSelector,
    slicedSelector: string,
  )

Source from the content-addressed store, hash-verified

58 }
59
60 static replaceAnAttributeSelector(
61 result: string | false,
62 attributeSelector: string,
63 value: AttributeSelector,
64 slicedSelector: string,
65 ): string | false {
66 if (result !== false) return result;
67
68 const attributeString = attributeSelector.slice(1, attributeSelector.length);
69
70 if (attributeSelector.charAt(0) === '|') {
71 const match = slicedSelector.match(`^${attributeString}-`);
72
73 if (match) {
74 const newMatch = match[0].replace(/-$/, '');
75
76 return `${newMatch}-${value.nameGeneratorCounter.generate(slicedSelector)}`;
77 }
78 }
79
80 if (attributeSelector.charAt(0).match(/^[=~|]/)) {
81 const match = slicedSelector.match(attributeString);
82
83 if (match && slicedSelector === match[0]) {
84 return match[0];
85 }
86 }
87
88 switch (attributeSelector.charAt(0)) {
89 case '*': {
90 const match = slicedSelector.match(attributeString);
91
92 if (match) {
93 return value.nameGeneratorCounter.generate(slicedSelector)
94 + match[0]
95 + value.nameGeneratorCounter.generate(slicedSelector);
96 }
97 break;
98 }
99 case '^': {
100 const match = slicedSelector.match(`^${attributeString}`);
101
102 if (match) {
103 return match[0] + value.nameGeneratorCounter.generate(slicedSelector);
104 }
105
106 break;
107 }
108 case '$': {
109 const match = slicedSelector.match(`${attributeString}$`);
110
111 if (match) {
112 return value.nameGeneratorCounter.generate(slicedSelector) + match[0];
113 }
114
115 break;
116 }
117

Callers 2

setAttributeSelectorMethod · 0.80

Calls 1

generateMethod · 0.80

Tested by

no test coverage detected