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

Method prepareValue

lib/attributeLibrary.ts:171–206  ·  view source on GitHub ↗
(
    repObj: Parameters<BaseLibrary['prepareValue']>[0],
    options: AttributeLibraryOptions = {},
  )

Source from the content-addressed store, hash-verified

169
170 // Prepare the value to store in the mapping
171 prepareValue(
172 repObj: Parameters<BaseLibrary['prepareValue']>[0],
173 options: AttributeLibraryOptions = {},
174 ): ReturnType<BaseLibrary['prepareValue']> {
175 const replacedObject = { ...repObj };
176
177 if (!this.isValidSelector(replacedObject.value)) {
178 return null;
179 }
180
181 const escapeFreeSelector = AttributeLibrary.removePseudoElements(replacedObject.value);
182
183 // checks if this value was already set
184 const realSelector = escapeFreeSelector.slice(1, escapeFreeSelector.length);
185
186 if (!options.ignoreAttributeSelectors) {
187 const newName = this.replaceAttributeSelector(escapeFreeSelector);
188
189 if (newName) {
190 replacedObject.renamedValue = newName;
191 }
192 }
193
194 if (
195 replacedObject.renamedValue !== undefined
196 && AttributeLibrary.isSelector(replacedObject.renamedValue)
197 ) {
198 replacedObject.renamedValue = (
199 replacedObject.renamedValue.slice(1, replacedObject.renamedValue.length)
200 );
201 }
202
203 replacedObject.value = realSelector;
204
205 return replacedObject;
206 }
207
208 // todo jpeer: #104 remove any
209 postfetchValue(result: string, opts: AttributeLibraryOptions): string | any {

Callers

nothing calls this directly

Calls 4

isValidSelectorMethod · 0.95
removePseudoElementsMethod · 0.80
isSelectorMethod · 0.80

Tested by

no test coverage detected