Skip to content

Commit

Permalink
fix(fast-path-parse): typings, jsdoc and other typings fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dalisoft committed Sep 15, 2024
1 parent d928ea3 commit 8027c64
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 50 deletions.
12 changes: 12 additions & 0 deletions packages/fast-path-parse/aot/match.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
/**
* Compiles an route path for fastest validation
* @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';
*
* const pathMatch = compile('/user/:id');
* pathMatch('/user/123') // returns `true`
* ```
*/
function match(path: string): (pathname: string) => boolean;

export = match;
10 changes: 0 additions & 10 deletions packages/fast-path-parse/aot/match.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
const segmentsSlice = require('../utils/segment.js');

/**
* Compiles an route path for fastest validation
* @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';
*
* const pathMatch = compile('/user/:id');
* pathMatch('/user/123') // returns `true`
* ```
*/
// eslint-disable-next-line max-lines-per-function
const match = (path) => {
Expand Down
12 changes: 12 additions & 0 deletions packages/fast-path-parse/aot/parse.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
/**
* Compiles an route path for fastest parsing
* @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';
*
* const pathParse = compile('/user/:id');
* pathParse('/user/123') // returns { id: '123' }
* ```
*/
function parse(
path: string
): (
Expand Down
10 changes: 0 additions & 10 deletions packages/fast-path-parse/aot/parse.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
const segmentsSlice = require('../utils/segment.js');

/**
* Compiles an route path for fastest parsing
* @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';
*
* const pathParse = compile('/user/:id');
* pathParse('/user/123') // returns { id: '123' }
* ```
*/
const parse = (path) => {
const { segments, filled } = segmentsSlice(path);
Expand Down
12 changes: 12 additions & 0 deletions packages/fast-path-parse/runtime/match.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
/**
* Prepares an route path for validating
* @param path A path to be compiled
* @returns Function which validates runtime
* @example
* ```ts
* import match from 'fast-path-parser/runtime/match';
*
* const pathMatch = match('/user/:id');
* pathMatch('/user/123') // returns `true`
* ```
*/
function match(path: string): (pathname: string) => boolean;

export = match;
11 changes: 0 additions & 11 deletions packages/fast-path-parse/runtime/match.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,8 @@
const segmentsSlice = require('../utils/segment.js');

/**
* Prepares an route path for validating
* @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';
*
* const pathMatch = match('/user/:id');
* pathMatch('/user/123') // returns `true`
* ```
*/

const match = (path) => {
const { segments, filled, length: LENGTH } = segmentsSlice(path);

Expand Down
12 changes: 12 additions & 0 deletions packages/fast-path-parse/runtime/parse.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
/**
* Prepares an route path for parsing
* @param path A path to be compiled
* @returns Function which parse params at runtime
* @example
* ```ts
* import parse from 'fast-path-parser/runtime/parse';
*
* const pathParse = parse('/user/:id');
* pathParse('/user/123') // returns { id: '123' }
* ```
*/
function parse(
path: string
): (
Expand Down
12 changes: 0 additions & 12 deletions packages/fast-path-parse/runtime/parse.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,7 @@
const segmentsSlice = require('../utils/segment.js');

/**
* Prepares an route path for parsing
* @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';
*
* const pathParse = parse('/user/:id');
* pathParse('/user/123') // returns { id: '123' }
* ```
*/

const parse = (path) => {
const { segments, filled } = segmentsSlice(path);

Expand Down
9 changes: 9 additions & 0 deletions packages/fast-path-parse/utils/segment.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ export interface ISegmentSlice {
length: number;
}

/**
* Parses route string into segments and parses it
* @param path A path to parse
* @example
* ```ts
* segmentsSlice('/foo/bar').segments
* // [{name: 'foo', segment: false, size: 3, last: false}, {name: 'bar', segment: false, size: 3, last: true}]
* ```
*/
function segmentsSlice(path: string): ISegmentSlice;

export = segmentsSlice;
7 changes: 0 additions & 7 deletions packages/fast-path-parse/utils/segment.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,7 @@ const parseSegment = (name, getIndex, position = 1) => {
};

/**
* Parses route string into segments and parses it
* @type {import('./segment')}
* @param path A path to parse
* @example
* ```ts
* segmentsSlice('/foo/bar').segments
* // [{name: 'foo', segment: false, size: 3, last: false}, {name: 'bar', segment: false, size: 3, last: true}]
* ```
*/
module.exports = function segmentsSlice(path) {
let INDEX = 1;
Expand Down

0 comments on commit 8027c64

Please sign in to comment.