e22m4u 3 дней назад
Родитель
Сommit
3a6cb5839d
8 измененных файлов с 49 добавлено и 22 удалено
  1. 4 0
      .mocharc.cjs
  2. 0 4
      .mocharc.json
  3. 1 1
      README.md
  4. 2 6
      eslint.config.js
  5. 13 11
      package.json
  6. 1 0
      src/index.d.ts
  7. 26 0
      src/path-trie.d.ts
  8. 2 0
      tsconfig.json

+ 4 - 0
.mocharc.cjs

@@ -0,0 +1,4 @@
+module.exports = {
+  extension: ['js'],
+  spec: 'src/**/*.spec.js',
+}

+ 0 - 4
.mocharc.json

@@ -1,4 +0,0 @@
-{
-  "extension": ["js"],
-  "spec": "src/**/*.spec.js"
-}

+ 1 - 1
README.md

@@ -1,7 +1,7 @@
 ## @e22m4u/js-path-trie
 
 Маршрутизатор для Node.js на основе
-[префиксного дерева](https://ru.wikipedia.org/wiki/Trie) (Trie).
+[префиксного дерева](https://ru.wikipedia.org/wiki/Trie) (trie).
 
 - Использует [path-to-regexp](https://github.com/pillarjs/path-to-regexp) синтаксис.
 - Поддерживает параметры маршрута.

+ 2 - 6
eslint.config.js

@@ -2,7 +2,6 @@ import globals from 'globals';
 import eslintJs from '@eslint/js';
 import eslintJsdocPlugin from 'eslint-plugin-jsdoc';
 import eslintMochaPlugin from 'eslint-plugin-mocha';
-import eslintImportPlugin from 'eslint-plugin-import';
 import eslintPrettierConfig from 'eslint-config-prettier';
 import eslintChaiExpectPlugin from 'eslint-plugin-chai-expect';
 
@@ -17,19 +16,16 @@ export default [{
   plugins: {
     'jsdoc': eslintJsdocPlugin,
     'mocha': eslintMochaPlugin,
-    'import': eslintImportPlugin,
     'chai-expect': eslintChaiExpectPlugin,
   },
   rules: {
     ...eslintJs.configs.recommended.rules,
     ...eslintPrettierConfig.rules,
-    ...eslintImportPlugin.flatConfigs.recommended.rules,
+    ...eslintJsdocPlugin.configs['flat/recommended-error'].rules,
     ...eslintMochaPlugin.configs.recommended.rules,
     ...eslintChaiExpectPlugin.configs['recommended-flat'].rules,
-    ...eslintJsdocPlugin.configs['flat/recommended-error'].rules,
-    'no-duplicate-imports': 'error',
+    'no-unused-vars': ['error', {'caughtErrors': 'none'}],
     'jsdoc/reject-any-type': 0,
-    'jsdoc/reject-function-type': 0,
     'jsdoc/require-param-description': 0,
     'jsdoc/require-returns-description': 0,
     'jsdoc/require-property-description': 0,

+ 13 - 11
package.json

@@ -1,6 +1,6 @@
 {
   "name": "@e22m4u/js-path-trie",
-  "version": "0.1.0",
+  "version": "0.0.13",
   "description": "Маршрутизатор для Node.js на основе префиксного дерева",
   "author": "Mikhail Evstropov <e22m4u@yandex.ru>",
   "license": "MIT",
@@ -9,15 +9,17 @@
     "trie",
     "router"
   ],
-  "homepage": "https://gitrepos.ru/e22m4u/js-path-trie",
+  "homepage": "https://github.com/e22m4u/js-path-trie",
   "repository": {
     "type": "git",
-    "url": "git+https://gitrepos.ru/e22m4u/js-path-trie.git"
+    "url": "git+https://github.com/e22m4u/js-path-trie.git"
   },
   "type": "module",
+  "types": "./src/index.d.ts",
   "module": "./src/index.js",
   "main": "./dist/cjs/index.cjs",
   "exports": {
+    "types": "./src/index.d.ts",
     "import": "./src/index.js",
     "require": "./dist/cjs/index.cjs"
   },
@@ -25,17 +27,17 @@
     "node": ">=16"
   },
   "scripts": {
-    "lint": "eslint ./src",
-    "lint:fix": "eslint ./src --fix",
+    "lint": "tsc && eslint ./src",
+    "lint:fix": "tsc && eslint ./src --fix",
     "format": "prettier --write \"./src/**/*.js\"",
     "test": "npm run lint && c8 --reporter=text-summary mocha",
     "test:coverage": "npm run lint && c8 --reporter=text mocha",
-    "build:cjs": "rimraf ./dist/cjs && node build-cjs.js",
+    "build:cjs": "rimraf ./dist/cjs && node --no-warnings=ExperimentalWarning build-cjs.js",
     "prepare": "husky"
   },
   "dependencies": {
-    "@e22m4u/js-debug": "~0.4.0",
-    "@e22m4u/js-format": "~0.3.0",
+    "@e22m4u/js-debug": "~0.3.3",
+    "@e22m4u/js-format": "~0.2.1",
     "path-to-regexp": "~8.3.0"
   },
   "devDependencies": {
@@ -48,13 +50,13 @@
     "eslint": "~9.39.1",
     "eslint-config-prettier": "~10.1.8",
     "eslint-plugin-chai-expect": "~3.1.0",
-    "eslint-plugin-import": "~2.32.0",
     "eslint-plugin-jsdoc": "~61.4.1",
     "eslint-plugin-mocha": "~11.2.0",
     "globals": "~16.5.0",
     "husky": "~9.1.7",
     "mocha": "~11.7.5",
-    "prettier": "~3.7.3",
-    "rimraf": "~6.1.2"
+    "prettier": "~3.6.2",
+    "rimraf": "~6.1.2",
+    "typescript": "~5.9.3"
   }
 }

+ 1 - 0
src/index.d.ts

@@ -0,0 +1 @@
+export * from './path-trie.js';

+ 26 - 0
src/path-trie.d.ts

@@ -0,0 +1,26 @@
+/**
+ * Resolved value.
+ */
+export type ResolvedValue<T = unknown> = {
+  value: T;
+  params: {[name: string]: unknown};
+}
+
+/**
+ * Path trie.
+ */
+export declare class PathTrie {
+  /**
+   * Add value.
+   *
+   * @param pathTemplate
+   * @param value
+   */
+  add<T>(pathTemplate: string, value: T): this;
+
+  /**
+   * Match value.
+   * @param path
+   */
+  match<T = unknown>(path: string): ResolvedValue<T> | undefined;
+}

+ 2 - 0
jsconfig.json → tsconfig.json

@@ -1,5 +1,7 @@
 {
   "compilerOptions": {
+    "rootDir": "src",
+    "noEmit": true,
     "target": "es2022",
     "module": "NodeNext",
     "moduleResolution": "NodeNext"