Skip to content

Commit

Permalink
fix(fast-path-parse): declaration types added
Browse files Browse the repository at this point in the history
  • Loading branch information
dalisoft committed Sep 3, 2024
1 parent cbab236 commit b908746
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 14 deletions.
5 changes: 5 additions & 0 deletions packages/fast-path-parse/aot/match.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function match(
path: string
): (pathname: string, params?: Record<string, string>) => boolean;

export = match;
5 changes: 3 additions & 2 deletions packages/fast-path-parse/aot/match.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ const segmentsSlice = require('../utils/segment.js');

/**
* Compiles an route path for fastest validation
* @param {string} path A path to be compiled
* @returns {(pathname: string, params?: Record<string, string>) => boolean} Optimized function which validate params at runtime
* @type {import('./match')}
* @param path A path to be compiled
* @returns Optimized function which validate params at runtime
* @example
* ```ts
* import compile from 'fast-path-parser/aot/match';
Expand Down
8 changes: 8 additions & 0 deletions packages/fast-path-parse/aot/parse.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
function parse(
path: string
): (
pathname: string,
params?: Record<string, string>
) => Record<string, string>;

export = parse;
9 changes: 5 additions & 4 deletions packages/fast-path-parse/aot/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ const segmentsSlice = require('../utils/segment.js');

/**
* Compiles an route path for fastest parsing
* @param {string} path A path to be compiled
* @returns {(pathname: string, params?: Record<string, string>) => params} Optimized function which parse params at runtime
* @type {import('./parse')}
* @param path A path to be compiled
* @returns Optimized function which parse params at runtime
* @example
* ```ts
* import compile from 'fast-path-parser/aot/parse';
Expand All @@ -12,7 +13,7 @@ const segmentsSlice = require('../utils/segment.js');
* pathParse('/user/123') // returns { id: '123' }
* ```
*/
const compile = (path) => {
const parse = (path) => {
const { segments, filled } = segmentsSlice(path);

if (filled.length > 0) {
Expand Down Expand Up @@ -57,4 +58,4 @@ const compile = (path) => {
return (_, params = {}) => params;
};

module.exports = compile;
module.exports = parse;
20 changes: 16 additions & 4 deletions packages/fast-path-parse/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,22 @@
"description": "Fastest route path-to-params parser",
"type": "commonjs",
"exports": {
"./aot/parse": "./aot/parse.js",
"./aot/match": "./aot/match.js",
"./runtime/parse": "./runtime/parse.js",
"./runtime/match": "./runtime/match.js"
"./aot/parse": {
"default": "./aot/parse.js",
"types": "./aot/parse.d.ts"
},
"./aot/match": {
"default": "./aot/match.js",
"types": "./aot/match.d.ts"
},
"./runtime/parse": {
"default": "./runtime/parse.js",
"types": "./runtime/parse.d.ts"
},
"./runtime/match": {
"default": "./runtime/match.js",
"types": "./runtime/match.d.ts"
}
},
"files": [
"aot",
Expand Down
5 changes: 5 additions & 0 deletions packages/fast-path-parse/runtime/match.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function match(
path: string
): (pathname: string, params?: Record<string, string>) => boolean;

export = match;
5 changes: 3 additions & 2 deletions packages/fast-path-parse/runtime/match.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ const segmentsSlice = require('../utils/segment.js');

/**
* Prepares an route path for validating
* @param {string} path A path to be compiled
* @returns {(pathname: string, params?: Record<string, string>) => boolean} Function which validates runtime
* @type {import('./match')}
* @param path A path to be compiled
* @returns Function which validates runtime
* @example
* ```ts
* import match from 'fast-path-parser/runtime/match';
Expand Down
8 changes: 8 additions & 0 deletions packages/fast-path-parse/runtime/parse.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
function parse(
path: string
): (
pathname: string,
params?: Record<string, string>
) => Record<string, string>;

export = parse;
5 changes: 3 additions & 2 deletions packages/fast-path-parse/runtime/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ const segmentsSlice = require('../utils/segment.js');

/**
* Prepares an route path for parsing
* @param {string} path A path to be compiled
* @returns {(pathname: string, params?: Record<string, string>) => params} Function which parse params at runtime
* @type {import('./parse')}
* @param path A path to be compiled
* @returns Function which parse params at runtime
* @example
* ```ts
* import parse from 'fast-path-parser/runtime/parse';
Expand Down

0 comments on commit b908746

Please sign in to comment.