Clean up core-js

This commit is contained in:
Paulo Gustavo Veiga 2021-12-02 21:43:05 -08:00
parent c2b94b8696
commit b57dcd6fd1
9 changed files with 60 additions and 88 deletions

View File

@ -2,9 +2,6 @@
"compilerOptions": {
"baseUrl": ".",
"module": "commonjs",
"paths": {
"@libraries/*": ["../../libraries/*"]
}
},
"exclude": ["node_modules"]
}

View File

@ -1,53 +0,0 @@
/*
Function: $defined
Returns true if the passed in value/object is defined, that means is not null or undefined.
Arguments:
obj - object to inspect
*/
export const $defined = function (obj) {
return obj != undefined;
};
export const $assert = function (assert, message) {
if (!$defined(assert) || !assert) {
logStackTrace();
console.log(message);
throw new Error(message);
}
};
export const sign = function (value) {
return value >= 0 ? 1 : -1;
};
export function logStackTrace(exception) {
if (!$defined(exception)) {
try {
throw Error('Unexpected Exception');
} catch (e) {
exception = e;
}
}
var result = '';
if (exception.stack) {
//Firefox and Chrome...
result = exception.stack;
} else if (window.opera && exception.message) {
//Opera
result = exception.message;
} else {
//IE and Safari
result = exception.sourceURL + ': ' + exception.line + '\n\n';
var currentFunction = arguments.callee.caller;
while (currentFunction) {
var fn = currentFunction.toString();
result = result + '\n' + fn;
currentFunction = currentFunction.caller;
}
}
window.errorStack = result;
return result;
}

View File

@ -1,18 +0,0 @@
import * as Functions from './Functions';
import * as Util from './Utils';
export const Function = Functions;
export const Utils = Util;
function coreJs() {
global.core = {
Function,
Utils
};
Math.sign = Function.sign;
global.$assert = Function.$assert;
global.$defined = Function.$defined;
return global.core;
}
export default coreJs;

View File

@ -52,3 +52,57 @@ export const createDocument = function () {
return doc;
};
/*
Function: $defined
Returns true if the passed in value/object is defined, that means is not null or undefined.
Arguments:
obj - object to inspect
*/
export const $defined = function (obj) {
return obj != undefined;
};
export const $assert = function (assert, message) {
if (!$defined(assert) || !assert) {
logStackTrace();
console.log(message);
throw new Error(message);
}
};
export const sign = function (value) {
return value >= 0 ? 1 : -1;
};
export function logStackTrace(exception) {
if (!$defined(exception)) {
try {
throw Error('Unexpected Exception');
} catch (e) {
exception = e;
}
}
var result = '';
if (exception.stack) {
//Firefox and Chrome...
result = exception.stack;
} else if (window.opera && exception.message) {
//Opera
result = exception.message;
} else {
//IE and Safari
result = exception.sourceURL + ': ' + exception.line + '\n\n';
var currentFunction = arguments.callee.caller;
while (currentFunction) {
var fn = currentFunction.toString();
result = result + '\n' + fn;
currentFunction = currentFunction.caller;
}
}
window.errorStack = result;
return result;
}

View File

@ -2,7 +2,6 @@ const path = require('path');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
module.exports = {
entry: './src/core.js',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'core.js',
@ -19,16 +18,11 @@ module.exports = {
test: /.js$/,
exclude: [
/node_modules/,
path.resolve(__dirname, '../../libraries/mootools-core-1.4.5'),
path.resolve(__dirname, '../../libraries/underscore-min'),
]
},
],
},
resolve: {
alias: {
'@libraries': path.resolve(__dirname, '../../libraries/'),
},
extensions: ['.js'],
},
plugins: [new CleanWebpackPlugin()],

View File

@ -21,11 +21,7 @@ import TransformUtil from './peer/utils/TransformUtils';
class Font {
constructor(fontFamily, textPeer) {
// eslint-disable-next-line no-unused-vars
const tools = Toolkit; // Used as of the defined object.
const font = `tools.create${fontFamily}Font();`;
// eslint-disable-next-line no-eval
this.peer = eval(font);
this.peer = Toolkit[`create${fontFamily}Font`]();
this._textPeer = textPeer;
}

View File

@ -48,7 +48,8 @@ class Rect extends ElementClass {
super(peer, defaultAttributes);
}
static getType() {
// eslint-disable-next-line class-methods-use-this
getType() {
return 'Rect';
}

View File

@ -27,7 +27,8 @@ class Text extends ElementClass {
super(peer, attributes);
}
static getType() {
// eslint-disable-next-line class-methods-use-this
getType() {
return 'Text';
}

View File

@ -75,7 +75,7 @@ class Toolkit {
return new RectPeer(arc);
}
static reateArialFont() {
static createArialFont() {
return new ArialFont();
}