element-ts

A suite of developer tools written in TypeScript.

hydrogen

Hydrogen is a jack of all trades for managing APIs. You can get a big project off the ground quickly with its ease of use and vast functionality.


import {HEndpointGroup,
		HHTTPServer,
		HRequest,
		HResponse,
		StandardType
} from "@element-ts/hydrogen";

const rootEndpoint: HEndpointGroup = new HEndpointGroup();
const userEndpoint: HEndpointGroup = new HEndpointGroup();

userEndpoint.post("/sign-up", {
    handler: async(req: HRequest, res: HResponse): Promise => {

	    const body: {name: string, age: number} = req.getBody();
	    res.send({id: "xxx", name: body.name});

    },
    types: {
	    name: StandardType.STRING,
	    age: StandardType.NUMBER
    }
});

rootEndpoint.get("/hello", async(req: HRequest, res: HResponse) => {
    res.sendFile("/path-to-file");
});

rootEndpoint.attach("/user", userEndpoint);

new HHTTPServer(rootEndpoint).start(3000);
			

silicon

Silicon is a MongoDB driver. It wraps the official driver provided by MongoDB found here on NPM. Silicon simplifies many processes by providing a type-safe object-oriented wrapper of the MongoDB driver. Also included in silicon is a powerful type-safe query driver.


import {SiObject} from "@element-ts/silicon";

interface UserProps { name: string; age: number; }
class User extends SiObject {

    public constructor() { super("table-name"); }

}

const user: User = new User();
user.props.name = "Elijah";
user.props.age = 21;

await user.create();
await user.update();
await user.update("name");
await user.fetch();
await user.delete();
			

krypton

A very light weight package written in Typescript combining node/crypto and bcrypt for some helpful methods.


import {
    KrBcrypt,
    KrHash,
    KrHashAlgorithm,
    KrRSA,
    KrRSAKeyPair
} from "element-ts/krypton";

// KrBcrypt
const password: string = "1234";
const createdPassword: Buffer = await KrBcrypt.createPassword(password);
const checkPassword: boolean = await KrBcrypt.verifyPassword(
    password,
    createdPassword
);

// KrHash
const hashedData: Buffer = KrHash.hash(Buffer.from("Hello, world!");
const hashedData: Buffer = KrHash.hash(Buffer.from(
    "Hello, world!",
    KrHashAlgorithm.sha512
));
const hasher: KrHash = new KrHash()
hasher.append(Buffer.from("Hello"));
hasher.append(Buffer.from("World"));
const hashedData: Buffer = hasher.hash();

// KrCipher
const cipher: KrCipher = new KrCipher(Buffer.from("password"));
const msg: Buffer = Buffer.from("Hello, world!");
const encryptedData: Buffer = cipher.encrypt(msg);
const decryptedData: Buffer = cipher.decrypt(encryptedData);
console.log(msg === decryptedData);

// KrRSA
const keys: KrRSAKeyPair = KrRSA.generateKeys();
const message: string = "Hello, world!";
const dataUnEncrypted: Buffer = Buffer.from(message);
const dataEncrypted: Buffer = KrRSA.encrypt(
    dataUnEncrypted,
    keys.publicKey
);
const dataDecrypted: Buffer = KrRSA.decrypt(
    dataEncrypted,
    keys.privateKey
);
const messageDecrypted: string = dataDecrypted.toString("utf8");
			

lithium

A type-safe remote function invocation library using websockets and TypeScript.


import {
    LiCommandRegistryStructure,
    LiSocket,
    LiServer
} from "@element-ts/lithium";

export interface MyServerCommands extends LiCommandRegistryStructure {
    changeFavoriteNumber: {
    	param: number;
        return: void;
    };
    getFavoriteColor: {
        param: void;
        return: number;
    };
}

export interface MyClientCommands extends LiCommandRegistryStructure {
    favoriteNumberChanged: {
        param: number;
        return: void;
    };
}

// Client Side
const server: LiServer = new LiServer({
    port: 8080,
    debug: true
});

let favoriteNumber: number = 42;

server.implement("getFavoriteColor", async(): Promise => {
    return favoriteNumber;
});

server.implement("changeFavoriteNumber", async(num: number): Promise => {
    favoriteNumber = num;
    await server.broadcast("favoriteNumberChanged", favoriteNumber);
});

// Client Side
const socket: LiSocket = await LiSocket.init({
    address: "ws://localhost:8080",
    debug: true
});

socket.implement("favoriteNumberChanged", async(num: number): Promise => {
    console.log(`Favorite number is now: ${num}!`);
    await socket.invoke("changeFavoriteNumber", num + 1);
});

await socket.invoke("changeFavoriteNumber", 0);
			

palladium

A type-safe promise based http/s request library.


import {
    PdRequest,
    PdResponse,
    PdMethod
} from "@element-ts/palladium";

const req: PdRequest = new PdRequest();
req.setUrl("https://myapi.com/users");
req.setMethod(PdMethod.Get);

const res: PdResponse = await req.request();
const obj: object | undefined = res.getJSON();
const status: number = res.statusCode;
			

neon

Neon is a simple package the provides really helpful logging. With even just the default options, Neon makes console.log() look like a smudge on a rock. It provides the type of the logged value, the stack it came from, and prints using the colors package.


import {Neon} from "@element-ts/neon";

Neon.enable();

Neon.setTitle("MyLogger");
Neon.log("Hello from MyLogger.");
Neon.clearTitle();
Neon.log("Hello, world!");
Neon.log(1223456789);
Neon.log(true);
Neon.log({foo: "bar"});
Neon.log([1, 2, 3]);
Neon.log(Buffer.from("Hello, world!"));

Neon.err("AHHHH!");
Neon.err(new Error("WHOA WHOA!"));
Neon.err("AHHHH!", true);