native-fn
Version:
141 lines (135 loc) • 3.94 kB
JavaScript
var version = "1.0.85";
var packageJSON = {
version: version};
function assign() {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
var to = Object(args[0]);
for (var i = 1; i < args.length; i++) {
var src = args[i];
if (src == null)
continue;
for (var key in src) {
if (!Object.prototype.hasOwnProperty.call(src, key) || key === '__proto__' || key === 'constructor' || key === 'prototype')
continue;
to[key] = src[key];
}
}
return to;
}
function createCustomError(name, Base) {
if (Base === void 0) { Base = Error; }
function CustomError(message) {
if (!(this instanceof CustomError))
return new CustomError(message);
var error = new Base(message || '');
if (typeof Object.setPrototypeOf === 'function')
Object.setPrototypeOf(error, CustomError.prototype);
else
error.__proto__ = CustomError.prototype;
error.name = name;
if (typeof message !== 'undefined')
error.message = message;
if (typeof Symbol !== 'undefined' && Symbol.toStringTag) {
try {
Object.defineProperty(error, Symbol.toStringTag, {
value: name,
writable: false,
enumerable: false,
configurable: true
});
}
catch (_) {
}
}
if (typeof Error.captureStackTrace === 'function') {
Error.captureStackTrace(error, CustomError);
}
else if (Base.captureStackTrace && typeof Base.captureStackTrace === 'function') {
Base.captureStackTrace(error, CustomError);
}
else {
try {
var tempError = new Base();
if (tempError.stack)
error.stack = tempError.stack;
}
catch (_) {
}
}
return error;
}
CustomError.prototype = Object.create(Base.prototype, {
constructor: {
value: CustomError,
writable: true,
enumerable: false,
configurable: true
}
});
try {
Object.defineProperty(CustomError.prototype, 'name', {
value: name,
writable: true,
enumerable: false,
configurable: true
});
}
catch (_) {
try {
CustomError.prototype.name = name;
}
catch (_) {
}
}
try {
Object.defineProperty(CustomError, 'name', {
value: name,
writable: false,
enumerable: false,
configurable: true
});
}
catch (_) {
}
return CustomError;
}
var PluginNotExtendedError = createCustomError('PluginNotExtendedError');
(function () {
if (typeof globalThis === 'object')
return;
Object.defineProperty(Object.prototype, '__getGlobalThis__', {
get: function () { return this; },
configurable: true
});
try {
var global = __getGlobalThis__;
Object.defineProperty(global, 'globalThis', {
value: global,
writable: true,
configurable: true
});
}
finally {
delete Object.prototype.__getGlobalThis__;
}
}());
var Native = {
Version: packageJSON.version,
Constants: {},
Errors: {
PluginNotExtendedError: PluginNotExtendedError
},
extends: function (plugin) {
if (plugin.installed)
return this;
this.Constants = assign(this.Constants, plugin.Constants);
this.Errors = assign(this.Errors, plugin.Errors);
this[plugin.name] = plugin.module;
plugin.installed = true;
return this;
}
};
export { Native as default };