UNPKG

timezonecomplete

Version:

DateTime, TimeZone, Duration and Period library aimed at providing a consistent and complete date-time interface, away from the original JavaScript Date class.

62 lines 1.68 kB
"use strict"; /** * Copyright (c) 2019 ABB Switzerland Ltd. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.convertError = exports.errorIs = exports.error = exports.throwError = void 0; /** * Throws an error with the given name and message * @param name error name, without timezonecomplete prefix * @param message complete message * @param args arguments for the placeholders * @throws the given error */ function throwError(name, message) { var error = new Error(message); error.name = "timezonecomplete." + name; throw error; } exports.throwError = throwError; /** * Returns an error with the given name and message * @param name * @param message * @throws nothing */ function error(name, message) { var error = new Error(message); error.name = "timezonecomplete." + name; return error; } exports.error = error; /** * Returns true iff `error.name` is equal to or included by `name` * @param error * @param name string or array of strings * @throws nothing */ function errorIs(error, name) { if (typeof name === "string") { return error.name === "timezonecomplete." + name; } else { return error.name.startsWith("timezonecomplete.") && name.includes(error.name.substr("timezonecomplete.".length)); } } exports.errorIs = errorIs; /** * Converts all errors thrown by `cb` to the given error name * @param errorName * @param cb * @throws [errorName] */ function convertError(errorName, cb) { try { return cb(); } catch (e) { return throwError(errorName, e.message); } } exports.convertError = convertError; //# sourceMappingURL=error.js.map