Compare commits

..

7 Commits
0.2.0 ... 0.3.2

Author SHA1 Message Date
061e27d92a Fixed build
All checks were successful
Build / Build NPM Project (push) Successful in 32s
Build / Tag Version (push) Successful in 7s
Build / Publish (push) Successful in 17s
2024-02-28 23:57:20 -05:00
63a5c5f6b7 Reverted that revert because I should be using npx anyways
All checks were successful
Build / Tag Version (push) Successful in 9s
Build / Publish (push) Successful in 18s
Build / Build NPM Project (push) Successful in 39s
2024-02-28 23:52:03 -05:00
64a0eac6df Reverted that revert because I should be using npx anyways
Some checks failed
Build / Build NPM Project (push) Failing after 7s
Build / Publish (push) Has been skipped
Build / Tag Version (push) Has been skipped
2024-02-28 23:51:56 -05:00
3e1341d876 Reverted that revert because I should be using npx anyways
Some checks failed
Build / Tag Version (push) Blocked by required conditions
Build / Publish (push) Blocked by required conditions
Build / Build NPM Project (push) Has been cancelled
2024-02-28 23:51:22 -05:00
b3457ed588 Reverted build changes
All checks were successful
Build / Build NPM Project (push) Successful in 33s
Build / Tag Version (push) Successful in 7s
Build / Publish (push) Successful in 13s
2024-02-28 23:50:16 -05:00
210f007e07 Added padding utility and updated logger object
All checks were successful
Build / Build NPM Project (push) Successful in 31s
Build / Tag Version (push) Successful in 7s
Build / Publish (push) Successful in 14s
2024-02-28 23:43:07 -05:00
24edc4a12d Changed logger events
All checks were successful
Build / Build NPM Project (push) Successful in 30s
Build / Tag Version (push) Successful in 12s
Build / Publish (push) Successful in 21s
2024-02-28 19:23:58 -05:00
5 changed files with 40 additions and 17 deletions

4
package-lock.json generated
View File

@ -1,12 +1,12 @@
{
"name": "@ztimson/js-utilities",
"version": "0.0.0",
"version": "0.2.1",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "@ztimson/js-utilities",
"version": "0.0.0",
"version": "0.2.1",
"license": "MIT",
"devDependencies": {
"@types/jest": "^29.5.12",

View File

@ -1,6 +1,6 @@
{
"name": "@ztimson/js-utilities",
"version": "0.2.0",
"version": "0.3.2",
"description": "JavaScript Utility library",
"author": "Zak Timson",
"license": "MIT",
@ -13,10 +13,10 @@
"module": "./dist/js-utilities.mjs",
"types": "./dist/src/index.d.ts",
"scripts": {
"build": "vite build",
"build": "npx vite build",
"test": "npx jest",
"test:coverage": "npx jest --coverage",
"watch": "vite build --watch"
"watch": "npx vite build --watch"
},
"devDependencies": {
"@types/jest": "^29.5.12",

View File

@ -58,46 +58,61 @@ export type LoggerEvents = TypedEvents & {
export class Logger extends TypedEmitter<LoggerEvents> {
static LOG_LEVEL: LOG_LEVEL = LOG_LEVEL.INFO;
constructor(public readonly namespace: string) {
constructor(public readonly namespace?: string) {
super();
}
private pad(text: string, length: number, char: string, end = false) {
const l = length - text.length;
if(l <= 0) return text;
const padding = Array(~~(l / char.length)).fill(char).join('');
return !end ? padding + text : text + padding;
}
private format(...text: string[]): string {
return `${new Date().toISOString()} [${this.namespace}] ${text.join(' ')}`;
const now = new Date();
const timestamp = `${now.getFullYear()}-${now.getMonth() + 1}-${now.getDate()} ${this.pad(now.getHours().toString(), 2, '0')}:${this.pad(now.getMinutes().toString(), 2, '0')}:${this.pad(now.getSeconds().toString(), 2, '0')}.${this.pad(now.getMilliseconds().toString(), 3, '0', true)}`;
return `${timestamp}${this.namespace ? ` [${this.namespace}]` : ''} ${text.join(' ')}`;
}
debug(...args: string[]) {
if(LOG_LEVEL.VERBOSE >= Logger.LOG_LEVEL) {
Logger.emit(LOG_LEVEL.VERBOSE, ...args);
console.debug(CliForeground.LIGHT_GREY + this.format(...args) + CliEffects.CLEAR);
const str = this.format(...args);
Logger.emit(LOG_LEVEL.VERBOSE, str);
console.debug(CliForeground.LIGHT_GREY + str + CliEffects.CLEAR);
}
}
error(...args: string[]) {
if(LOG_LEVEL.ERROR >= Logger.LOG_LEVEL) {
Logger.emit(LOG_LEVEL.ERROR, ...args);
console.error(CliForeground.RED + this.format(...args) + CliEffects.CLEAR);
const str = this.format(...args);
Logger.emit(LOG_LEVEL.ERROR, str);
console.error(CliForeground.RED + str + CliEffects.CLEAR);
}
}
info(...args: string[]) {
if(LOG_LEVEL.INFO >= Logger.LOG_LEVEL) {
Logger.emit(LOG_LEVEL.INFO, ...args);
console.info(CliForeground.CYAN + this.format(...args) + CliEffects.CLEAR);
const str = this.format(...args);
Logger.emit(LOG_LEVEL.INFO, str);
console.info(CliForeground.BLUE + str + CliEffects.CLEAR);
}
}
log(...args: string[]) {
if(LOG_LEVEL.INFO >= Logger.LOG_LEVEL) {
Logger.emit(LOG_LEVEL.INFO, ...args);
console.log(CliEffects.CLEAR + this.format(...args));
const str = this.format(...args);
Logger.emit(LOG_LEVEL.INFO, str);
console.log(CliEffects.CLEAR + str);
}
}
warn(...args: string[]) {
if(LOG_LEVEL.WARN >= Logger.LOG_LEVEL) {
Logger.emit(LOG_LEVEL.WARN, ...args);
console.warn(CliForeground.YELLOW + this.format(...args) + CliEffects.CLEAR);
const str = this.format(...args);
Logger.emit(LOG_LEVEL.WARN, str);
console.warn(CliForeground.YELLOW + str + CliEffects.CLEAR);
}
}
}

View File

@ -52,6 +52,13 @@ export function insertAt(target: string, str: string, index: number): String {
return `${target.slice(0, index)}${str}${target.slice(index + 1)}`;
}
export function pad(text: string, length: number, char: string, start = true) {
const l = length - text.length;
if(l <= 0) return text;
const padding = Array(~~(l / char.length)).fill(char).join('');
return start ? padding + text : text + padding;
}
/**
* Generate a string of random characters.
*

View File

@ -8,6 +8,7 @@
"declarationMap": true,
"experimentalDecorators": true,
"esModuleInterop": true,
"inlineSourceMap": true,
"lib": ["ESNext", "DOM"],
"module": "ES6",
"moduleResolution": "Node",