From e660c2d7a45f16b781755fad4c04ad888a0742f5 Mon Sep 17 00:00:00 2001 From: Sten Raudmets Date: Mon, 29 Jan 2024 11:38:51 +0000 Subject: [PATCH] Remove delimiter logic --- dist/index.js | 24 ---------- src/text-format.test.ts | 97 ----------------------------------------- src/text-format.ts | 51 ---------------------- 3 files changed, 172 deletions(-) delete mode 100644 src/text-format.test.ts diff --git a/dist/index.js b/dist/index.js index 9050ad7..b68947c 100644 --- a/dist/index.js +++ b/dist/index.js @@ -127849,36 +127849,12 @@ function getSign(bytes) { } ;// CONCATENATED MODULE: ./src/text-format.ts -function createHtmlComment(content) { - return ``; -} -function getAppNameDelimiter(appName) { - return { - start: createHtmlComment(`${appName} start`), - end: createHtmlComment(`${appName} end`), - }; -} function formatTextFragments(...text) { return text .map((fragment) => fragment.trim()) .filter(Boolean) .join('\n\n'); } -function swapContentPartiallyByDelimiter({ existingContent, newPartialContent, delimiterIdentifier, }) { - const delimiter = getAppNameDelimiter(delimiterIdentifier); - const startIndex = existingContent.indexOf(delimiter.start); - const endIndex = existingContent.indexOf(delimiter.end, startIndex); - if (startIndex === -1 || endIndex === -1) { - return formatTextFragments(existingContent, delimiter.start, newPartialContent, delimiter.end); - } - const existingBodyStart = existingContent.substring(0, startIndex); - const existingBodyEnd = existingContent.substring(endIndex + delimiter.end.length); - return formatTextFragments(existingBodyStart, delimiter.start, newPartialContent, delimiter.end, existingBodyEnd); -} -function createContentByDelimiter({ title, content, delimiterIdentifier, }) { - const appNameDelimiter = getAppNameDelimiter(delimiterIdentifier); - return formatTextFragments(title, appNameDelimiter.start, content, appNameDelimiter.end); -} ;// CONCATENATED MODULE: ./src/comments.ts diff --git a/src/text-format.test.ts b/src/text-format.test.ts deleted file mode 100644 index f679b9e..0000000 --- a/src/text-format.test.ts +++ /dev/null @@ -1,97 +0,0 @@ -import { expect, test, describe } from 'vitest'; -import { createContentByDelimiter, swapContentPartiallyByDelimiter } from './text-format'; - -describe('swapContentPartiallyByDelimiter', () => { - const original = ` -## Bundle Sizes - - - -alpha - - - - - -beta - - -`.trim(); - - test('in place swap', () => { - const swapped = swapContentPartiallyByDelimiter({ - existingContent: original, - newPartialContent: 'delta', - delimiterIdentifier: 'account-page-frontend', - }); - expect(swapped).toBe( - ` -## Bundle Sizes - - - -alpha - - - - - -delta - - -`.trim(), - ); - }); - - test('new addition in swap', () => { - const swapped = swapContentPartiallyByDelimiter({ - existingContent: original, - newPartialContent: 'gamma', - delimiterIdentifier: 'stories-page', - }); - expect(swapped).toBe( - ` -## Bundle Sizes - - - -alpha - - - - - -beta - - - - - -gamma - - -`.trim(), - ); - }); -}); - -describe('createContentByDelimiter', () => { - test('add content', () => { - const swapped = createContentByDelimiter({ - title: '## Bundle Sizes', - content: 'alpha', - delimiterIdentifier: 'cards-page', - }); - expect(swapped).toBe( - ` -## Bundle Sizes - - - -alpha - - -`.trim(), - ); - }); -}); diff --git a/src/text-format.ts b/src/text-format.ts index c9c25f6..abb4b53 100644 --- a/src/text-format.ts +++ b/src/text-format.ts @@ -1,57 +1,6 @@ -function createHtmlComment(content: string) { - return ``; -} - -function getAppNameDelimiter(appName: string) { - return { - start: createHtmlComment(`${appName} start`), - end: createHtmlComment(`${appName} end`), - } as const; -} - export function formatTextFragments(...text: string[]) { return text .map((fragment) => fragment.trim()) .filter(Boolean) .join('\n\n'); } - -export function swapContentPartiallyByDelimiter({ - existingContent, - newPartialContent, - delimiterIdentifier, -}: { - existingContent: string; - newPartialContent: string; - delimiterIdentifier: string; -}) { - const delimiter = getAppNameDelimiter(delimiterIdentifier); - const startIndex = existingContent.indexOf(delimiter.start); - const endIndex = existingContent.indexOf(delimiter.end, startIndex); - if (startIndex === -1 || endIndex === -1) { - return formatTextFragments(existingContent, delimiter.start, newPartialContent, delimiter.end); - } - const existingBodyStart = existingContent.substring(0, startIndex); - const existingBodyEnd = existingContent.substring(endIndex + delimiter.end.length); - - return formatTextFragments( - existingBodyStart, - delimiter.start, - newPartialContent, - delimiter.end, - existingBodyEnd, - ); -} - -export function createContentByDelimiter({ - title, - content, - delimiterIdentifier, -}: { - title: string; - content: string; - delimiterIdentifier: string; -}) { - const appNameDelimiter = getAppNameDelimiter(delimiterIdentifier); - return formatTextFragments(title, appNameDelimiter.start, content, appNameDelimiter.end); -}