Skip to content

Commit

Permalink
null is an object, but is a primitive type.
Browse files Browse the repository at this point in the history
So, every time I typeof == 'object', I should also check != null
  • Loading branch information
StefanoBalocco committed Jan 29, 2022
1 parent 5fbe440 commit a5fb256
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 36 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ The first that exists and is not false, is the used as result of the path expres

If the path expression supports booleans, you can prepend [!] to a path.

If the path expression supports strings, you can append, as last path, STRING:this is a string {and/you/can/have/paths/too}! {?this/path/is/true} showed only if the condition is true{?this/path/is/true}{?!this/is/false} visible only unless is true{?!this/is/false}
If the path expression supports strings, you can append, as last path

STRING:this is a string {and/you/can/have/paths/too}! {?this/path/is/true} showed only if the condition is true{?this/path/is/true}{?!this/is/false} visible only unless is true{?!this/is/false}

In a boolean check, empty lists or empty string will be considered "false".

Expand Down
32 changes: 14 additions & 18 deletions jTDAL.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,36 +97,36 @@ var jTDAL;
case 'GLOBAL': {
if (1 < path.length) {
const countSecondLevel = path.length;
returnValue += (boolPath ? (not ? '!(' : '(') : '') + '"object"===typeof (t[i]=d)';
returnValue += (boolPath ? (not ? '!(' : '(') : '') + '"object"===typeof(t[i]=d)&&null!==t[i]';
for (let indexSecondLevel = 1; indexSecondLevel < countSecondLevel; ++indexSecondLevel) {
returnValue += '&&';
let lastPath = 't[i]["' + path[indexSecondLevel] + '"]';
returnValue += '"undefined"!==typeof ';
returnValue += '"undefined"!==typeof';
returnValue += '(t[i]=("function"===typeof ' + lastPath + '?' + lastPath + '(r,d)):' + lastPath + ')';
}
returnValue += (boolPath ? '?"object"===typeof t[i]?0<Object.keys(t[i]).length:(Array.isArray(t[i])?0<t[i].length:false!==t[i]&&null!==t[i]):false)?true' : '?t[i]') + ':';
returnValue += (boolPath ? '?"object"===typeof t[i]?null!==t[i]&&0<Object.keys(t[i]).length:(Array.isArray(t[i])?0<t[i].length:false!==t[i]):false)?true' : '?t[i]') + ':';
}
break;
}
default: {
const countSecondLevel = path.length;
openedBracket++;
returnValue += '(' + (boolPath ? (not ? '!' : '') + '(' : '') + '"object"===typeof (t[i]=r)';
returnValue += '(' + (boolPath ? (not ? '!' : '') + '(' : '') + '"object"===typeof(t[i]=r)&&null!==t[i]';
for (let indexSecondLevel = 0; indexSecondLevel < countSecondLevel; ++indexSecondLevel) {
returnValue += '&&';
let lastPath = 't[i]["' + path[indexSecondLevel] + '"]';
returnValue += '"undefined"!==typeof ';
returnValue += '"undefined"!==typeof';
returnValue += '(t[i]=("function"===typeof ' + lastPath + '?' + lastPath + '(d,r):' + lastPath + '))';
}
returnValue += (boolPath ? '?"object"===typeof t[i]?0<Object.keys(t[i]).length:(Array.isArray(t[i])?0<t[i].length:false!==t[i]&&null!==t[i]):false)' + (not ? '&&' : '||') : '?t[i]:');
returnValue += (boolPath ? (not ? '!' : '') + '(' : '') + '"object"===typeof (t[i]=d)';
returnValue += (boolPath ? '?"object"===typeof t[i]?null!==t[i]&&0<Object.keys(t[i]).length:(Array.isArray(t[i])?0<t[i].length:false!==t[i]):false)' + (not ? '&&' : '||') : '?t[i]:');
returnValue += (boolPath ? (not ? '!' : '') + '(' : '') + '"object"===typeof(t[i]=d)&&null!==t[i]';
for (let indexSecondLevel = 0; indexSecondLevel < countSecondLevel; ++indexSecondLevel) {
returnValue += '&&';
let lastPath = 't[i]["' + path[indexSecondLevel] + '"]';
returnValue += '"undefined"!==typeof ';
returnValue += '"undefined"!==typeof';
returnValue += '(t[i]=("function"===typeof ' + lastPath + '?' + lastPath + '(d,r):' + lastPath + '))';
}
returnValue += (boolPath ? '?"object"===typeof t[i]?0<Object.keys(t[i]).length:(Array.isArray(t[i])?0<t[i].length:false!==t[i]&&null!==t[i]):false)?true' : '?t[i]') + ':';
returnValue += (boolPath ? '?"object"===typeof t[i]?null!==t[i]&&0<Object.keys(t[i]).length:(Array.isArray(t[i])?0<t[i].length:false!==t[i]):false)?true' : '?t[i]') + ':';
}
}
}
Expand Down Expand Up @@ -203,7 +203,7 @@ var jTDAL;
current[0] += '+(';
current[0] += 'false!==(t[i++]=' + tmpValue + ')&&';
current[0] += '(!Array.isArray(t[--i])||(t[i]=Object.assign({},t[i])))&&';
current[0] += '("object"===typeof t[i]&&0<Object.keys(t[i++]).length)&&(t[i++]=1)';
current[0] += '("object"===typeof t[i]&&null!==t[i]&&0<Object.keys(t[i++]).length)&&(t[i++]=1)';
current[0] += '?';
current[0] += 'Object.keys(t[i-2]).reduce(function(o,e){';
current[0] += 'r["' + tmpTDALrules[1] + '"]=t[i-2][e];';
Expand Down Expand Up @@ -264,16 +264,12 @@ var jTDAL;
}
else if ('true' !== tmpValue) {
current[2] += '+(false!==(t[i++]=' + tmpValue + ')&&("string"===typeof t[--i]||("number"===typeof t[i]&&!isNaN(t[i])))?" ' + tmpTDALrules[1] +
'=\\""+t[i]+"\\"":(true!==t[i]?"":"';
'=\\""+t[i]+"\\"":(true!==t[i]?"":"' + tmpTDALrules[1] + '"';
if ('undefined' !== (typeof attributes[tmpTDALrules[1]])) {
current[1] = current[1].replace(new RegExp('\\s*' + tmpTDALrules[1] + '(?:=([\'"]).*?\\1)?'), '');
current[2] += tmpTDALrules[1] + '"' +
((('undefined' !== (typeof attributes[tmpTDALrules[1]][3])) && ('' != attributes[tmpTDALrules[1]][3])) ? '+"="+' +
JSON.stringify(String(attributes[tmpTDALrules[1]][2] + attributes[tmpTDALrules[1]][3] +
attributes[tmpTDALrules[1]][2])) : "");
}
else {
current[2] += '"';
current[2] += ((('undefined' !== (typeof attributes[tmpTDALrules[1]][3])) && ('' != attributes[tmpTDALrules[1]][3])) ? '+"="+' +
JSON.stringify(String(attributes[tmpTDALrules[1]][2] + attributes[tmpTDALrules[1]][3] +
attributes[tmpTDALrules[1]][2])) : "");
}
current[2] += '))';
}
Expand Down
Loading

0 comments on commit a5fb256

Please sign in to comment.