HotTea (new ver) Alpha0.1 released now!
Tags: javascript, webdev, watercooler, typescript
Published: 2020-12-31 09:13:37

###[HotTea GitHub repo](https://github.com/CalinZBaenen/HotTea).

#<b>What is HotTea?</b>
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](https://github.com/CalinZBaenen/HotTeaLegacy).
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).
<br/>

#<b>What does HotTea currently have/support?</b>
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).
<br/>
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:
```javascript
// 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.
<br/>
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:
```javascript

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

```
<br/>

#<b>That's all.</b>
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.

<div alt="Thanks! Cheers!">
##<b><center><b>Thanks for reading!<br/>Cheers!</b></center></b>
</div>