@s-hiroshi/bks
Version:
Cli bookmarks application
35 lines • 1.1 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseBookmark = void 0;
const fs = require("fs");
const readline = require("readline");
/**
*
* @param filePath
* @returns
*/
async function parseBookmark(filePath) {
// @see https://blog.katsubemakito.net/nodejs/file-read
const stream = fs.createReadStream(filePath, {
encoding: "utf8",
highWaterMark: 1024
});
const reader = readline.createInterface({ input: stream, crlfDelay: Infinity });
// const items: Item;
const items = [];
for await (const line of reader) {
const matchecKeyword = line.match(/<a[^>]+>(?<keyword>[^<]+)<\/a>/i);
const matchedContent = line.match(/href="(?<content>[^"]+)"/i);
if (matchecKeyword && matchedContent) {
const item = {
keyword: matchecKeyword.groups.keyword,
content: matchedContent.groups.content
};
items.push(item);
}
}
;
return items;
}
exports.parseBookmark = parseBookmark;
//# sourceMappingURL=parseBookmarks.js.map