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 🙏

© 2024 – Pkg Stats / Ryan Hefner

insulatejs

v1.2.1

Published

JS library to create constants and immutable objects/members/methods

Downloads

3

Readme

insulatejs v1.2.1

Library to create constants, immutable objects, including the parent objects, members and methods in javascript (constants polyfil for ecma5)

Created by Alex Becker [email protected].
also available on bower. bower install insulatejs, npm._ npm install insulatejs.

Simply immutable objects/proprties/methods/constants (incuding the parent objects!).

By running insulate.createObject() you can create an object in global namespace that can not be reset, redefined or in anyway messed with.

Further, you can add members and methods with insulate.createMember() and insulate.createMethod() that will not be vulnerable to any unwanted changes initiated by other scripts. By keeping your important functions immutable you can improve security
In fact, after you created an object with insulate and used insulate to add methods and members, they will all behave as constants, imitable! Every thing that you create with insulate can not be redefined! Insulate itself is created to be imitable by using it's createObject() method. It can not be redefined.

To use, include insulate.js script in head of your page.
To turn on error messages in console, use insulate.logErrors();, highly recommended to do so, when using for a first time. To turn error messages back off, insulate.muteErrors();

To create a global constant:
insulate.createConstant() will create a constant in a global namespace. Needs a name and optional value to set the constant

example  
insulate.createConstant("MYCONST", "hello world");   
Try to reset it  
MYCONST = 123;
console.log(MYCONST); //will still print out "hello world"! 

If you choose not to pass the second argument, you can set the constant later.

example
insulate.createConstant("MYCONST"); MYCONST = "hello world";   
Now MYCONST will always return "hello world".  
Try to reset it  
MYCONST = 123;
console.log(MYCONST); //will print out "hello world"!    

It is important not to declare your constants before you create them with insulate, if you do, before ruining insulate.createConstant(), insulate will ask you to pick a different name!

To create a constant in another scope, other than global, use insulate.createMember();

To create immutable objects:

insulate.createObject(); will create an object in global space or in any context, if supplied.
Needs a name and optionally context (an object).
All members and methods of this the top level object will be immutable, as long as you create
each of them with insulate library.
Nested objects can be passed with dotted notation - obj1.obj2.obj3 or as a named reference.

example 
insulate.createObject("myObj"); will create myObj in global namespace.   
This should be used as a starting point. 
Creating nested objects with insulate library will insure immutability.   
insulate.createObject("myObjInner", myObj); will create a myObjInner object    
as a myObj member. Can also be done with insulate.createMember();.  
Now try to reset either one:   
myObj = "I am trying to hack you";   
console.log(typeof myObj); //will print out an object!   
myObj.myObjInner = "I am trying to hack you";   
console.log(typeof myObj.myObjInner); //will still print out an object!  

To create immutable methods:

insulate.createMethod() will create a immutable method (if created in an object made with insulate utility) needs a name, object and an optional function.
Nested objects can be passed with dotted notation - obj1.obj2.obj3 or as a named reference

example
insulate.createObject("myObj"); // in case you have not created it before.
insulate.createMethod("hello", myObj, function(){console.log("hello world")});  
Let's try to reset it:  
myObj.hello = function(){console.log("i'm trying to hack you")};  
myObj.hello(); // will still print out "hello world"!

If you choose not to pass a function as the third argument, you can set the method later.

example
insulate.createObject("myObj"); // in case you have not created it before.
insulate.createMethod("hello", myObj);
myObj.hello = function(){console.log("hello world")};   
Let's try to reset it:  
myObj.hello = function(){console.log("i'm trying to hack you")};  
myObj.hello(); // will still print out "hello world"!

To create immutable members:

insulate.createMember() will create an imitable member in an object (created with insulate).
Needs a name, object and optional value.
Nested objects can be passed with dotted notaition - obj1.obj2.obj3 or as a named reference

example 
insulate.createObject("myObj"); // in case you have not created it before.
insulate.createMember("lirics", myObj, "lorem ipsum something, something");   
Let's try to reset it:  
myObj.lirics = "i'm trying to hack you";  
console.log(myObj.lirics); // will still print out "lorem ipsum something, something"!

if you choose not to pass any value as the third argument, you can set the member later

example
insulate.createObject("myObj");
insulate.createMember("lirics", myObj);
myObj.lirics = "lorem ipsum something, something";  
Let's try to reset it:  
myObj.lirics = "i'm trying to hack you";  
console.log(myObj.lirics); // will still print out "lorem ipsum something, something"!    


*(all modern browsers that support `Object.defineProperty()`).*    

Your feedback is quite welcome!
[email protected]