mirror of
https://github.com/lucaspalomodevelop/JSSTE.git
synced 2026-03-12 23:17:22 +00:00
remove empty catch | add checker module
This commit is contained in:
parent
430831bde9
commit
ff32e74531
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "jsste",
|
||||
"version": "1.1.2",
|
||||
"version": "1.1.3",
|
||||
"description": "A Javascript Static Template Emgine",
|
||||
"main": "src/index.js",
|
||||
"directories": {
|
||||
|
||||
59
src/checker.js
Normal file
59
src/checker.js
Normal file
@ -0,0 +1,59 @@
|
||||
function isObject(obj) {
|
||||
return obj !== undefined && obj !== null && obj.constructor == Object;
|
||||
}
|
||||
function isArray(obj) {
|
||||
return obj !== undefined && obj !== null && obj.constructor == Array;
|
||||
}
|
||||
|
||||
function isBoolean(obj) {
|
||||
return obj !== undefined && obj !== null && obj.constructor == Boolean;
|
||||
}
|
||||
|
||||
function isFunction(obj) {
|
||||
return obj !== undefined && obj !== null && obj.constructor == Function;
|
||||
}
|
||||
|
||||
function isNumber(obj) {
|
||||
return obj !== undefined && obj !== null && obj.constructor == Number;
|
||||
}
|
||||
|
||||
function isString(obj) {
|
||||
return obj !== undefined && obj !== null && obj.constructor == String;
|
||||
}
|
||||
|
||||
function isInstanced(obj) {
|
||||
if (obj === undefined || obj === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isArray(obj)) {
|
||||
return false;
|
||||
}
|
||||
if (isBoolean(obj)) {
|
||||
return false;
|
||||
}
|
||||
if (isFunction(obj)) {
|
||||
return false;
|
||||
}
|
||||
if (isNumber(obj)) {
|
||||
return false;
|
||||
}
|
||||
if (isObject(obj)) {
|
||||
return false;
|
||||
}
|
||||
if (isString(obj)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
isObject: isObject,
|
||||
isArray: isArray,
|
||||
isBoolean: isBoolean,
|
||||
isFunction: isFunction,
|
||||
isNumber: isNumber,
|
||||
isString: isString,
|
||||
isInstanced: isInstanced,
|
||||
};
|
||||
@ -1,4 +1,5 @@
|
||||
const fs = require("fs");
|
||||
const checker = require("./checker")
|
||||
//const path = require("path");
|
||||
//let appdir = path.join(__dirname, "..");
|
||||
let app = {};
|
||||
@ -26,10 +27,8 @@ app.render = function (pagecode, templatecode) {
|
||||
//let result = "";
|
||||
|
||||
//if (!pagecode == JSON) pagecode = JSON.parse(pagecode);
|
||||
if (pagecode != null || pagecode != undefined) {
|
||||
try {
|
||||
if ((pagecode != null || pagecode != undefined) && checker.isString(pagecode)) {
|
||||
pagecode = JSON.parse(pagecode);
|
||||
} catch {}
|
||||
}
|
||||
|
||||
//TODO
|
||||
@ -54,7 +53,7 @@ app.render = function (pagecode, templatecode) {
|
||||
for (let i in pagecode) {
|
||||
let value = undefined;
|
||||
|
||||
if ( new RegExp(/\d*_([A-Z]|[a-z])\w*_/g).test(i)) continue;
|
||||
if (new RegExp(/\d*_([A-Z]|[a-z])\w*_/g).test(i)) continue;
|
||||
if (new RegExp(/js\$([A-Z]*[a-z]*)\w+/g).test(i)) {
|
||||
let SE = require("./scriptExecuter");
|
||||
pagecode[i] = SE(pagecode[i]);
|
||||
|
||||
@ -1,14 +1,13 @@
|
||||
const checker = require("./checker");
|
||||
|
||||
function mergeJson(org, ext) {
|
||||
// let placeholder = undefined;
|
||||
if (org !== JSON) {
|
||||
try {
|
||||
org = JSON.parse(org);
|
||||
} catch (error) {}
|
||||
|
||||
if (!checker.isObject(org)) {
|
||||
org = JSON.parse(org);
|
||||
}
|
||||
if (ext !== JSON) {
|
||||
try {
|
||||
ext = JSON.parse(ext);
|
||||
} catch (error) {}
|
||||
if (!checker.isObject(ext)) {
|
||||
ext = JSON.parse(ext);
|
||||
}
|
||||
|
||||
Object.keys(ext).forEach(function (key) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user