UNPKG

netscape-bookmark-export-converter

Version:

Converts Netscape Bookmark Format files used by popular web browsers to an array of objects containing individual bookmarks URI's and their respective folder tags.

38 lines (37 loc) 1.59 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.convert = void 0; /* eslint-disable no-console */ /* eslint-disable import/extensions */ /* eslint-disable import/no-unresolved */ const promises_1 = require("fs/promises"); const utilities_1 = require("./utilities"); /** * Converts Netscape Bookmark export file to an array of URIs and Tags * * @function * @public * @param fileName * @returns */ const convert = (fileName) => __awaiter(void 0, void 0, void 0, function* () { try { const fileData = yield (0, promises_1.readFile)(fileName, 'utf8'); const jsonData = (0, utilities_1.reduceToArray)([(0, utilities_1.sanitize)((0, utilities_1.useCheerioToConvertStringToJson)(fileData))].filter(utilities_1.noNull)); return jsonData; } catch (_error) { return []; } }); exports.convert = convert; exports.default = convert;