@gmod/nclist
Version:
Read features from JBrowse 1 format nested containment list JSON
30 lines • 1.02 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.readJSON = readJSON;
exports.newURL = newURL;
//@ts-nocheck
const resolve_uri_1 = __importDefault(require("@jridgewell/resolve-uri"));
async function readJSON(url, readFile, options = {}) {
const { defaultContent = {} } = options;
try {
const str = await readFile(url, { encoding: 'utf8' });
const decoder = new TextDecoder('utf8');
return JSON.parse(decoder.decode(str));
}
catch (error) {
if (error.code === 'ENOENT' ||
error.status === 404 ||
error.message.includes('404') ||
error.message.includes('ENOENT')) {
return defaultContent;
}
throw error;
}
}
function newURL(arg, base = '.') {
return (0, resolve_uri_1.default)(arg, base);
}
//# sourceMappingURL=util.js.map