@bahatron/utils
v4.1.1
Published
The only utility library you'll ever need
Readme
Utils
npm install @bahatron/utilsA collection of utility functions and objects
Logger
Fast and simple event driven logger.
import { Logger } from "@bahatron/utils";
const logger = Logger.Create({
id: "myLogger",
pretty: false,
debug: true,
});
logger.on("error", async (entry) => {
// doSomething
});
logger.warning({ foo: "bar" }, "this is a warning");Helpers
Collection of highly useful helper functions
import { Helpers } from "@bahatron/utils";
const val = Helpers.getenv("MY_ENV_VAR", "aDefaultValue");
await Helpers.parallelize({
workers: 100,
queue: httpCallsToMake,
handler: async (item) => {
// doYourThing
},
});JsonSchema
The JsonSchema object provides a schema builder (based on TypeForm) plus a typecaster validator (jsonschema)
import { JsonSchema } from "@bahatron/utils";
const schema = JsonSchema.Object({
foo: JsonSchema.String(),
});
const myObject = JsonSchema.validate(
{
foo: "bar",
},
schema,
);
myObject.foo; // stringObservable
Runtime agnostic and typehinted implementation of node's EventEmitter class.
import { Observable } from "@bahatron/utils";
const observer = Observable<"foo" | "bar">();
observer.once("foo", doSomething);
observer.emit("foo");