diff --git a/.gitignore b/.gitignore index f39fcb6..7f82a6f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ -.idea/ -._* -.DS_Store -bun.lockb package-lock.json +._* +.idea/ +.DS_Store node_modules/ +dist/ diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..aa0e10b --- /dev/null +++ b/.npmignore @@ -0,0 +1,7 @@ +.woodpecker/ +test/ +.gitignore +README.md +.prettierignore +.prettierrc +eslint.config.ts diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..84af45f --- /dev/null +++ b/.prettierignore @@ -0,0 +1,3 @@ +.woodpecker +node_modules +dist diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..9e19544 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,11 @@ +{ + "arrowParens": "avoid", + "tabWidth": 2, + "useTabs": false, + "bracketSpacing": false, + "printWidth": 120, + "semi": false, + "singleQuote": true, + "jsxSingleQuote": true, + "trailingComma": "none" +} diff --git a/.woodpecker/test.yml b/.woodpecker/test.yml index 5eae361..3288aaa 100644 --- a/.woodpecker/test.yml +++ b/.woodpecker/test.yml @@ -1,6 +1,6 @@ when: - path: - include: ['index.ts'] + include: ['**/*.{js,jsx,ts,tsx}'] steps: install: @@ -10,10 +10,42 @@ steps: commands: - npm install - test: - image: oven/bun + typecheck: + image: node when: - event: [pull_request, push, manual] depends_on: install commands: - - bun test + - npm run typecheck + + lint: + image: node + when: + - event: [pull_request, push, manual] + depends_on: install + commands: + - npm run lint + + fmt: + image: node + when: + - event: [pull_request, push, manual] + depends_on: install + commands: + - npm run check:fmt + + test: + image: node + when: + - event: [pull_request, push, manual] + depends_on: install + commands: + - npm run test + + check: + image: node + when: + - event: [pull_request, push, manual] + depends_on: install + commands: + - npm run check diff --git a/README.md b/README.md new file mode 100644 index 0000000..3e620d1 --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +# Miscellaneous +Various helpers I often use in TypeScript but that are impossible to categorize. + +In fact, it is just two functions about base64 and number arrays. diff --git a/eslint.config.ts b/eslint.config.ts new file mode 100644 index 0000000..754d790 --- /dev/null +++ b/eslint.config.ts @@ -0,0 +1,15 @@ +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}} + }, + globalIgnores(['dist']) +]) diff --git a/package.json b/package.json index 61c4046..78230ae 100644 --- a/package.json +++ b/package.json @@ -5,17 +5,32 @@ "author": "Pascal Perrenoud ", "scripts": { - "test": "bun test" + "check": "clear ; npm run typecheck && npm run lint && npm run check:fmt && npm run test ; clear && echo 'OK'", + "check:fmt": "npx prettier -c **/*.{js,jsx,ts,tsx}", + "fmt": "prettier --write **/*.{js,jsx,ts,tsx}", + "lint": "eslint **/*.{js,jsx,ts,tsx}", + "test": "bun test", + "typecheck": "tsc --noEmit" }, "dependencies": { - "log": "git+https://git.pband.ch/typescript/log.git" + "log": "git+ssh://git@git.pband.ch:typescript/log.git#main" }, "devDependencies": { - "@types/bun": "^1.0.11" + "@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" }, - "module": "index.ts", "type": "module", - "files": ["index.ts"] + "main": "./src/index.ts", + "exports": { + ".": "./src/index.ts" + } } diff --git a/index.ts b/src/index.ts similarity index 90% rename from index.ts rename to src/index.ts index 7b572a9..f4e9051 100644 --- a/index.ts +++ b/src/index.ts @@ -3,8 +3,7 @@ import logger from 'log' const log = logger('misc') export function a2str(buf: Uint8Array) : string { - // @ts-ignore - return String.fromCharCode.apply(null, buf) + return String.fromCharCode.apply(null, [...buf]) } export function str2a(str: string) : Uint8Array { const buf = new Uint8Array(str.length) diff --git a/index.test.ts b/test/main.test.ts similarity index 91% rename from index.test.ts rename to test/main.test.ts index 63668a8..3cbab64 100644 --- a/index.test.ts +++ b/test/main.test.ts @@ -1,4 +1,4 @@ -import {a2b64, a2str, b642a, str2a} from './index' +import {a2b64, a2str, b642a, str2a} from '..' import {test, expect} from 'bun:test' diff --git a/tsconfig.json b/tsconfig.json index 3d49bf0..5dc8e0f 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,32 +1,14 @@ { "compilerOptions": { - // Enable latest features - "lib": ["ESNext","dom"], - "target": "ESNext", + "target": "ES2020", "module": "ESNext", - "moduleDetection": "force", - "allowJs": true, - "checkJs": true, - - // Bundler mode - "moduleResolution": "bundler", - "allowImportingTsExtensions": true, - "verbatimModuleSyntax": true, - "noEmit": true, - - // Best practices + "moduleResolution": "node", + "declaration": true, + "outDir": "dist", + "rootDir": "./src", "strict": true, - "skipLibCheck": true, - "noFallthroughCasesInSwitch": true, - - // Some stricter flags (disabled by default) - "noUnusedLocals": false, - "noUnusedParameters": false, - "forceConsistentCasingInFileNames": true, - "noPropertyAccessFromIndexSignature": false + "esModuleInterop": true, + "skipLibCheck": true }, - - "include": [ - "index.ts", - ] + "include": ["src"] }