MCPcopy Create free account
hub / github.com/deepnote/vscode-deepnote / concatMultilineString

Function concatMultilineString

src/renderers/client/helpers.ts:3–20  ·  view source on GitHub ↗
(str: nbformat.MultilineString, trim?: boolean)

Source from the content-addressed store, hash-verified

1import type * as nbformat from '@jupyterlab/nbformat';
2
3export function concatMultilineString(str: nbformat.MultilineString, trim?: boolean): string {
4 const nonLineFeedWhiteSpaceTrim = /(^[\t\f\v\r ]+|[\t\f\v\r ]+$)/g; // Local var so don't have to reset the lastIndex.
5 if (Array.isArray(str)) {
6 let result = '';
7 for (let i = 0; i < str.length; i += 1) {
8 const s = str[i];
9 if (i < str.length - 1 && !s.endsWith('\n')) {
10 result = result.concat(`${s}\n`);
11 } else {
12 result = result.concat(s);
13 }
14 }
15
16 // Just trim whitespace. Leave \n in place
17 return trim ? result.replace(nonLineFeedWhiteSpaceTrim, '') : result;
18 }
19 return trim ? str.toString().replace(nonLineFeedWhiteSpaceTrim, '') : str.toString();
20}

Callers 1

renderMethod · 0.90

Calls 2

toStringMethod · 0.65
replaceMethod · 0.45

Tested by

no test coverage detected