MCPcopy Index your code
hub / github.com/codeceptjs/CodeceptJS / parsedJsonAsString

Method parsedJsonAsString

lib/locator.js:94–119  ·  view source on GitHub ↗
(locator)

Source from the content-addressed store, hash-verified

92 }
93
94 parsedJsonAsString(locator) {
95 if (typeof locator !== 'string') {
96 return false
97 }
98
99 const trimmed = locator.trim()
100 if (!trimmed.startsWith('{') || !trimmed.endsWith('}')) {
101 return false
102 }
103
104 try {
105 const parsed = JSON.parse(trimmed)
106 if (typeof parsed === 'object' && parsed !== null && !Array.isArray(parsed)) {
107 this.locator = parsed
108 this.type = Object.keys(parsed)[0]
109 this.value = parsed[this.type]
110 this.strict = true
111
112 Locator.filters.forEach(f => f(parsed, this))
113 return true
114 }
115 } catch (e) {
116 // continue with normal string processing
117 }
118 return false
119 }
120
121 /**
122 * @returns {string}

Callers 1

constructorMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected