npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

henscript

v0.0.2

Published

a new way to javascript

Readme

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 = require('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

<script type="text/javascript" src="henscript/index.js"></script>

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 = require('henscript'), word = 'bar';
henscript.if( word == 'bar', 
	function() {
		console.log('test1');
	}
);

The overall function will return a ConditionResponse object which contains the functions elseif and else. see ConditionResponse

var henscript = require('henscript'), word = 'foo';
henscript.if( word == 'bar', 
	function() {
		console.log('test1');
	}
).elseif( word == 'foo',
	function() {
		console.log('test2');
	}
).else(function() {
	console.log('test3');
});

### 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 = require('henscript');
henscript.switch('y',{
	'h':console.log,
	'e':console.log,
	'n':console.log,
	'r':console.log,
	'y':function(value){
		console.log('Henr' + value + ' is the best.');
	}

}).else(function(){
	console.log('he is still pretty cool.');
});

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 = require('henscript'), foo = 5;
henscript.while(function(){
		return foo > 0;
	},
	function(){
		console.log(foo);
		foo--;
	}
).else(function(){
	console.log('the condition was not met initially');
});

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 = require('henscript'), foo = 10;
henscript.for(function(){
		return foo > 5;
	},
	function(){
		console.log(foo);
	},
	function(){
		foo--;
	}
);

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.map(function(element){
	return element + 'foo';
});

would result in

{
	'foobar':'barfoo',
	'barfoo':'foofoo'
}

Object.prototype.size()

Will return the number of fields in an object

var foo = {foo:"bar",barbar:"foofoo"};
console.log(foo.size()); // 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.log(a.equals(c)); // true
console.log(a.equals(b)); // false

a.equals(c,function(){
	// would be called, 3 is equal to 3
});

a.equals(b,function(){
	// wouldn't be called, 3 is not equal to 4
}).else(function(){
	// however this would be called
});

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.log(a.not_equal(c)) // true
console.log(a.not_equal(b)) // false

a.not_equal(c,function(){
	// would be called, 3 is not equal to 4
});

a.not_equal(b,function(){
	// wouldn't be called, 3 is equal to 3
}).else(function(){
	// however this would be called
});

Boolean functions

operators

  • Boolean.prototype.and(bool_2)
  • Boolean.prototype.or(bool_2)
  • Boolean.prototype.not(bool_2) or Boolean.prototype.bang(bool_2)

console.log(a.or(c)) // true console.log(a.or(b)) // true console.log(c.or(b)) // true

console.log(a.not()) // false console.log(b.not()) // true

### Boolean.prototype.condition([callback_true],[callback_false])
Similar to the [condition operator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators#Special_operators) 
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.
```js
var a = true, b = false;
a.condition(function(){
	// called since a is true
},function(){
	// not called
});

b.condition(function(){
	// not called since b is false
},function(){
	// called
});

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)

console.log(a.times(c)) // 15 console.log(a.over(b)) // 0.5

var d = a.plus(b).over(c); // d is now 5, (5 + 10) / 3

d = negate(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=])
<br>
Just as [Object.prototype.equals](#Object_equal) works just with 
[operators](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators#Comparison_operators) that apply to numbers
or quantities

```js
var a = 30, b = 50, c = 30;
a.greater_equal(c) // true
a.greater(c) // false

a.less(b,function(){
	// would be called
});

a.greater(b,function(){
	// would not be called a is not greater than b
}).else(function(){
	// would be called since the previous condition was not met
});

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 = new henscript.ConditionResponse(false);
condition.else(function(){
	// this would be called sinse the original condition
	// was false
});

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 = new henscript.ConditionResponse(false);
condition.elseif(true,function(){
	// this would be called sinse the original condition
	// was false and this one is true
});