Skip to content

Commit

Permalink
fix(fast-path-parse): add utils for export
Browse files Browse the repository at this point in the history
  • Loading branch information
dalisoft committed Sep 15, 2024
1 parent c49f254 commit 9677d6e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
4 changes: 4 additions & 0 deletions packages/fast-path-parse/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
"./runtime/match": {
"default": "./runtime/match.js",
"types": "./runtime/match.d.ts"
},
"./utils/segment": {
"default": "./utils/segment.js",
"types": "./utils/segment.d.ts"
}
},
"files": [
Expand Down
16 changes: 16 additions & 0 deletions packages/fast-path-parse/utils/segment.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export interface ISegment {
name: string;
segment: boolean;
position: number;
last: boolean;
}

export interface ISegmentSlice {
segments: ISegment[];
filled: ISegment[];
length: number;
}

function segmentsSlice(path: string): ISegmentSlice;

export = segmentsSlice;
6 changes: 4 additions & 2 deletions packages/fast-path-parse/utils/segment.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* @param {(() => number)} getIndex
* @param {number} position
*/

// eslint-disable-next-line complexity
const parseSegment = (name, getIndex, position = 1) => {
if (name === '*' || name === '(.*)') {
Expand All @@ -25,7 +26,8 @@ const parseSegment = (name, getIndex, position = 1) => {

/**
* Parses route string into segments and parses it
* @param {string} path
* @type {import('./segment')}
* @param path A path to parse
* @example
* ```ts
* segmentsSlice('/foo/bar').segments
Expand All @@ -36,7 +38,7 @@ module.exports = function segmentsSlice(path) {
let INDEX = 1;

/**
* @type {Array<{name: string; segment: boolean, last: boolean, position: number}>}
* @type {import('./segment').ISegment[]}
*/
const segments = path
.substring(1)
Expand Down

0 comments on commit 9677d6e

Please sign in to comment.