asp-net-core-url-compiler
v1.0.1
Published
A simple url compiler for asp.net core routes implemented on Typescript.
Downloads
6
Maintainers
Readme
ASP.NET Core url compiler
A simple url compiler for asp.net core routes implemented on Typescript.
Install
npm install --save asp-net-core-url-compiler
Usage
import { compileUrl } from 'asp-net-core-url-compiler';
const urlTemplateFromAspNetCoreServer = 'products/{category}?page={page:int}&limit={limit:int?}';
let url = compileUrl(urlTemplateFromAspNetCoreServer, {
category: 'computers',
page: 12,
limit: 100
});
console.log(url);
// products/computers?page=12&limit=100
let url = compileUrl(urlTemplateFromAspNetCoreServer, {
category: 'computers',
limit: 100
});
// throws error
// Parameter 'page' missing.
let url = compileUrl(urlTemplateFromAspNetCoreServer, {
category: 'computers',
page: 4
});
console.log(url);
// products/computers?page=4&limit=
let url = compileUrl(urlTemplateFromAspNetCoreServer, {
category: 'computers',
page: "not today"
});
// throws error
// Parameter 'page:int' doesn't match C# Int32. Value of type Int32 must be a number. Provided value: "not today"
Supported
- Nullable route constaints like
{name?}
- Simple type route constraint validation for
int
,string
,boolean
andguid
Not supported yet
- The rest of route constraints (
long
,decimal
,required
and so on) - Token replacement in route templates ([controller], [action], [area])
Build
tsc ts/asp-net-core-url-compiler.ts --outDir ./js/