@bahatron/utils
TypeScript icon, indicating that this package has built-in type declarations

4.1.0 • Public • Published

Utils

npm install @bahatron/utils

A collection of utility functions and objects

Logger

Fast and simple event driven logger.

import { Logger } from "@bahatron/utils";

const logger = Logger.Logger({
	id: "myLogger",
	pretty: false,
	debug: true
})

logger.on("error", async (entry) => {
	// doSomething
})

logger.warning({foo: "bar", "this is a warning")

Helpers

getenv

get env will throw an exception if MY_ENV_VAR is not set and there's no default value. This is good for failing fast

import { Helpers } from "@bahatron/utils";

let val = Helpers.getenv("MY_ENV_VAR", "aDefaultValue");

parallelize

Parallelize the work of a queue of item around a number of workers. This is done through promises on the main thread rather than using child processes Great for funnelling http calls

let httpCallsToMake = [...]

await parallelize({
	workers: 100,
	queue: httpCallsToMake,
	handler: async (item) => {
		// doYourThing
	}
})

Validator

import { Validator } from "@bahatron/utils";

let errors = Validator.json(MyObject, MyJsonSchema);

let maybeString = Validator.optionalString(null); // undefined

let maybeInt = Validator.optionalInt("12"); // 12

let maybeInt = Validator.optionalInt("abc"); // undefined

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
4.1.06latest

Version History

VersionDownloads (Last 7 Days)Published
4.1.06
4.0.219
4.0.112
4.0.01
3.7.465
3.7.30
3.7.20
3.7.10
3.7.00
3.6.120
3.6.110
3.6.1083
3.6.90
3.6.81
3.6.70
3.6.60
3.6.50
3.6.40
3.6.30
3.6.20
3.6.10
3.6.01
3.5.160
3.5.150
3.5.140
3.5.130
3.5.120
3.5.110
3.5.100
3.5.90
3.5.80
3.5.70
3.5.60
3.5.50
3.5.40
3.5.30
3.5.21
3.5.10
3.5.00
3.4.50
3.4.41
3.4.30
3.4.20
3.4.10
3.4.00
3.3.00
3.2.90
3.2.80
3.2.70
3.2.60
3.2.50
3.2.40
3.2.30
3.2.20
3.2.10
3.2.00
3.1.50
3.1.40
3.1.31
3.1.20
3.1.10
3.1.00
3.0.10
3.0.00
2.5.10
2.5.00
2.4.00
2.3.10
2.3.00
2.2.00
2.1.10
2.1.00
2.0.50
2.0.40
2.0.30
2.0.20
2.0.10
2.0.00
1.1.20
1.1.10
1.1.00
1.0.20
1.0.10
1.0.00
0.3.70
0.3.60
0.3.51
0.3.41
0.3.30
0.3.21
0.3.10
0.3.00
0.2.00
0.1.10
0.1.00

Package Sidebar

Install

npm i @bahatron/utils

Weekly Downloads

194

Version

4.1.0

License

Apache-2.0

Unpacked Size

108 kB

Total Files

67

Last publish

Collaborators

  • bahatron