Comparing version 1.3.0 to 1.3.1
@@ -43,3 +43,3 @@ # Advanced usage | ||
If you already have bookmarks in your browser you can speed up the process of converting them into `YAML` using the `convert` tool, read more about that here: | ||
[Exporting existing bookmarks](./docs/EXPORTING-EXISTING-BOOKMARKS.md). | ||
[Exporting existing bookmarks](./EXPORTING-EXISTING-BOOKMARKS.md). | ||
@@ -46,0 +46,0 @@ The `convert` command works in a similar way to `get` with the same options. |
@@ -54,2 +54,2 @@ # Exporting existing bookmarks | ||
You might want to take the time to add descriptions to the `YAML` to give your users a better experience. For more options on how to convert `HTML` bookmarks to `YAML` see: [Advanced usage](./docs/ADVANCED-USAGE.md). | ||
You might want to take the time to add descriptions to the `YAML` to give your users a better experience. For more options on how to convert `HTML` bookmarks to `YAML` see: [Advanced usage](./ADVANCED-USAGE.md). |
{ | ||
"name": "bookworms", | ||
"version": "1.3.0", | ||
"version": "1.3.1", | ||
"description": "A cli tool for centralising and generating bookmarks", | ||
@@ -5,0 +5,0 @@ "main": "./src/index.js", |
@@ -101,3 +101,2 @@ <p align="center"> | ||
- Test `convert` with browsers other than Chrome | ||
- Bug fix markdown generator header for deep folders | ||
- Improve documentation for using bookworms modules | ||
@@ -104,0 +103,0 @@ - Allow users to select the exports they want or won't want |
@@ -1,248 +0,309 @@ | ||
import {jest} from '@jest/globals' | ||
import {generateImportBookmarkMarkup, traverseStructure, traverseFolders, traverseBookmarks, generateBookmarkFolderMarkup, generateBookmarkLinkMarkup, generateTimeStamp} from '../generate-bookmarks.js'; | ||
import { jest } from "@jest/globals"; | ||
import { | ||
generateImportBookmarkMarkup, | ||
traverseStructure, | ||
traverseFolders, | ||
traverseBookmarks, | ||
generateBookmarkFolderMarkup, | ||
generateBookmarkLinkMarkup, | ||
generateTimeStamp, | ||
} from "../generate-bookmarks.js"; | ||
describe('generating bookmarks structure', () => { | ||
describe('generateImportBookmarkMarkup', () => { | ||
test('should return full structure for bookmarks', () => { | ||
Date.now = jest.fn(() => 1487076708000) | ||
const config = { | ||
label: 'Bookmarks config', | ||
description: 'Bookmarks config description', | ||
folders: [{ | ||
label: 'Folder 1', | ||
description: 'Folder description 1', | ||
bookmarks: [{ | ||
label: 'Link 1', | ||
description: 'Bookmark 1', | ||
href: 'https://www.testlink1.com' | ||
}] | ||
}, | ||
{ | ||
label: 'Folder 2', | ||
description: 'Folder description 2', | ||
folders: [{ | ||
label: 'Folder 2.1', | ||
description: 'Folder description 2.1', | ||
bookmarks: [{ | ||
label: 'Link 2', | ||
description: 'Bookmark 2', | ||
href: 'https://www.testlink2.com' | ||
}] | ||
}] | ||
}], | ||
bookmarks: [{ | ||
label: 'Link 3', | ||
description: 'Bookmark 3', | ||
href: 'https://www.testlink3.com' | ||
}] | ||
} | ||
expect(generateImportBookmarkMarkup(config)).toMatchSnapshot() | ||
}); | ||
describe("generating bookmarks structure", () => { | ||
describe("generateImportBookmarkMarkup", () => { | ||
test("should return full structure for bookmarks", () => { | ||
jest | ||
.spyOn(Date.prototype, "toLocaleString") | ||
.mockReturnValue("30/09/2021, 19:43:14"); | ||
const config = { | ||
label: "Bookmarks config", | ||
description: "Bookmarks config description", | ||
folders: [ | ||
{ | ||
label: "Folder 1", | ||
description: "Folder description 1", | ||
bookmarks: [ | ||
{ | ||
label: "Link 1", | ||
description: "Bookmark 1", | ||
href: "https://www.testlink1.com", | ||
}, | ||
], | ||
}, | ||
{ | ||
label: "Folder 2", | ||
description: "Folder description 2", | ||
folders: [ | ||
{ | ||
label: "Folder 2.1", | ||
description: "Folder description 2.1", | ||
bookmarks: [ | ||
{ | ||
label: "Link 2", | ||
description: "Bookmark 2", | ||
href: "https://www.testlink2.com", | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
], | ||
bookmarks: [ | ||
{ | ||
label: "Link 3", | ||
description: "Bookmark 3", | ||
href: "https://www.testlink3.com", | ||
}, | ||
], | ||
}; | ||
expect(generateImportBookmarkMarkup(config)).toMatchSnapshot(); | ||
}); | ||
describe('traverseStructure', () => { | ||
test('should return structure for browsers bookmarks', () => { | ||
Date.now = jest.fn(() => 1487076708000) | ||
const structure = { | ||
folders: [{ | ||
label: 'browsers folder 1', | ||
description: 'browsers folder description 1', | ||
bookmarks: [{ | ||
label: 'browsers link 1', | ||
description: 'browsers bookmark 1', | ||
href: 'https://www.testlink1.com' | ||
}] | ||
}, | ||
{ | ||
label: 'browsers folder 2', | ||
description: 'browsers folder description 2', | ||
folders: [{ | ||
label: 'browsers folder 2.1', | ||
description: 'browsers folder description 2.1', | ||
bookmarks: [{ | ||
label: 'browsers link 2', | ||
description: 'browsers bookmark 2', | ||
href: 'https://www.testlink2.com' | ||
}] | ||
}] | ||
}], | ||
bookmarks: [{ | ||
label: 'browsers link 3', | ||
description: 'browsers bookmark 3', | ||
href: 'https://www.testlink3.com' | ||
}] | ||
} | ||
expect(traverseStructure(structure, 'browsers')).toMatchSnapshot() | ||
}); | ||
test('should return structure for Readme bookmarks', () => { | ||
Date.now = jest.fn(() => 1487076708000) | ||
const structure = { | ||
folders: [{ | ||
label: 'Readme folder 1', | ||
description: 'Readme folder description 1', | ||
bookmarks: [{ | ||
label: 'Readme link 1', | ||
description: 'Readme bookmark 1', | ||
href: 'https://www.testlink1.com' | ||
}] | ||
}, | ||
{ | ||
label: 'Readme folder 2', | ||
description: 'Readme folder description 2', | ||
folders: [{ | ||
label: 'Readme folder 2.1', | ||
description: 'Readme folder description 2.1', | ||
bookmarks: [{ | ||
label: 'Readme link 2', | ||
description: 'Readme bookmark 2', | ||
href: 'https://www.testlink2.com' | ||
}] | ||
}] | ||
}], | ||
bookmarks: [{ | ||
label: 'Readme link 3', | ||
description: 'Readme bookmark 3', | ||
href: 'https://www.testlink3.com' | ||
}] | ||
} | ||
expect(traverseStructure(structure, 'readme')).toMatchSnapshot() | ||
}); | ||
}) | ||
describe('traverseFolders', () => { | ||
test('should return simple structure for browsers folders', () => { | ||
Date.now = jest.fn(() => 1487076708000) | ||
const folders = [ | ||
{ | ||
label: 'browsers folder 1', | ||
description: 'browsers folder description 1' | ||
}, | ||
{ | ||
label: 'browsers folder 2', | ||
description: 'browsers folder description 2' | ||
} | ||
] | ||
expect(traverseFolders(folders, 'browsers')).toMatchSnapshot() | ||
}); | ||
test('should return structure for nested browsers folders', () => { | ||
Date.now = jest.fn(() => 1487076708000) | ||
const folders = [ | ||
{ | ||
label: 'browsers folder 1', | ||
description: 'browsers folder description 1', | ||
folders: [ | ||
{ | ||
label: 'browsers folder 1.1', | ||
description: 'browsers folder description 1.1' | ||
} | ||
] | ||
}, | ||
{ | ||
label: 'browsers folder 2', | ||
description: 'browsers folder description 2' | ||
} | ||
] | ||
expect(traverseFolders(folders, 'browsers')).toMatchSnapshot() | ||
}); | ||
test('should return simple structure for Readme folders', () => { | ||
Date.now = jest.fn(() => 1487076708000) | ||
const folders = [ | ||
{ | ||
label: 'Readme folder 1', | ||
description: 'Readme folder description 1' | ||
}, | ||
{ | ||
label: 'Readme folder 2', | ||
description: 'Readme folder description 2' | ||
} | ||
] | ||
expect(traverseFolders(folders, 'readme')).toMatchSnapshot() | ||
}); | ||
test('should return structure for nested Readme folders', () => { | ||
Date.now = jest.fn(() => 1487076708000) | ||
const folders = [ | ||
{ | ||
label: 'Readme folder 1', | ||
description: 'Readme folder description 1', | ||
folders: [ | ||
{ | ||
label: 'Readme folder 1.1', | ||
description: 'Readme folder description 1.1' | ||
} | ||
] | ||
}, | ||
{ | ||
label: 'Readme folder 2', | ||
description: 'Readme folder description 2' | ||
} | ||
] | ||
expect(traverseFolders(folders, 'readme')).toMatchSnapshot() | ||
}); | ||
}) | ||
describe('traverseBookmarks', () => { | ||
test('should return structure for browsers links', () => { | ||
Date.now = jest.fn(() => 1487076708000) | ||
const bookmarks = [{ | ||
label: 'browsers link 1', | ||
description: 'browsers bookmark 1', | ||
href: 'https://www.testlink1.com' | ||
}); | ||
describe("traverseStructure", () => { | ||
test("should return structure for browsers bookmarks", () => { | ||
Date.now = jest.fn(() => 1487076708000); | ||
const structure = { | ||
folders: [ | ||
{ | ||
label: "browsers folder 1", | ||
description: "browsers folder description 1", | ||
bookmarks: [ | ||
{ | ||
label: "browsers link 1", | ||
description: "browsers bookmark 1", | ||
href: "https://www.testlink1.com", | ||
}, | ||
], | ||
}, | ||
{ | ||
label: "browsers folder 2", | ||
description: "browsers folder description 2", | ||
folders: [ | ||
{ | ||
label: "browsers folder 2.1", | ||
description: "browsers folder description 2.1", | ||
bookmarks: [ | ||
{ | ||
label: "browsers link 2", | ||
description: "browsers bookmark 2", | ||
href: "https://www.testlink2.com", | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
], | ||
bookmarks: [ | ||
{ | ||
label: "browsers link 3", | ||
description: "browsers bookmark 3", | ||
href: "https://www.testlink3.com", | ||
}, | ||
], | ||
}; | ||
expect(traverseStructure(structure, "browsers")).toMatchSnapshot(); | ||
}); | ||
test("should return structure for Readme bookmarks", () => { | ||
Date.now = jest.fn(() => 1487076708000); | ||
const structure = { | ||
folders: [ | ||
{ | ||
label: "Readme folder 1", | ||
description: "Readme folder description 1", | ||
bookmarks: [ | ||
{ | ||
label: "Readme link 1", | ||
description: "Readme bookmark 1", | ||
href: "https://www.testlink1.com", | ||
}, | ||
], | ||
}, | ||
{ | ||
label: "Readme folder 2", | ||
description: "Readme folder description 2", | ||
folders: [ | ||
{ | ||
label: "Readme folder 2.1", | ||
description: "Readme folder description 2.1", | ||
bookmarks: [ | ||
{ | ||
label: "Readme link 2", | ||
description: "Readme bookmark 2", | ||
href: "https://www.testlink2.com", | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
], | ||
bookmarks: [ | ||
{ | ||
label: "Readme link 3", | ||
description: "Readme bookmark 3", | ||
href: "https://www.testlink3.com", | ||
}, | ||
], | ||
}; | ||
expect(traverseStructure(structure, "readme")).toMatchSnapshot(); | ||
}); | ||
}); | ||
describe("traverseFolders", () => { | ||
test("should return simple structure for browsers folders", () => { | ||
Date.now = jest.fn(() => 1487076708000); | ||
const folders = [ | ||
{ | ||
label: "browsers folder 1", | ||
description: "browsers folder description 1", | ||
}, | ||
{ | ||
label: "browsers folder 2", | ||
description: "browsers folder description 2", | ||
}, | ||
]; | ||
expect(traverseFolders(folders, "browsers")).toMatchSnapshot(); | ||
}); | ||
test("should return structure for nested browsers folders", () => { | ||
Date.now = jest.fn(() => 1487076708000); | ||
const folders = [ | ||
{ | ||
label: "browsers folder 1", | ||
description: "browsers folder description 1", | ||
folders: [ | ||
{ | ||
label: "browsers folder 1.1", | ||
description: "browsers folder description 1.1", | ||
}, | ||
], | ||
}, | ||
{ | ||
label: "browsers folder 2", | ||
description: "browsers folder description 2", | ||
}, | ||
]; | ||
expect(traverseFolders(folders, "browsers")).toMatchSnapshot(); | ||
}); | ||
test("should return simple structure for Readme folders", () => { | ||
Date.now = jest.fn(() => 1487076708000); | ||
const folders = [ | ||
{ | ||
label: "Readme folder 1", | ||
description: "Readme folder description 1", | ||
}, | ||
{ | ||
label: "Readme folder 2", | ||
description: "Readme folder description 2", | ||
}, | ||
]; | ||
expect(traverseFolders(folders, "readme")).toMatchSnapshot(); | ||
}); | ||
test("should return structure for nested Readme folders", () => { | ||
Date.now = jest.fn(() => 1487076708000); | ||
const folders = [ | ||
{ | ||
label: "Readme folder 1", | ||
description: "Readme folder description 1", | ||
folders: [ | ||
{ | ||
label: 'browsers link 2', | ||
description: 'browsers bookmark 2', | ||
href: 'https://www.testlink2.com' | ||
}] | ||
expect(traverseBookmarks(bookmarks, 'browsers')).toMatchSnapshot() | ||
}); | ||
test('should return structure for Readme links', () => { | ||
Date.now = jest.fn(() => 1487076708000) | ||
const bookmarks = [{ | ||
label: 'Readme link 1', | ||
description: 'Readme bookmark 1', | ||
href: 'https://www.testlink1.com' | ||
label: "Readme folder 1.1", | ||
description: "Readme folder description 1.1", | ||
}, | ||
{ | ||
label: 'Readme link 2', | ||
description: 'Readme bookmark 2', | ||
href: 'https://www.testlink2.com' | ||
} | ||
] | ||
expect(traverseBookmarks(bookmarks, 'readme')).toMatchSnapshot() | ||
}); | ||
}) | ||
], | ||
}, | ||
{ | ||
label: "Readme folder 2", | ||
description: "Readme folder description 2", | ||
}, | ||
]; | ||
expect(traverseFolders(folders, "readme")).toMatchSnapshot(); | ||
}); | ||
}); | ||
describe("traverseBookmarks", () => { | ||
test("should return structure for browsers links", () => { | ||
Date.now = jest.fn(() => 1487076708000); | ||
const bookmarks = [ | ||
{ | ||
label: "browsers link 1", | ||
description: "browsers bookmark 1", | ||
href: "https://www.testlink1.com", | ||
}, | ||
{ | ||
label: "browsers link 2", | ||
description: "browsers bookmark 2", | ||
href: "https://www.testlink2.com", | ||
}, | ||
]; | ||
expect(traverseBookmarks(bookmarks, "browsers")).toMatchSnapshot(); | ||
}); | ||
test("should return structure for Readme links", () => { | ||
Date.now = jest.fn(() => 1487076708000); | ||
const bookmarks = [ | ||
{ | ||
label: "Readme link 1", | ||
description: "Readme bookmark 1", | ||
href: "https://www.testlink1.com", | ||
}, | ||
{ | ||
label: "Readme link 2", | ||
description: "Readme bookmark 2", | ||
href: "https://www.testlink2.com", | ||
}, | ||
]; | ||
expect(traverseBookmarks(bookmarks, "readme")).toMatchSnapshot(); | ||
}); | ||
}); | ||
describe('generateBookmarkFolderMarkup', () => { | ||
test('should return structure for browsers folder', () => { | ||
Date.now = jest.fn(() => 1487076708000) | ||
expect(generateBookmarkFolderMarkup(null, 'browsers folder', 'browsers folder description', '<div>Children HTML</div>', 'browsers')).toMatchSnapshot() | ||
}); | ||
test('should return structure for Readme folder', () => { | ||
Date.now = jest.fn(() => 1487076708000) | ||
expect(generateBookmarkFolderMarkup(0, 'Readme folder', 'Readme folder description', '_Children markdown_', 'readme')).toMatchSnapshot() | ||
}); | ||
}) | ||
describe('generateBookmarkLinkMarkup', () => { | ||
test('should return structure for browsers link', () => { | ||
Date.now = jest.fn(() => 1487076708000) | ||
const bookmark = { | ||
label: 'browsers link', | ||
description: 'browsers bookmark', | ||
href: 'https://www.testlink.com' | ||
} | ||
expect(generateBookmarkLinkMarkup(bookmark, 'browsers')).toMatchSnapshot() | ||
}); | ||
test('should return structure for Readme link', () => { | ||
Date.now = jest.fn(() => 1487076708000) | ||
const bookmark = { | ||
label: 'Readme link', | ||
description: 'Readme bookmark', | ||
href: 'https://www.testlink.com' | ||
} | ||
expect(generateBookmarkLinkMarkup(bookmark, 'readme')).toMatchSnapshot() | ||
}); | ||
}) | ||
describe('generateTimeStamp', () => { | ||
test('should return timestamp', () => { | ||
Date.now = jest.fn(() => 1487076708000) | ||
expect(generateTimeStamp()).toEqual(1487076708000) | ||
}); | ||
}) | ||
}) | ||
describe("generateBookmarkFolderMarkup", () => { | ||
test("should return structure for browsers folder", () => { | ||
Date.now = jest.fn(() => 1487076708000); | ||
expect( | ||
generateBookmarkFolderMarkup( | ||
null, | ||
"browsers folder", | ||
"browsers folder description", | ||
"<div>Children HTML</div>", | ||
"browsers" | ||
) | ||
).toMatchSnapshot(); | ||
}); | ||
test("should return structure for Readme folder", () => { | ||
Date.now = jest.fn(() => 1487076708000); | ||
expect( | ||
generateBookmarkFolderMarkup( | ||
0, | ||
"Readme folder", | ||
"Readme folder description", | ||
"_Children markdown_", | ||
"readme" | ||
) | ||
).toMatchSnapshot(); | ||
}); | ||
}); | ||
describe("generateBookmarkLinkMarkup", () => { | ||
test("should return structure for browsers link", () => { | ||
Date.now = jest.fn(() => 1487076708000); | ||
const bookmark = { | ||
label: "browsers link", | ||
description: "browsers bookmark", | ||
href: "https://www.testlink.com", | ||
}; | ||
expect( | ||
generateBookmarkLinkMarkup(bookmark, "browsers") | ||
).toMatchSnapshot(); | ||
}); | ||
test("should return structure for Readme link", () => { | ||
Date.now = jest.fn(() => 1487076708000); | ||
const bookmark = { | ||
label: "Readme link", | ||
description: "Readme bookmark", | ||
href: "https://www.testlink.com", | ||
}; | ||
expect(generateBookmarkLinkMarkup(bookmark, "readme")).toMatchSnapshot(); | ||
}); | ||
}); | ||
describe("generateTimeStamp", () => { | ||
test("should return timestamp", () => { | ||
Date.now = jest.fn(() => 1487076708000); | ||
expect(generateTimeStamp()).toEqual(1487076708000); | ||
}); | ||
}); | ||
}); |
@@ -39,21 +39,27 @@ import { fetchBookmarkConfig } from "./load-bookmarks.js"; | ||
const traverseStructure = ({ bookmarks, folders }, type) => { | ||
const traverseStructure = ({ bookmarks, folders }, type, index = 1) => { | ||
const arr = []; | ||
if (folders) { | ||
arr.push(traverseFolders(folders, type)); | ||
switch (type) { | ||
case "browsers": | ||
arr.push(traverseFolders(folders, type, index)); | ||
arr.push(traverseBookmarks(bookmarks, type)); | ||
break; | ||
case "readme": | ||
arr.push(traverseBookmarks(bookmarks, type)); | ||
arr.push(traverseFolders(folders, type, index)); | ||
} | ||
if (bookmarks) { | ||
arr.push(traverseBookmarks(bookmarks, type)); | ||
} | ||
return arr.join(""); | ||
}; | ||
const traverseFolders = (folders, type) => { | ||
const traverseFolders = (folders, type, index = 1) => { | ||
const arr = []; | ||
if (!folders) { | ||
return arr; | ||
} | ||
folders.forEach((folder) => { | ||
const children = traverseStructure(folder, type); | ||
// todo fix the depth of folder headings for Readme | ||
const children = traverseStructure(folder, type, index + 1); | ||
arr.push( | ||
generateBookmarkFolderMarkup( | ||
1, | ||
index, | ||
folder.label, | ||
@@ -71,2 +77,6 @@ folder.description, | ||
const arr = []; | ||
if (!bookmarks) { | ||
return arr; | ||
} | ||
bookmarks.forEach((bookmark) => { | ||
@@ -73,0 +83,0 @@ arr.push(generateBookmarkLinkMarkup(bookmark, type)); |
@@ -1,39 +0,83 @@ | ||
import {bookmark, bookmarkFolder, bookmarkLink, addDescription, addBookwormsDescription} from '../browsers' | ||
import { jest } from "@jest/globals"; | ||
import { | ||
bookmark, | ||
bookmarkFolder, | ||
bookmarkLink, | ||
addDescription, | ||
addBookwormsDescription, | ||
} from "../browsers"; | ||
// I don't like using snapshots for these tests but because of the HTML formatting its easier | ||
describe('Templates - browsers', () => { | ||
describe('bookmark', () => { | ||
test('should return structure for browsers bookmarks', () => { | ||
expect(bookmark('26/09/2021 - 6pm', 'Bookmarks label', 'Bookmarks description', '<div>Children HTML</div>')).toMatchSnapshot() | ||
}); | ||
}) | ||
describe('bookmarkFolder', () => { | ||
test('should return description, header and children', () => { | ||
expect(bookmarkFolder('26/09/2021 - 6pm', 'Section label', 'Section description', '<div>Children HTML</div>')).toMatchSnapshot() | ||
}); | ||
}) | ||
describe('bookmarkFolder', () => { | ||
test('should return description, header and children', () => { | ||
expect(bookmarkFolder('26/09/2021 - 6pm', 'Link label', 'Link description', '<div>Children HTML</div>')).toMatchSnapshot() | ||
}); | ||
}) | ||
describe('bookmarkLink', () => { | ||
test('should return description and link', () => { | ||
expect(bookmarkLink('26/09/2021 - 6pm', 'Link label', 'Link description', 'https://www.testlink.com')).toMatchSnapshot() | ||
}); | ||
}) | ||
describe('addDescription', () => { | ||
test('should return description comment', () => { | ||
expect(addDescription('hello world')).toEqual('<!-- hello world -->') | ||
}); | ||
test('should return empty string', () => { | ||
expect(addDescription('')).toEqual('') | ||
}); | ||
}) | ||
describe('addBookwormsDescription', () => { | ||
test('should return description for file comment', () => { | ||
expect(addBookwormsDescription(1633027394454)).toEqual('<!-- These bookmarks were last updated on 30/09/2021, 19:43:14 using bookworms (https://github.com/thearegee/bookworms) -->') | ||
}); | ||
}) | ||
describe("Templates - browsers", () => { | ||
describe("bookmark", () => { | ||
test("should return structure for browsers bookmarks", () => { | ||
expect( | ||
bookmark( | ||
"26/09/2021 - 6pm", | ||
"Bookmarks label", | ||
"Bookmarks description", | ||
"<div>Children HTML</div>" | ||
) | ||
).toMatchSnapshot(); | ||
}); | ||
}); | ||
}) | ||
describe("bookmarkFolder", () => { | ||
test("should return description, header and children", () => { | ||
expect( | ||
bookmarkFolder( | ||
"26/09/2021 - 6pm", | ||
"Section label", | ||
"Section description", | ||
"<div>Children HTML</div>" | ||
) | ||
).toMatchSnapshot(); | ||
}); | ||
}); | ||
describe("bookmarkFolder", () => { | ||
test("should return description, header and children", () => { | ||
expect( | ||
bookmarkFolder( | ||
"26/09/2021 - 6pm", | ||
"Link label", | ||
"Link description", | ||
"<div>Children HTML</div>" | ||
) | ||
).toMatchSnapshot(); | ||
}); | ||
}); | ||
describe("bookmarkLink", () => { | ||
test("should return description and link", () => { | ||
expect( | ||
bookmarkLink( | ||
"26/09/2021 - 6pm", | ||
"Link label", | ||
"Link description", | ||
"https://www.testlink.com" | ||
) | ||
).toMatchSnapshot(); | ||
}); | ||
}); | ||
describe("addDescription", () => { | ||
test("should return description comment", () => { | ||
expect(addDescription("hello world")).toEqual("<!-- hello world -->"); | ||
}); | ||
test("should return empty string", () => { | ||
expect(addDescription("")).toEqual(""); | ||
}); | ||
}); | ||
describe("addBookwormsDescription", () => { | ||
test("should return description for file comment", () => { | ||
jest | ||
.spyOn(Date.prototype, "toLocaleString") | ||
.mockReturnValue("30/09/2021, 19:43:14"); | ||
expect(addBookwormsDescription(1633027394454)).toEqual( | ||
"<!-- These bookmarks were last updated on 30/09/2021, 19:43:14 using bookworms (https://github.com/thearegee/bookworms) -->" | ||
); | ||
}); | ||
}); | ||
}); |
@@ -0,1 +1,2 @@ | ||
import { jest } from "@jest/globals"; | ||
import { | ||
@@ -35,2 +36,3 @@ bookmark, | ||
}); | ||
describe("bookmarkFolder", () => { | ||
@@ -48,2 +50,3 @@ test("should return description, header and children", () => { | ||
}); | ||
describe("convertNumberIntoHeader", () => { | ||
@@ -73,2 +76,3 @@ test("should return h1 mardown", () => { | ||
}); | ||
describe("addTitle", () => { | ||
@@ -82,2 +86,3 @@ test("should return title comment", () => { | ||
}); | ||
describe("addDescription", () => { | ||
@@ -91,4 +96,8 @@ test("should return description comment", () => { | ||
}); | ||
describe("addBookwormsDescription", () => { | ||
test("should return description for file comment", () => { | ||
jest | ||
.spyOn(Date.prototype, "toLocaleString") | ||
.mockReturnValue("30/09/2021, 19:43:14"); | ||
expect(addBookwormsDescription(1633027394454)).toEqual( | ||
@@ -95,0 +104,0 @@ "_These bookmarks were last updated on 30/09/2021, 19:43:14 using [Bookworms](https://github.com/thearegee/bookworms)_" |
const bookmark = (timeDate, label, description, children) => { | ||
return ` | ||
${addTitle(label)} | ||
${addDescription(description)} | ||
${children} | ||
${addBookwormsDescription(timeDate)} | ||
`; | ||
const arr = []; | ||
arr.push(addTitle(label)); | ||
if (description) { | ||
arr.push(`\n${description}`); | ||
} | ||
arr.push(children); | ||
arr.push(addBookwormsDescription(timeDate)); | ||
return arr.join("\n"); | ||
}; | ||
const bookmarkFolder = (index, label, description, children) => { | ||
return ` | ||
${convertNumberIntoHeader(index, label)} | ||
${addDescription(description)} | ||
${children} | ||
`; | ||
const arr = ["\n"]; | ||
arr.push(convertNumberIntoHeader(index, label)); | ||
if (description) { | ||
arr.push(`\n${description}`); | ||
} | ||
arr.push(children); | ||
return arr.join("\n"); | ||
}; | ||
const convertNumberIntoHeader = (index, label) => { | ||
const arr = [""]; | ||
for (let i = 0; i <= index; i++) { | ||
arr.push("#"); | ||
} | ||
return `${arr.join("")} ${label}`; | ||
return `${"#".repeat(index + 1)} ${label}`; | ||
}; | ||
const bookmarkLink = (label, description, href) => { | ||
if (!href) { | ||
return ``; | ||
} | ||
return ` | ||
* [${label}](${href}) ${addDescription(description)} | ||
* [${label ? label : href}](${href}) ${addDescription(description)} | ||
`; | ||
@@ -30,0 +33,0 @@ }; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1418
292709
117