+
Skip to content

Conversation

JakeSidSmith
Copy link
Owner

@JakeSidSmith JakeSidSmith commented Sep 8, 2022

Add an {allowSubPaths: true} option to the deconstruct method.

This allows deconstructing URLs/paths where they match the template but include additional sub-paths e.g.

const url = createTSURL(['user', requiredString('userId')], {
  baseUrl: 'https://server.com',
  basePath: '/api',
  trailingSlash: false,
});

url.deconstruct('https://server.com/api/user/123/posts/123');
// throws an error

url.deconstruct('https://server.com/api/user/123/posts/123', {
  allowSubPaths: true,
});
// returns { urlParams: { userId: '123' }, queryParams: {} }

This PR also converts ReadonlyArray<whatever> to readonly whatever[] and makes some changes to how param types are inferred so that instead of inferring a LOT of interfaces (one for each value type: string, number, boolean, etc) we only infer a single interface for required parts and another for optional parts.

This means that instead of ending up with types like { requiredString: string } & { requiredNumber: number } & {} & {} & {} & {}... etc { optionalNumber: number } & {} . We just end up with { requiredString: string, requiredNumber: number } & { optionalNumber: number }

Some minor fixes to documentation.

@JakeSidSmith JakeSidSmith merged commit 44a6dac into master Sep 10, 2022
@JakeSidSmith JakeSidSmith deleted the allow-sub-paths branch September 10, 2022 13:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载