/***
* my tests
*/
//object
//var myObj = {};
//console.log(myObj.toString());
/***
* library code below
*/
(function(root){
console.log('root:');
console.log(root);
//properties
var whiteRe = /\s*/; //check for whitespace
var spaceRe = /\s+/; //check for space
var nonSpaceRe = /\S/; //check for non-whitespace
var eqRe = /\s*=/;
var curlyRe = /\s*\}/; //check for culry
var tagRe = /#|\^|\/|>|\{|&|=|!/; //check for special characters
//use JS RegExp Obj to define internal regex test method
var RegExp_test = RegExp.prototype.test;
function testRegExp(re, string) {
return RegExp_test.call(re, string);
}
//test for whitespace
function isWhitespace(string) {
return !testRegExp(nonSpaceRe, string);
}
//test for array using native .isArray or use JS Obj.toString to test
var Object_toString = Object.prototype.toString;
var isArray = Array.isArray || function (obj) {
return Object_toString.call(obj) === '[object Array]';
};
//make HTML safe with escape characters
var entityMap = {
"&": "&",
"<": "<",
">": ">",
'"': '"',
"'": ''',
"/": '/'
};
function escapeHtml(string) {
return String(string).replace(/[&<>"'\/]/g, function (s) {
return entityMap[s];
});
}
//test escapeHtml
//console.log(escapeHtml('<h1>Hello ! & >< Worl/d</h1>'));
//---------------
//Scanner Obj
//---------------
//constructor
function Scanner(string) {
this.string = string;
this.tail = string;
this.pos = 0;
}
//Returns `true` if the tail is empty (end of string).
Scanner.prototype.eos = function () {
return this.tail === "";
};
//~ eos test
//var scanned = new Scanner('this is my cool test string');
//console.log(scanned.eos());
// Tries to match the given regular expression at the current position.
// Returns the matched text if it can match, the empty string...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.