MCPcopy
hub / github.com/prettier/prettier / getFlowScalarLineContents

Function getFlowScalarLineContents

src/language-yaml/utilities.js:155–197  ·  view source on GitHub ↗

@param {string} nodeType @param {string} content

(nodeType, content, options)

Source from the content-addressed store, hash-verified

153@param {string} content
154*/
155function getFlowScalarLineContents(nodeType, content, options) {
156 const rawLineContents = content
157 .split("\n")
158 .map((lineContent, index, lineContents) =>
159 index === 0 && index === lineContents.length - 1
160 ? lineContent
161 : index !== 0 && index !== lineContents.length - 1
162 ? lineContent.trim()
163 : index === 0
164 ? lineContent.trimEnd()
165 : lineContent.trimStart(),
166 );
167
168 if (options.proseWrap === "preserve") {
169 return rawLineContents.map((lineContent) =>
170 lineContent ? [lineContent] : [],
171 );
172 }
173
174 /** @type {string[][]} */
175 const lines = [];
176 for (const [index, line] of rawLineContents.entries()) {
177 const words = splitWithSingleSpace(line);
178
179 if (
180 index > 0 &&
181 rawLineContents[index - 1].length > 0 &&
182 words.length > 0 &&
183 !(
184 // trailing backslash in quoteDouble should be preserved
185 nodeType === "quoteDouble" && lines.at(-1).at(-1).endsWith("\\")
186 )
187 ) {
188 lines[lines.length - 1] = [...lines.at(-1), ...words];
189 } else {
190 lines.push(words);
191 }
192 }
193
194 return options.proseWrap === "never"
195 ? lines.map((words) => [words.join(" ")])
196 : lines;
197}
198
199function getBlockValueLineContents(
200 node,

Callers 1

printFlowScalarContentFunction · 0.90

Calls 7

splitWithSingleSpaceFunction · 0.85
splitMethod · 0.80
trimEndMethod · 0.80
trimStartMethod · 0.80
atMethod · 0.80
mapMethod · 0.45
trimMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…