Compare commits
28 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
9418bfe6ba
|
|||
|
347608ca40
|
|||
|
436cea462d
|
|||
|
abc41ac749
|
|||
|
27779a07f0
|
|||
|
7a4284ef6a
|
|||
|
140382073d
|
|||
|
216225b11a
|
|||
|
0daf6497d5
|
|||
|
fae54e1b71
|
|||
|
ca3528268a
|
|||
|
7d0a87a2eb
|
|||
|
87f5865915
|
|||
|
5f76dd89a3
|
|||
|
ca87ffd33c
|
|||
|
73e9f804c4
|
|||
|
69d93bcf61
|
|||
|
208e7834d3
|
|||
|
802bd8e511
|
|||
|
cb9b082285
|
|||
|
42c80676e7
|
|||
|
2af2f19efb
|
|||
|
c948aa3cc2
|
|||
|
17ac2bdcf4
|
|||
|
4dbe36932c
|
|||
|
8ca1f9e2f2
|
|||
|
903a315788
|
|||
|
3b452ae9d7
|
+4
-4
@@ -1,6 +1,6 @@
|
||||
bun.lockb
|
||||
package-lock.json
|
||||
._*
|
||||
.idea/
|
||||
.DS_Store
|
||||
node_modules/
|
||||
dist/
|
||||
.idea/
|
||||
._*
|
||||
.DS_Store
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
.woodpecker/
|
||||
test/
|
||||
.gitignore
|
||||
README.md
|
||||
.prettierignore
|
||||
.prettierrc
|
||||
eslint.config.ts
|
||||
@@ -1,4 +0,0 @@
|
||||
.woodpecker
|
||||
node_modules
|
||||
test
|
||||
dist
|
||||
-11
@@ -1,11 +0,0 @@
|
||||
{
|
||||
"arrowParens": "avoid",
|
||||
"tabWidth": 2,
|
||||
"useTabs": false,
|
||||
"bracketSpacing": false,
|
||||
"printWidth": 120,
|
||||
"semi": false,
|
||||
"singleQuote": true,
|
||||
"jsxSingleQuote": true,
|
||||
"trailingComma": "none"
|
||||
}
|
||||
@@ -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
|
||||
@@ -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/*"]`
|
||||
@@ -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'])
|
||||
])
|
||||
@@ -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
@@ -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"]
|
||||
}
|
||||
|
||||
@@ -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
@@ -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
@@ -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
|
||||
}
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
import {test} from 'bun:test'
|
||||
|
||||
test('Basic test', () => 'Hello, world!')
|
||||
+27
-8
@@ -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",
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user