HotTea GitHub repo.
What is HotTea?
HotTea is meant to be a library to (kind of) replace Typescript.
The idea is that, since browsers don't natively support TS (i.e. <script language="typescript" type="application/typescript" src="project.ts"></script
), this library creates some useful fill-in features, that Javascript itself doesn't define.
The idea actually starter as a smaller, less ambitious goal; make REAL classes in JS. Here's the original project.
Now, with my plans, I plan on adding more, since I'm also adding a typing system via TypedObject
(a feature that will be discussed).
What does HotTea currently have/support?
Sadly, HotTea doesn't currently support REAL classes, as I eventually strive to add. Though, it has its concrete foundation created. A lot of the lib can (and possibly will) depend on the foundation defined in this version (even if there are only 3 (seemingly) very simple features).
So, what does it have?
First, it has TypedObject
s, something that work similar to a HashMap<KT, VT>
in Java.
TypedObject
s work like this:
// Keep in mind, TypedObject returns a proxy,
// as it isn't its own class.
const john = new TypedObject({
"name": String,
"age": Number
}, false);
john.name; // null
john.name = "John Egbert";
john.age; // null
john.age = "13"; // TypeError: type String(primitive) does not match type Number
john.age = new Number(13);
john.creator; // ReferenceError: key 'creator' does not exist
john.creator = "Andrew Hussie"; // ReferenceError: key 'creator' does not exist
// Might create a class called AssignmentError just for this message (idk yet).
const dave = new TypedObject({
"name": String,
"age": Number
});
dave.name; // null
dave.name = "Dave Strider"; // TypeError: String(primitive) does not match type String
dave.name = new String("Dave Strider");
dave.age = new Number(13);
Now, you'll notice a few things.
One, all properties start off as null
. This is deliberate, to allow all properties to be null
, since they are considered objects (and undefined
is treated as void (therefore unusable)).
Why? Because the point isn't to be 100% correct, it's to be predictable (which is the purpose of typing in my vision (though I have 20/200 vision, so I'm probably wrong)).
And I think this will really help, especially if you're expecting a specific result.
The last two features are smaller, but they do play a role, and are even used within TypedObject
. isprimitive
, and isprimitive.of
.
isprimitive
tests to see if a value is a primitive one (i.e. not typeof "object
", nor an instance of an object)/
isprimitive.of
works on a similar principle, except it checks to see if the value is the primitive of the class.
Here's an example:
isprimitive("test"); // true
isprimitive(new String("test")); // false
isprimitive(undefined); // true
isprimitive(null); // false
isprimitive({}); // false
isprimitive(function() {}); // false
isprimitive.of(new String("test"), String); // false
isprimitive.of(new String("test"), String, false); // true
isprimitive.of("test", String); // true
isprimitive.of("test", Number); // false
isprimitive.of("test", Number, false); // false
That's all.
I hope you liked what you see, and consider giving HotTea a try, I've worked quite a bit on it, and appreciate to see some community feedback.
Thanks for reading!
Cheers!
Cheers!
Top comments (0)