28 Commits

Author SHA1 Message Date
pascal 9418bfe6ba Remove problematic lib chalk 2025-09-06 09:57:22 +02:00
pascal 347608ca40 Add tsconfig to lib 2024-07-29 11:54:00 +02:00
Pascal Perrenoud 436cea462d remove peerDependencies 2024-07-27 13:38:49 +02:00
Pascal Perrenoud abc41ac749 fmt 2024-07-27 13:35:17 +02:00
Pascal Perrenoud 27779a07f0 BREAKING CHANGE : Align levels to Rust :) 2024-06-03 16:55:58 +02:00
pascal 7a4284ef6a Rework padding option 2024-05-22 10:14:20 +02:00
pascal 140382073d Add comment 2024-05-22 10:12:49 +02:00
pascal 216225b11a Remove LevelFilter 2024-05-22 10:12:17 +02:00
pascal 0daf6497d5 Allow to control padding of level 2024-05-22 10:11:59 +02:00
pascal fae54e1b71 Add verbose option 2024-05-22 10:01:03 +02:00
pascal ca3528268a Remove types chalk as suggested 2024-05-22 10:00:54 +02:00
pascal 7d0a87a2eb Unify constructor 2024-05-22 08:52:15 +02:00
pascal 87f5865915 Do a check no one did ??? 2024-05-20 01:15:05 +02:00
pascal 5f76dd89a3 Type logger and export Logger 2024-05-19 19:37:16 +02:00
pascal ca87ffd33c Export all files for NPM 2024-05-19 19:37:10 +02:00
pascal 73e9f804c4 Fix export of Writer 2024-05-15 21:10:40 +02:00
pascal 69d93bcf61 Replace Writer abstract class with interface 2024-05-15 21:04:28 +02:00
pascal 208e7834d3 remove useless failproofing 2024-05-15 21:04:08 +02:00
pascal 802bd8e511 Update Writer interface 2024-05-15 20:46:06 +02:00
pascal cb9b082285 Unify package.json 2024-05-15 13:15:07 +02:00
pascal 42c80676e7 Failsafe options 2024-05-15 12:54:36 +02:00
pascal 2af2f19efb Fix Writer's constructor's privacy 2024-05-15 12:46:55 +02:00
pascal c948aa3cc2 Fix various issues (import style, type on Writer) 2024-05-14 23:09:11 +02:00
pascal 17ac2bdcf4 Remove writers from lib
Closes #4
2024-05-14 22:49:59 +02:00
pascal 4dbe36932c Unify lib options 2024-05-14 12:51:44 +02:00
pascal 8ca1f9e2f2 implement lib 2024-05-14 12:46:32 +02:00
pascal 903a315788 Hide src from package 2024-05-14 12:46:32 +02:00
pascal 3b452ae9d7 Add structure 2024-05-14 12:46:31 +02:00
14 changed files with 45 additions and 141 deletions
+4 -4
View File
@@ -1,6 +1,6 @@
bun.lockb
package-lock.json
._*
.idea/
.DS_Store
node_modules/
dist/
.idea/
._*
.DS_Store
-7
View File
@@ -1,7 +0,0 @@
.woodpecker/
test/
.gitignore
README.md
.prettierignore
.prettierrc
eslint.config.ts
-4
View File
@@ -1,4 +0,0 @@
.woodpecker
node_modules
test
dist
-11
View File
@@ -1,11 +0,0 @@
{
"arrowParens": "avoid",
"tabWidth": 2,
"useTabs": false,
"bracketSpacing": false,
"printWidth": 120,
"semi": false,
"singleQuote": true,
"jsxSingleQuote": true,
"trailingComma": "none"
}
-19
View File
@@ -1,19 +0,0 @@
when:
- path:
include: ['src/**/*.ts']
steps:
install:
image: node
when:
- event: [pull_request, push, manual]
commands:
- npm install
test:
image: oven/bun:alpine
when:
- event: [pull_request, push, manual]
depends_on: install
commands:
- bun test
-8
View File
@@ -1,8 +0,0 @@
# Library template
Basic template to create a TypeScript library that works properly when included
## How to split in multiple file
Technically, there is nothing to do, but if you want to allow sub-imports, you have to :
1. In `package.json`, under `exports`, add `"./submodule": "./src/submodule.ts"`
2. In `tsconfig.json`, under `paths`, add `"lib-name/*": ["./src/*"]`
-20
View File
@@ -1,20 +0,0 @@
import js from '@eslint/js'
import globals from 'globals'
import tseslint from 'typescript-eslint'
import {defineConfig, globalIgnores} from 'eslint/config'
export default defineConfig([
tseslint.configs.recommended,
{
files: ['**/*.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
plugins: {js},
extends: ['js/recommended'],
languageOptions: {globals: {...globals.browser, ...globals.node}},
rules: {
'no-unused-vars': 'warn',
'@typescript-eslint/no-unused-vars': ['warn']
}
},
globalIgnores(['dist'])
])
+2 -2
View File
@@ -1,5 +1,5 @@
import {Level, type WriterOptions, type Writer} from './types'
import {Logger, writers, options} from './logger'
import {Level, type WriterOptions, type Writer} from './src/types'
import {Logger, writers, options} from './src/logger'
export default (namespace: string): Logger => new Logger(namespace)
export {Logger, Level, type WriterOptions, type Writer, writers, options}
+3 -27
View File
@@ -1,35 +1,11 @@
{
"scripts": {
"check": "clear ; npm run typecheck && npm run lint && npx prettier -c **/*.{js,jsx,ts,tsx} && clear && echo 'OK'",
"fmt": "prettier --write **/*.{js,jsx,ts,tsx}",
"lint": "eslint **/*.{js,jsx,ts,tsx}",
"test": "bun test",
"typecheck": "tsc --noEmit"
},
"dependencies": {
"chalk": "^5.6.2"
},
"devDependencies": {
"@eslint/js": "^9.35.0",
"@types/bun": "^1.2.21",
"bun": "^1.2.21",
"eslint": "^9.35.0",
"globals": "^16.4.0",
"jiti": "^2.5.1",
"prettier": "^3.6.2",
"typescript": "^5.9.2",
"typescript-eslint": "^8.43.0"
},
"name": "log",
"description": "log library with logger and writers",
"version": "1.0.0",
"author": "Pascal Perrenoud <pascal@pband.ch>",
"module": "index.ts",
"type": "module",
"main": "./src/index.ts",
"exports": {
".": "./src/index.ts"
}
"files": ["index.ts", "src", "tsconfig.json"]
}
-19
View File
@@ -1,19 +0,0 @@
import {Chalk} from 'chalk'
import {Level} from './types'
const chalk = new Chalk({level: 2}) // 256 colors
export function get_color(level: Level) {
switch (level) {
case Level.DEBUG:
return chalk.blueBright
case Level.TRACE:
return chalk.green
case Level.INFO:
return (str: string) => str
case Level.WARNING:
return chalk.hex('#FFA500')
case Level.ERROR:
return chalk.red
}
}
+7 -7
View File
@@ -1,7 +1,7 @@
import {Level, type Options, type Writer} from './types'
export const writers = new Map<string, Writer>()
export const options: Options = {
export let options: Options = {
format: '[$time] $level $namespace :',
pad_level: true,
verbose: true
@@ -18,28 +18,28 @@ export class Logger {
return new Logger(`${this.namespace}:${sub_namespace}`)
}
public debug(...data: unknown[]): void {
public debug(...data: any[]): void {
log(data, Level.DEBUG, this._namespace)
}
public trace(...data: unknown[]): void {
public trace(...data: any[]): void {
log(data, Level.TRACE, this._namespace)
}
public info(...data: unknown[]): void {
public info(...data: any[]): void {
log(data, Level.INFO, this._namespace)
}
public warn(...data: unknown[]): void {
public warn(...data: any[]): void {
log(data, Level.WARNING, this._namespace)
}
public error(...data: unknown[]): void {
public error(...data: any[]): void {
log(data, Level.ERROR, this._namespace)
}
}
function log(message: unknown[], level: Level, namespace: string): void {
function log(message: any[], level: Level, namespace: string): void {
if (writers.size === 0) {
if (options.verbose) console.log('No writer subscribed, discard message')
return
+2 -2
View File
@@ -19,11 +19,11 @@ export enum Level {
export type WriterOptions = {
minLevel: Level
[key: string | number | symbol]: unknown
[key: string | number | symbol]: any
}
export interface Writer {
log(level: Level, ...data: unknown[]): void
log(level: Level, ...data: any[]): void
get options(): WriterOptions
readonly _options: WriterOptions
}
-3
View File
@@ -1,3 +0,0 @@
import {test} from 'bun:test'
test('Basic test', () => 'Hello, world!')
+27 -8
View File
@@ -1,14 +1,33 @@
{
"compilerOptions": {
"target": "ES2020",
// Enable latest features
"lib": ["ESNext","dom"],
"target": "ESNext",
"module": "ESNext",
"moduleResolution": "node",
"declaration": true,
"outDir": "dist",
"rootDir": "./src",
"moduleDetection": "force",
"allowJs": true,
"checkJs": true,
// Bundler mode
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"verbatimModuleSyntax": true,
"noEmit": true,
// Best practices
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true
"skipLibCheck": true,
"noFallthroughCasesInSwitch": true,
// Some stricter flags (disabled by default)
"noUnusedLocals": false,
"noUnusedParameters": false,
"forceConsistentCasingInFileNames": true,
"noPropertyAccessFromIndexSignature": false
},
"include": ["src"]
"include": [
"index.ts",
"src/**/*.ts",
]
}