Henscript
It's finally here, sort of
What is it? you may ask, I too ask that question. But the real question is how can I make Javascript better, or worse. I present to you Henscript, defining a new way of using those things we use everyday.
Use it
nodejs
install it via npm npm install henscript
To use it just require the module. It will return an object that holds all sorts of new functions
as well as modify some already existant objects.
var henscript = ;
browser
Just download the index.js file and import it as a js file, there will be a object called henscript floating around your global namespace
Table of Contents
henscript functions
Object functions
Boolean functions
Number functions
ConditionResponse functions
henscript functions
henscript.if(condition,[callback])
When given a boolean that is true the callback is called
var henscript = word = 'bar';henscript;
The overall function will return a ConditionResponse object which contains the functions elseif and else. see ConditionResponse
var henscript = word = 'foo';henscript;
henscript.switch(to_be_tested,[matches])
Will test a given value to all the matches, upon finding the match it will call the corresponding callback. It also will return a ConditionResponse object see ConditionResponse
var henscript = ;henscript;
henscript.while([condition_callback],[update])
While the condition_callback returns true the update call back will be called, this also will return a ConditionResponse see ConditionResponse.
var henscript = foo = 5;henscript;
henscript.for([condition_callback],[update],[modify_callback])
Very similar to henscript.while except with an extra callback for modifying any variable variable that needs to be. It's not super practical.
var henscript = foo = 10;henscript;
Object functions
Object.prototype.map([callback])
Much like Array.prototype.map but for objects, you can go through each field and apply logic to determine the outcome object's properties.
var foo = foobar:'bar'barfoo:'foo';var output = foo;
would result in
Object.prototype.size()
Will return the number of fields in an object
var foo = foo:"bar"barbar:"foofoo";console; // 2
Object.prototype.equal(obj_b,[callback=]) or Object.prototype.equals(obj_b,[callback=])
Will test whether the given object (obj_b) is equal to the current object, when called without the callback parameter it will return a plain boolean, however when passed a callback it will call it if the two are equal and in turn return a ConditionResponse to which you could tag an else.
var a = 3 b = 4 c = 3; console; // trueconsole; // false a; a;
Object.prototype.not_equal(obj_b,[callback=])
Very similar to above Object.prototype.equal just tests whether the two are not equal and follows the same rules
var a = 3 b = 3 c = 4; console // trueconsole // false a; a;
Boolean functions
operators
- Boolean.prototype.and(bool_2)
- Boolean.prototype.or(bool_2)
- Boolean.prototype.not(bool_2) or Boolean.prototype.bang(bool_2)
If you are not familiar with these checkout this. Each will return the resulting boolean which will allow for chaining these operators.
var a = true b = false c = true;console // trueconsole // false console // trueconsole // trueconsole // true console // falseconsole // true
Boolean.prototype.condition([callback_true],[callback_false])
Similar to the condition operator but I think this version is alot more readable. It allows for the corresponding callback to be called based on whether or not the boolean is true.
var a = true b = false;a; b;
Number functions
Arithmetic operators
- Number.prototype.add(num_2) or Number.prototype.plus(num_2)
- Number.prototype.subtract(num_2) or Number.prototype.minus(num_2)
- Number.prototype.multiply(num_2) or Number.prototype.times(num_2)
- Number.prototype.divide(num_2) or Number.prototype.over(num_2);
- Number.prototype.modulus(num_2) or Number.prototype.mod(num_2)
- Number.prototype.power(num_2)
- Number.prototype.squared(num_2)
- Number.prototype.negate(num_2)
Pretty well known things, however here's a resource, just your basic math operators, you may notice there are no operators that do assignment like+=
where it will add then assign the value back to the caller.
var a = 5b = 10c = 3;console // 15console // 2 console // 15console // 0.5 var d = a;// d is now 5, (5 + 10) / 3 d = ; // d is now -5
Comparison Operators
- Number.prototype.greater(num_2,[callback=])
- Number.prototype.greater_equal(num_2,[callback=])
- Number.prototype.less(num_2,[callback=])
- Number.prototype.less_equal(num_2,[callback=])
Just as Object.prototype.equals works just with operators that apply to numbers or quantities
var a = 30 b = 50 c = 30;a // truea // false a; a;
ConditionResponse functions
condition.else(condition,[callback])
when the previous operation that returned this ConditionResponse resulted in a false then the callback will be called
var condition = false;condition;
condition.elseif(condition,[callback])
when the given condition is true and the previous operation that returned this ConditionResponse resulted in a false then the callback will be called.
var condition = false;condition;