A lightweight TypeScript utility library that makes JavaScript/TypeScript code easier to read and validate. Provides clean, type-safe helpers for condition checking, string validation, and array transformations.
- Condition Class – Create expressive, reusable validation conditions with clear pass/fail semantics and optional timestamps
- String Validators – Chainable string checks (JSON validation, empty, length, numeric, case-sensitive, regex matching)
- Array Utilities – Convert arrays to JSON strings, Sets, or unique arrays
- Type Safety – Fully typed with TypeScript for IDE autocomplete and error prevention
- Zero Dependencies – Pure TypeScript, no external dependencies required
npm install @beautify-lang/js
# or
pnpm add @beautify-lang/js
# or
yarn add @beautify-lang/jsCreate reusable conditions that validate expected outputs with clear logging:
import { Condition } from '@beautify-lang/js';
const isEven = new Condition(
() => 42 % 2,
0,
'Number is even'
);
if (isEven.passes()) {
console.log('Condition passed!');
} else {
// Logs: [@beautify-lang/js at 2026-09-27 12:00:00]: Condition "Number is even" failed. Given Callback returned 0, expected output was 0
}
// Check if condition fails
if (isEven.fails()) {
console.log('Condition failed!');
}Disable timestamps in logs:
const condition = new Condition(
() => myValue,
expectedValue,
'My validation',
console.warn,
false // logTimestamp: false disables timestamp in log messages
);Chainable string validators for common checks:
import { isString } from '@beautify-lang/js';
const input = '{ "valid": true }';
// Check if valid JSON
if (isString(input).validJSON()) {
console.log('Valid JSON string');
}
// Check string properties
isString(input).empty(); // false
isString(input).ofLength(17); // true
isString(input).numeric(); // false
isString(input).uppercase(); // false
isString(input).lowercase(); // false
isString(input).matches(/\d+/); // falseTransform arrays with clean, declarative syntax:
import { convertArray } from '@beautify-lang/js';
const numbers = [1, 2, 2, 3, 3, 3];
// Convert to JSON string
const json = convertArray(numbers).toJsonString();
// "[1,2,2,3,3,3]"
// Convert to Set
const set = convertArray(numbers).toSet();
// Set {1, 2, 3}
// Get unique values as array
const unique = convertArray(numbers).toUniqueArray();
// [1, 2, 3]import { not } from '@beautify-lang/js';
const result = not(true); // false
const truthy = not(false); // trueA class for creating reusable validation conditions.
new Condition<T>(
cb: () => unknown,
expectedOutput: T,
label: string,
logger: (...args: any[]) => void = console.warn,
logTimestamp: boolean = true
)Parameters:
cb– Callback function that returns the value to validateexpectedOutput– Expected output to compare againstlabel– Human-readable label for the condition (used in log messages)logger– Optional logging function (defaults toconsole.warn)logTimestamp– Whentrue(default), includes ISO timestamp in log messages
passes(): boolean– Returnstrueif callback output matches expected output. Logs failure details with timestamp if mismatch.fails(): boolean– Returnstrueif callback output does NOT match expected output.
Returns an object with chainable string validation methods:
validJSON(): boolean– Checks if the string is valid JSONempty(): boolean– Checks if the string is emptyofLength(expectedLength: number): boolean– Checks if the string has the expected lengthnumeric(): boolean– Checks if the string contains only numeric charactersuppercase(): boolean– Checks if the string is uppercase (non-empty)lowercase(): boolean– Checks if the string is lowercase (non-empty)matches(regex: RegExp): boolean– Checks if the string matches the given regex
Returns an object with array transformation methods:
toJsonString(): string– Converts the array to a JSON stringtoSet(): Set<ItemType>– Converts the array to a SettoUniqueArray(): ItemType[]– Returns a new array with unique values
Returns the boolean negation of the input value.
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request.
Vedansh Shetti (@vedanshshetti)